Subversion Repositories wimsdev

Rev

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

  1. /*
  2. 27/7/2013 version 0.01
  3. "Inspired" by FLY program: http://martin.gleeson.com/fly
  4. *********************************************************************************
  5. * J.M. Evers 7/2013                                                             *
  6. * This is all just amateur scriblings... So no copyrights.                      *
  7. * This source code file, and compiled objects derived from it,                  *
  8. * can be used and distributed without restriction, including for commercial use *
  9. * No warrenty whatsoever                                                        *
  10. *********************************************************************************
  11. */
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <errno.h>
  15. #include <string.h>
  16. #include <unistd.h>
  17. #include <time.h> /* use for random id's */
  18. #include <math.h>
  19. /*
  20. #include <ctype.h>
  21. 11/2013
  22. removed: FreeBSD 9.0 / 9.1 C-lib bug...in chroot it will result in: Undefined symbol "_ThreadRuneLocale" implemented own versions of tolower() / toupper()
  23. Clang is fine (FreeBSD 10.0)
  24. */
  25.  
  26. /*
  27. in case svgdraw is in ~/src/Misc/svgdraw
  28. #include "../svgdraw/include/matheval.h"
  29. */
  30. #include "include/matheval.h"
  31. #include <assert.h>
  32. #include "canvasdraw.h"
  33. #include <sys/stat.h>
  34.  
  35. /* needed for gettimeofday */
  36. #include <sys/time.h>
  37. #include "canvasmacro.c"
  38. /******************************************************************************
  39. **  Internal Functions
  40. ******************************************************************************/
  41. void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
  42. void    sync_input(FILE *infile);/* proceed with inputfile */
  43. void    canvas_error(char *msg);
  44. void    add_javascript_functions(int js_functions[], int canvas_root_id);
  45. void    reset();/* reset some global variables like "use_filled" , "use_dashed" */
  46. int     get_token(FILE *infile); /* read next char until EOL*/
  47. int     x2px(double x);
  48. int     y2px(double y);
  49. double  px2x(int x);
  50. double  px2y(int y);
  51. double  get_real(FILE *infile,int last); /* read a values; calculation and symbols allowed */
  52. double  get_double(FILE *infile , int orientation , int last); /*the same as get_real(): but for an unknown amount of data args*/
  53. char    *str_replace ( const char *word, const char *sub_word, const char *rep_word );
  54. char    *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */
  55. char    *get_string(FILE *infile,int last); /* get the string at theend of a command */
  56. char    *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as  separator */
  57. char    *convert_hex2rgb(char *hexcolor);
  58. void    add_read_canvas(int reply_format);
  59. void    make_js_include(int canvas_root_id);
  60. void    check_string_length(int length);/* checks if the length of string argument of command is correct */
  61. FILE    *js_include_file;
  62. FILE    *get_file(int *line_number, char **filename);
  63. FILE    *infile;    /* will be stdin */
  64. /******************************************************************************
  65. ** global
  66. ******************************************************************************/
  67. int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */
  68. int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */
  69. /* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */
  70. int xsize = 320;
  71. int ysize = 320;
  72. double xmin = 0.0;
  73. double xmax = 320.0;
  74. double ymin = 0.0;
  75. double ymax = 320.0;
  76. double tmax = 2;
  77. double tmin = -2;
  78. /* flag to indicate parsing of line status */
  79. int done = FALSE;
  80. int type; /* eg command number */
  81. int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/
  82. int use_rotate = FALSE;
  83. int use_translate = FALSE;
  84. int use_filled = FALSE;
  85. int use_dashed = FALSE; /* dashing not natively supported in firefox  , for now... */
  86. char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
  87.  
  88. /******************************************************************************
  89. ** Main Program
  90. ******************************************************************************/
  91. int main(int argc, char *argv[]){
  92.     /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */
  93.     struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
  94.     infile = stdin;/* read flyscript via stdin */
  95.     int i,c;
  96.     double double_data[MAX_INT+1];
  97.     int int_data[MAX_INT+1];
  98.     for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
  99.     int use_parametric = FALSE;/* will be reset after parametric plotting */
  100.     int use_axis = FALSE;
  101.     int use_axis_numbering = FALSE;
  102.     int line_width = 1;
  103.     int decimals = 2;
  104.     int debug = 0;
  105.     int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */
  106.     int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */
  107.     int drag_type = -1;/* 0,1,2 : xy,x,y */
  108.     int use_tooltip = FALSE;
  109.     char *tooltip_text = "Click here";
  110.     char *temp = ""; /* */
  111.     char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
  112.     char *stroke_color = "255,0,0";
  113.     char *fill_color = "0,255,0";
  114.     char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
  115.     char *font_color = "#00000";
  116.     char *draw_type = "points";
  117.     char *fly_font = "normal";
  118.     char *input_style = "";
  119.     char *flytext = "";
  120.     int pixelsize = 1;
  121.     int reply_format = 0;
  122.     int input_cnt = 0;
  123.     int ext_img_cnt = 0;
  124.     int font_size = 12;
  125.     int dashtype[2] = { 2 , 2 };
  126.     int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
  127.     for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
  128.     int arrow_head = 8; /* size in px*/
  129.     int crosshair_size = 10; /* size in px*/
  130.     int plot_steps = 150;
  131.     int found_size_command = 0;
  132.     int click_cnt = 1;
  133.     int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
  134.     int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
  135.     int use_mouse_coordinates = FALSE;
  136.     double angle = 0.0;
  137.     int translate_x = 0;
  138.     int translate_y = 0;
  139.     int clickfillmarge = 20;
  140.     int animation_type = 9; /* == object type curve in drag library */
  141.     size_t string_length = 0;
  142.     double stroke_opacity = 0.8;
  143.     double fill_opacity = 0.8;
  144.     char *URL = "http://localhost/images";
  145.     memset(buffer,'\0',MAX_BUFFER);
  146.     void *tmp_buffer = "";
  147.    
  148.     /* default writing a unzipped js-include file into wims getfile directory */
  149.     char *w_wims_session = getenv("w_wims_session");
  150.     if(  w_wims_session == NULL || *w_wims_session == 0 ){
  151.         canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");
  152.     }
  153.     int L0=strlen(w_wims_session) + 21;
  154.     char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
  155.     snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
  156.     mode_t process_mask = umask(0); /* check if file exists */
  157.     int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
  158.     if( result == 0 || errno == EEXIST ){
  159.      umask(process_mask); /* be sure to set correct permission */
  160.      char *w_session = getenv("w_session");
  161.      int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
  162.     char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
  163.      snprintf(getfile_cmd,L1,"wims.cgi?session=%s&cmd=getfile&special_parm=%d.js",w_session,canvas_root_id);/* extension ".gz" is MANDATORY for webserver */   
  164.     /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
  165.     /* now write file into getfile dir*/
  166.     char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
  167.     int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
  168.     char *location = my_newmem(L2); /* create memory to fit string precisely */
  169.     snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
  170.     js_include_file = fopen(location,"w");/* open the file location for writing */
  171.     /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
  172.     if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
  173.  
  174. /* ----------------------------------------------------- */
  175. /* while more lines to process */
  176.  
  177.     while(!finished){
  178.         if(line_number>1 && found_size_command == FALSE){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
  179.         type = get_token(infile);
  180.         done = FALSE;
  181.         /*
  182.         @canvasdraw
  183.         @will try use the same syntax as flydraw or svgdraw to paint a html5 bitmap image<br />by generating a tailor-made javascript include file: providing only the js-functionality needed to perform the job.<br />thus ensuring a minimal strain on the client browser <br />(unlike some popular 'canvas-do-it-all' libraries, who have proven to be not suitable for low-end computers found in schools...)
  184.         @General syntax <ul><li>The transparency of all objects can be controlled by command 'opacity [0-255],[0,255]'</il><li>a line based object can be controlled by command 'linewidth int'</li><li>a line based object may be dashed by using keyword 'dashed' before the object command.<br />the dashing type can be controled by command 'dashtype int,int'</li>
  185.         <li>a fillable object can be set fillable by starting the object command with an 'f'<br />(like frect,fcircle,ftriangle...)<br />or by using the keyword 'filled' before the object command.<br />The fill colour will be the stroke colour...(19/10/2013)<li> a draggable object can be set draggable by a preceding command 'drag x/y/xy'<br />The translation can be read by javascript:read_dragdrop();<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 zoom and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword 'onclick'<br />not all flydraw objects can be set clickable</li></ul>
  186.         */
  187.         switch(type){
  188.         case END:
  189.         finished = 1;
  190.         done = TRUE;
  191.         break;
  192.         case 0:
  193.             sync_input(infile);
  194.             break;
  195.         case COMMENT:
  196.             sync_input(infile);
  197.             break;
  198.         case EMPTY:
  199.             sync_input(infile);
  200.             break;
  201.         case SIZE:
  202.             /*
  203.             @size width,height
  204.             @set canvas size in pixels
  205.             @mandatory first command
  206.             */
  207.             found_size_command = TRUE;
  208.             xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
  209.             ysize = (int)(abs(round(get_real(infile,1))));
  210.             /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
  211.             xmin = 0;xmax = xsize;
  212.             ymin = ysize;ymax = 0;
  213.  
  214. /*
  215.  The sequence in which stuff is finally printed is important !!
  216.  for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc
  217. */
  218. fprintf(stdout,"\n<script type=\"text/javascript\">var wims_status = \"$status\";</script>\n<!-- canvasdraw div and tooltip placeholder, if needed -->\n<div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;\" ></div><div id=\"tooltip_placeholder_div%d\" style=\"display:block\"><span id=\"tooltip_placeholder%d\" style=\"display:none\"></span></div>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id);
  219. fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n");
  220. fprintf(stdout,"<!-- include actual object code via include file -->\n<script type=\"text/javascript\" src=\"%s\"></script>\n",getfile_cmd);
  221. fprintf(js_include_file,"var wims_canvas_function%d = function(){\n<!-- common used stuff -->\nvar xsize = %d;var ysize = %d;var canvas_div = document.getElementById(\"canvas_div%d\");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;};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;};function x2px(x){return x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin);};function y2px(y){return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);};function px2x(px){return (Math.round((px*(xmax - xmin)/xsize + xmin)*precision))/precision;};function px2y(py){return (Math.round((ymax -py*(ymax - ymin)/ysize)*precision))/precision;};function scale_x_radius(rx){return parseInt(x2px(rx) - x2px(0));};function scale_y_radius(ry){return parseInt(y2px(ry) - y2px(0));};function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};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) ));};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;};var x_strings = null;var y_strings = null;var use_pan_and_zoom = 0;var use_snap_to_grid = 0;\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  222. /* default add the drag code : nearly always used ...*/
  223. add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
  224.             break;
  225.         case XRANGE:
  226.         /*
  227.         @ xrange xmin,xmax
  228.         @ if not given: 0,xsize (eg in pixels)
  229.         */
  230.             for(i = 0 ; i<2; i++){
  231.                 switch(i){
  232.                     case 0: xmin = get_real(infile,0);break;
  233.                     case 1: xmax = get_real(infile,1);break;
  234.                     default: break;
  235.                 }
  236.             }
  237.             if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
  238.             fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
  239.             break;
  240.         case YRANGE:
  241.         /*
  242.         @ yrange ymin,ymax
  243.         @ if not given 0,ysize (eg in pixels)
  244.         */
  245.             for(i = 0 ; i<2; i++){
  246.                 switch(i){
  247.                     case 0: ymin = get_real(infile,0);break;
  248.                     case 1: ymax = get_real(infile,1);break;
  249.                     default: break;
  250.                 }
  251.             }
  252.             if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
  253.             fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
  254.             break;
  255.         case TRANGE:
  256.         /*
  257.         @ trange tmin,tmax
  258.         @ default -2,2
  259.         */
  260.             use_parametric = TRUE;
  261.             for(i = 0 ; i<2; i++){
  262.                 switch(i){
  263.                     case 0: tmin = get_real(infile,0);break;
  264.                     case 1: tmax = get_real(infile,1);break;
  265.                     default: break;
  266.                 }
  267.             }
  268.             if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
  269.             break;
  270.         case LINEWIDTH:
  271.         /*
  272.         @ linewidth int
  273.         @ default 1
  274.         */
  275.             line_width = (int) (get_real(infile,1));
  276.             break;
  277.         case ARROWHEAD:
  278.         /*
  279.         @ arrowhead int
  280.         @ default 8 (pixels)
  281.         */
  282.             arrow_head = (int) (get_real(infile,1));
  283.             break;
  284.         case CROSSHAIRSIZE:
  285.         /*
  286.         @ crosshairsize int
  287.         @ default 10 (px)
  288.         */
  289.             crosshair_size = (int) (get_real(infile,1));
  290.             break;
  291.         case CROSSHAIR:
  292.         /*
  293.         @ crosshair x,y,color
  294.         @ draw a single crosshair point at (x;y) in color 'color'
  295.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  296.         @ may be set draggable / onclick
  297.         */
  298.             for(i=0;i<3;i++){
  299.                 switch(i){
  300.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  301.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  302.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  303.                         decimals = find_number_of_digits(precision);
  304.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,0,0,0,use_rotate,angle,flytext,font_size,font_family);
  305.                         click_cnt++;reset();
  306.                         break;
  307.                     default:break;
  308.                 }
  309.             }
  310.             break;
  311.         case CROSSHAIRS:
  312.         /*
  313.         @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
  314.         @ draw multiple crosshair points at given coordinates in color 'color'
  315.         @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
  316.         @ may be set draggable / onclick individually (!)
  317.         */
  318.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  319.             fill_color = stroke_color;
  320.             i=0;
  321.             while( ! done ){     /* get next item until EOL*/
  322.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  323.                 if(i%2 == 0 ){
  324.                     double_data[i] = get_real(infile,0); /* x */
  325.                 }
  326.                 else
  327.                 {
  328.                     double_data[i] = get_real(infile,1); /* y */
  329.                 }
  330.                 i++;
  331.             }
  332.             decimals = find_number_of_digits(precision);
  333.             for(c=0 ; c < i-1 ; c = c+2){
  334.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family);
  335.                 click_cnt++;
  336.             }
  337.             reset();
  338.             break;
  339.         case POINT:
  340.         /*
  341.         @ point x,y,color
  342.         @ draw a single point at (x;y) in color 'color'
  343.         @ use command 'linewidth int'  to adust size
  344.         @ may be set draggable / onclick
  345.         @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
  346.         */
  347.             for(i=0;i<3;i++){
  348.                 switch(i){
  349.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  350.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  351.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  352.                     decimals = find_number_of_digits(precision);
  353.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family);
  354.                     click_cnt++;break;
  355.                     default: break;
  356.                 }
  357.             }
  358.             reset();
  359.             break;
  360.         case POINTS:
  361.         /*
  362.         @ points color x1,y1,x2,y2,...,x_n,y_n
  363.         @ draw multiple points at given coordinates in color 'color'
  364.         @ use command 'linewidth int'  to adust size
  365.         @ may be set draggable / onclick individually (!)
  366.         */
  367.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  368.             fill_color = stroke_color;
  369.             i=0;
  370.             while( ! done ){     /* get next item until EOL*/
  371.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  372.                 if(i%2 == 0 ){
  373.                     double_data[i] = get_real(infile,0); /* x */
  374.                 }
  375.                 else
  376.                 {
  377.                     double_data[i] = get_real(infile,1); /* y */
  378.                 }
  379.                 i++;
  380.             }
  381.             decimals = find_number_of_digits(precision);           
  382.             for(c = 0 ; c < i-1 ; c = c+2){
  383.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family);
  384.                 click_cnt++;
  385.             }
  386.             reset();
  387.             break;
  388.         case SEGMENT:
  389.         /*
  390.         @ segment x1,y1,x2,y2,color
  391.         @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
  392.         @ may be set draggable / onclick
  393.         */
  394.             for(i=0;i<5;i++) {
  395.                 switch(i){
  396.                     case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
  397.                     case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
  398.                     case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
  399.                     case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
  400.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  401.                         decimals = find_number_of_digits(precision);
  402.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  403.                         click_cnt++;reset();
  404.                         break;
  405.                     default: break;
  406.                 }
  407.             }
  408.             break;
  409.         case LINE:
  410.         /*
  411.         @ line x1,y1,x2,y2,color
  412.         @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
  413.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  414.         @ may be set draggable / onclick
  415.         */
  416.             for(i=0;i<5;i++){
  417.                 switch(i){
  418.                     case 0: double_data[10]= get_real(infile,0);break; /* x-values */
  419.                     case 1: double_data[11]= get_real(infile,0);break; /* y-values */
  420.                     case 2: double_data[12]= get_real(infile,0);break; /* x-values */
  421.                     case 3: double_data[13]= get_real(infile,0);break; /* y-values */
  422.                     case 4: stroke_color=get_color(infile,1);/* name or hex color */
  423.                     if( double_data[10] == double_data[12] ){ /* vertical line*/
  424.                         double_data[1] = xmin;
  425.                         double_data[3] = ymax;
  426.                         double_data[0] = double_data[10];
  427.                         double_data[2] = double_data[10];
  428.                     }
  429.                     else
  430.                     {
  431.                         if( double_data[11] == double_data[13] ){ /* horizontal line */
  432.                             double_data[1] = double_data[11];
  433.                             double_data[3] = double_data[11];
  434.                             double_data[0] = ymin;
  435.                             double_data[2] = xmax;
  436.                         }
  437.                         else
  438.                         {
  439.                         /* m */
  440.                         double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
  441.                         /* q */
  442.                         double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
  443.                        
  444.                         /*xmin,m*xmin+q,xmax,m*xmax+q*/
  445.                        
  446.                             double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
  447.                             double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
  448.                             double_data[0] = xmin;
  449.                             double_data[2] = xmax;
  450.                         }
  451.                     }
  452.                     decimals = find_number_of_digits(precision);
  453.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  454.                     click_cnt++;reset();
  455.                     break;
  456.                 }
  457.             }
  458.             break;
  459.         case HLINE:
  460.         /*
  461.         @ hline x,y,color
  462.         @ draw a horizontal line through point (x:y) in color 'color'
  463.         @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
  464.         @ may be set draggable / onclick
  465.         */
  466.             for(i=0;i<3;i++) {
  467.                 switch(i){
  468.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  469.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  470.                     case 2: stroke_color = get_color(infile,1);/* name or hex color */
  471.                     double_data[3] = double_data[1];
  472.                     decimals = find_number_of_digits(precision);
  473.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,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);
  474.                     click_cnt++;reset();
  475.                     break;
  476.                 }
  477.             }
  478.             break;
  479.         case VLINE:
  480.         /*
  481.         @ vline x,y,color
  482.         @ draw a vertical line through point (x:y) in color 'color'
  483.         @ may be set draggable / onclick
  484.         */
  485.             for(i=0;i<3;i++) {
  486.                 switch(i){
  487.                     case 0: double_data[0] = get_real(infile,0);break; /* x-values */
  488.                     case 1: double_data[1] = get_real(infile,0);break; /* y-values */
  489.                     case 2: stroke_color=get_color(infile,1);/* name or hex color */
  490.                         double_data[2] = double_data[0];
  491.                         decimals = find_number_of_digits(precision);
  492.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],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);
  493.                         click_cnt++;reset();
  494.                     break;
  495.                 }
  496.             }
  497.             break;
  498.         case SQUARE:
  499.         /*
  500.         @ square x,y,side,color
  501.         @ draw a square with left top corner (x:y) with side 'side' in color 'color'
  502.         @ use command 'fsquare x,y,side,color' for a filled square
  503.         @ use command/keyword  'filled' before command 'square x,y,side,color'
  504.         @ use command 'fillcolor color' before 'fsquare' to set the fill colour.
  505.         @ may be set draggable / onclick
  506.         */
  507.             for(i=0;i<5;i++){
  508.                 switch(i){
  509.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  510.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  511.                     case 2:double_data[2] = get_real(infile,0);
  512.                            double_data[3] = double_data[2];
  513.                            break; /* x-values */
  514.                     case 3:stroke_color = get_color(infile,1);/* name or hex color */
  515.                         decimals = find_number_of_digits(precision);
  516.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  517.                         click_cnt++;reset();
  518.                         break;
  519.                 }
  520.             }
  521.             break;
  522.         case ROUNDRECT:
  523.         /*
  524.         @ roundrect x1,y1,x2,y2,radius,color
  525.         @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
  526.         @ use command/keyword  'filled' before command 'roundrect x1,y1,x2,y2,radius,color'
  527.         @ use command 'fillcolor color' before 'froundrect' to set the fill colour.
  528.         @ may be set draggable / onclick
  529.         */
  530.             for(i=0;i<6;i++){
  531.                 switch(i){
  532.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  533.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  534.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  535.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  536.                     case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
  537.                     case 5:stroke_color = get_color(infile,1);/* name or hex color */
  538.                         decimals = find_number_of_digits(precision);
  539.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  540.                         click_cnt++;reset();
  541.                     break;
  542.                 }
  543.             }
  544.             break;
  545.         case RECT:
  546.         /*
  547.         @ rect x1,y1,x2,y2,color
  548.         @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle
  549.         @ use command/keyword  'filled' before command 'rect x1,y1,x2,y2,color'
  550.         @ use command 'fillcolor color' before 'frect' to set the fill colour.
  551.         @ may be set draggable / onclick
  552.         */
  553.             for(i=0;i<5;i++){
  554.                 switch(i){
  555.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  556.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  557.                     case 2:double_data[2] = get_real(infile,0);break; /* x-values */
  558.                     case 3:double_data[3] = get_real(infile,0);break; /* y-values */
  559.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  560.                         decimals = find_number_of_digits(precision);
  561.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[2],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[3],decimals,double_data[3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  562.                         click_cnt++;reset();
  563.                         break;
  564.                 }
  565.             }
  566.             break;
  567.         case POLYLINE:
  568.         /*
  569.         @ polyline color,x1,y1,x2,y2...x_n,y_n
  570.         @ may be set draggable / onclick
  571.         */
  572.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  573.             i=0;
  574.             c=0;
  575.             while( ! done ){     /* get next item until EOL*/
  576.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  577.                 for( c = 0 ; c < 2; c++){
  578.                     if(c == 0 ){
  579.                         double_data[i] = get_real(infile,0);
  580.                         i++;
  581.                     }
  582.                     else
  583.                     {
  584.                         double_data[i] = get_real(infile,1);
  585.                         i++;
  586.                     }
  587.                 }
  588.             }
  589.             /* draw path : not closed & not filled */
  590.             decimals = find_number_of_digits(precision);
  591.             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  592.             click_cnt++;reset();
  593.             break;
  594.         case POLY:
  595.         /*
  596.         @ poly color,x1,y1,x2,y2...x_n,y_n
  597.         @ draw closed polygon
  598.         @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color
  599.         @ may be set draggable / onclick
  600.         */
  601.             stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
  602.             i=0;
  603.             c=0;
  604.             while( ! done ){     /* get next item until EOL*/
  605.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  606.                 for( c = 0 ; c < 2; c++){
  607.                     if(c == 0 ){
  608.                         double_data[i] = get_real(infile,0);
  609.                         i++;
  610.                     }
  611.                     else
  612.                     {
  613.                         double_data[i] = get_real(infile,1);
  614.                         i++;
  615.                     }
  616.                 }
  617.             }
  618.             /* draw path :  closed & optional filled */
  619.                 decimals = find_number_of_digits(precision);
  620.                 string_length = snprintf(NULL,0,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  621.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  622.                 click_cnt++;reset();
  623.             break;
  624.         case ARC:
  625.         /*
  626.          @ arc xc,yc,width,height,start_angle,end_angle,color
  627.          @ can not be set "onclick" or "drag xy"
  628.          @ attention: width == height == radius in pixels)
  629.         */
  630.             for(i=0;i<7;i++){
  631.                 switch(i){
  632.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  633.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  634.                     case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */
  635.                     case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */
  636.                     case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */
  637.                     case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */
  638.                     case 6:stroke_color = get_color(infile,1);/* name or hex color */
  639.                     /* in Shape library:
  640.                         x[0] = x[1] = xc
  641.                         y[0] = y[1] = yc
  642.                         w[0] = w[1] = radius = width = height  
  643.                         h[0] = start_angle ; h[1] = end_engle
  644.                     */
  645.                         decimals = find_number_of_digits(precision);
  646.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],int_data[0],int_data[0],decimals,double_data[2],decimals,double_data[3],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);
  647.                         reset();
  648.                     break;
  649.                 }
  650.             }
  651.             break;
  652.         case ELLIPSE:
  653.         /*
  654.         @ ellipse xc,yc,radius_x,radius_y,color
  655.         @ a ellipse with center xc/yc in x/y-range
  656.         @ radius_x and radius_y are in pixels
  657.         @ may be set draggable / onclick
  658.         @ will shrink / expand on zoom out / zoom in
  659.         */
  660.             for(i=0;i<5;i++){
  661.                 switch(i){
  662.                     case 0:double_data[0] = get_real(infile,0);break; /* x-values */
  663.                     case 1:double_data[1] = get_real(infile,0);break; /* y-values */
  664.                     case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
  665.                     case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
  666.                     case 4:stroke_color = get_color(infile,1);/* name or hex color */
  667.                         decimals = find_number_of_digits(precision);
  668.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  669.                         click_cnt++;reset();
  670.                     break;
  671.                 }
  672.             }
  673.             break;
  674.         case DASHTYPE:
  675.         /*
  676.         @ dashtype int ,int
  677.         @ When dashed is set, the objects will be drawn with this dashtyp
  678.         @ default value "dashtype 2,2"
  679.         */
  680.             for(i=0;i<2;i++){
  681.                 switch(i){
  682.                     case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
  683.                     case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
  684.                 }
  685.             }
  686.         break;
  687.         case CIRCLE:
  688.         /*
  689.         @ circle xc,yc,width (2*r in pixels),color
  690.         @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk
  691.         @ use command 'fillcolor color' to set the fillcolor
  692.         @ may be set draggable / onclick
  693.         @ will shrink / expand on zoom out / zoom in
  694.         */
  695.             for(i=0;i<4;i++){
  696.                 switch(i){
  697.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  698.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  699.                     case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* radius in 'dx' xrange*/
  700.                     case 3: stroke_color = get_color(infile,1);/* name or hex color */
  701.                         decimals = find_number_of_digits(precision);
  702.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],double_data[2],double_data[2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  703.                         click_cnt++;reset();
  704.                     break;
  705.                 }
  706.             }
  707.             break;
  708.         case RAYS:
  709.         /*
  710.          @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
  711.          @ draw rays in color 'color' and center (xc:yc)
  712.          @ may be set draggable or onclick (the complete object, not an indiviual ray !)
  713.         */
  714.             stroke_color=get_color(infile,0);
  715.             i=0;
  716.             while( ! done ){     /* get next until EOL*/
  717.                 if(i > MAX_INT - 1){canvas_error("to much rays in argument: repeat command multiple times to fit");}
  718.                 if( i > 3){
  719.                     double_data[i++] = double_data[0];
  720.                     double_data[i++] = double_data[1];
  721.                 }
  722.                 for(c=0; c<=1 ;c++){ /* switch x2px / y2px */
  723.                     double_data[i++]= get_double(infile,c,1);
  724.                 }
  725.             }
  726.             decimals = find_number_of_digits(precision);
  727.             for(c=0; c<i;c = c+4){
  728.                 click_cnt++;
  729.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c+2],decimals,double_data[0],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);
  730.             }
  731.             reset();
  732.             break;
  733.         case ARROW:
  734.         /*
  735.         @ arrow x1,y1,x2,y2,h,color
  736.         @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
  737.         @ use command 'linewidth int' to adjust thickness of the arrow
  738.         @ may be set draggable / onclick
  739.         */
  740.             for(i=0;i<6;i++){
  741.                 switch(i){
  742.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  743.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  744.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  745.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  746.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  747.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  748.                         decimals = find_number_of_digits(precision);
  749.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  750.                         click_cnt++;
  751.                         reset();
  752.                         break;
  753.                 }
  754.             }
  755.             break;
  756.         case ARROW2:
  757.         /*
  758.         @ arrow2 x1,y1,x2,y2,h,color
  759.         @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
  760.         @ use command 'arrowhead int' to adjust the arrow head size
  761.         @ use command 'linewidth int' to adjust thickness of the arrow
  762.         @ may be set draggable / onclick
  763.         */
  764.             for(i=0;i<6;i++){
  765.                 switch(i){
  766.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  767.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  768.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  769.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  770.                     case 4: arrow_head = (int) get_real(infile,0);break;/* h */
  771.                     case 5: stroke_color = get_color(infile,1);/* name or hex color */
  772.                         decimals = find_number_of_digits(precision);
  773.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  774.                         click_cnt++;reset();
  775.                         break;
  776.                 }
  777.             }
  778.             break;
  779.         case PARALLEL:
  780.         /*
  781.          @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
  782.          @ can not be set "onclick" or "drag xy"
  783.         */
  784.             for( i = 0;i < 8; i++ ){
  785.                 switch(i){
  786.                     case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
  787.                     case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
  788.                     case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
  789.                     case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
  790.                     case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
  791.                     case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
  792.                     case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
  793.                     case 7: stroke_color=get_color(infile,1);/* name or hex color */
  794.                     decimals = find_number_of_digits(precision);
  795.                     fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,11,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d,%d],[%d,%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  796.                     click_cnt++;reset();
  797.                     break;
  798.                     default: break;
  799.                 }
  800.             }
  801.             break;
  802.         case TRIANGLE:
  803.         /*
  804.          @triangle x1,y1,x2,y2,x3,y3,color
  805.          @may be set draggable / onclic
  806.         */
  807.             for(i=0;i<7;i++){
  808.                 switch(i){
  809.                     case 0: double_data[0] = get_real(infile,0);break; /* x */
  810.                     case 1: double_data[1] = get_real(infile,0);break; /* y */
  811.                     case 2: double_data[2] = get_real(infile,0);break; /* x */
  812.                     case 3: double_data[3] = get_real(infile,0);break; /* y */
  813.                     case 4: double_data[4] = get_real(infile,0);break; /* x */
  814.                     case 5: double_data[5] = get_real(infile,0);break; /* y */
  815.                     case 6: stroke_color = get_color(infile,1);/* name or hex color */
  816.                         decimals = find_number_of_digits(precision);
  817.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  818.                         click_cnt++;reset();
  819.                         break;
  820.                     default: break;
  821.                 }
  822.             }
  823.             break;
  824.         case LATTICE:
  825.         /*
  826.          @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
  827.          @can not be set "onclick" or "drag xy"
  828.         */
  829.             if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
  830.             for( i = 0; i<9; i++){
  831.                 switch(i){
  832.                     case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
  833.                     case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
  834.                     case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
  835.                     case 3: int_data[3] = (int) (get_real(infile,0));break; /* y1-values  -> y-pixels*/
  836.                     case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
  837.                     case 5: int_data[5] = (int) (get_real(infile,0));break; /* y2-values  -> y-pixels*/
  838.                     case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
  839.                     case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
  840.                     case 8: stroke_color=get_color(infile,1);
  841.                         decimals = find_number_of_digits(precision);
  842.                         string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,[%d,%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_translate,translate_x,translate_y);
  843.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  844.                         snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,[%d,%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_translate,translate_x,translate_y);
  845.                         add_to_buffer(tmp_buffer);
  846.                     break;
  847.                     default:break;
  848.                 }
  849.             }
  850.             reset();
  851.             break;
  852.         case SNAPTOGRID:
  853.         /*
  854.          @ snaptogrid
  855.          @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
  856.          @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
  857.          @ if xminor / yminor is defined, the drawing will snap to xminor/yminor
  858.         */
  859.             fprintf(js_include_file,"\nuse_snap_to_grid = 1;\nfunction snap_to_x(x){return x2px(snap_x*(Math.round(snap_x*px2x(x))));};\nfunction snap_to_y(y){return y2px(snap_y*(Math.round(snap_y*px2y(y))));};\n");
  860.         break;
  861.         case USERDRAW:
  862.         /*
  863.         @ userdraw object_type,color
  864.         @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>segment</li><li>segments</li><li>circle</li><li>circles</li><li>arrow</li><li>arrows</li><li>triangle</li><li>polygon</li><li>poly[3-9]</li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline</li><li>freehandlines</li><li>path</li><li>paths</li><li>text</li></ul>
  865.         @ note: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required)
  866.         @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />while typing the background of every typed char will be lightblue..."backspace / delete / esc" will remove typed text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt()" : lightblue background will disappear<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" , a confirm will popup asking to delete the selected text.This text will be removed from the "userdraw_txt()" answer array.<br />Use commands 'fontsize' and 'fontfamily' to control the text appearance
  867.         @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
  868.         @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse butten (e.g. event.which != 1 : all buttons but left)
  869.         @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
  870.         @ use command "dashed" and/or "dashtype int,int" to trigger dashing
  871.         @ use command "debug" to view the output of javascript funcion read_canvas();
  872.         @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
  873.         @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
  874.         */
  875.             if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
  876.                 canvas_error("Only one userdraw primitive may be used: read documentation !!");
  877.             }
  878.             use_userdraw = TRUE;
  879.             fprintf(js_include_file,"<!-- begin userdraw mouse events -->\nvar userdraw_x = new Array();var userdraw_y = new Array();var userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};if(wims_status != \"done\"){canvas_div.addEventListener(\"mousedown\",user_draw,false);canvas_div.addEventListener(\"mousemove\",user_drag,false);canvas_div.addEventListener(\"touchstart\",user_draw,false);canvas_div.addEventListener(\"touchmove\",user_drag,false);}\n<!-- end userdraw mouse events -->\n",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
  880.             draw_type = get_string_argument(infile,0);
  881.             stroke_color = get_color(infile,1);
  882.             if( strcmp(draw_type,"point") == 0 ){
  883.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  884.                 if(reply_format < 1 ){reply_format = 8;}
  885.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  886.                 add_js_points(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);
  887.             }
  888.             else
  889.             if( strcmp(draw_type,"points") == 0 ){
  890.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  891.                 if(reply_format < 1 ){reply_format = 8;}
  892.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  893.                 add_js_points(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);
  894.             }
  895.             else
  896.             if( strcmp(draw_type,"segment") == 0 ){
  897.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  898.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  899.                 if(reply_format < 1){reply_format = 11;}
  900.                 add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  901.             }
  902.             else
  903.             if( strcmp(draw_type,"segments") == 0 ){
  904.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  905.                 if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
  906.                 if(reply_format < 1){reply_format = 11;}
  907.                 add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  908.             }
  909.             else
  910.             if( strcmp(draw_type,"circle") == 0 ){
  911.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  912.                 if(reply_format < 1){reply_format = 10;}
  913.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  914.                 add_js_circles(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  915.             }
  916.             else
  917.             if( strcmp(draw_type,"circles") == 0 ){
  918.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  919.                 if(reply_format < 1){reply_format = 10;}
  920.                 /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
  921.                 add_js_circles(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  922.             }
  923.             else
  924.             if(strcmp(draw_type,"crosshair") == 0 ){
  925.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  926.                 if(reply_format < 1){reply_format = 8;}
  927.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  928.                 add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  929.             }
  930.             else
  931.             if(strcmp(draw_type,"crosshairs") == 0 ){
  932.                 if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
  933.                 if(reply_format < 1){reply_format = 8;}
  934.                 /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
  935.                 add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
  936.             }
  937.             else
  938.             if(strcmp(draw_type,"freehandline") == 0 ){
  939.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  940.                 if(reply_format < 1){reply_format = 6;}
  941.                 add_js_paths(js_include_file,1,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);  
  942.             }
  943.             else
  944.             if(strcmp(draw_type,"freehandlines") == 0 ){
  945.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  946.                 if(reply_format < 1){reply_format = 6;}
  947.                 add_js_paths(js_include_file,2,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);  
  948.             }
  949.             else
  950.             if(strcmp(draw_type,"path") == 0 ){
  951.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  952.                 if(reply_format < 1){reply_format = 6;}
  953.                 add_js_paths(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);  
  954.             }
  955.             else
  956.             if(strcmp(draw_type,"paths") == 0 ){
  957.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  958.                 if(reply_format < 1){reply_format = 6;}
  959.                 add_js_paths(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);  
  960.             }
  961.             else
  962.             if(strcmp(draw_type,"arrows") == 0 ){
  963.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  964.                 if(reply_format < 1){reply_format = 11;}
  965.                 add_js_arrows(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  966.             }
  967.             else
  968.             if(strcmp(draw_type,"arrow") == 0 ){
  969.                 if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
  970.                 if(reply_format < 1){reply_format = 11;}
  971.                 add_js_arrows(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
  972.             }
  973.             else
  974.             if(strcmp(draw_type,"polygon") == 0){
  975.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  976.                 if(reply_format < 1){reply_format = 2;}
  977.                 add_js_poly(js_include_file,-1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  978.             }
  979.             else
  980.             if(strncmp(draw_type,"poly",4) == 0){
  981.                 if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
  982.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  983.                 if(reply_format < 1){reply_format = 2;}
  984.                 add_js_poly(js_include_file,(int) (draw_type[4]-'0'),draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  985.             }
  986.             else
  987.             if(strcmp(draw_type,"triangle") == 0){
  988.                 if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
  989.                 if(reply_format < 1){reply_format = 2;}
  990.                 add_js_poly(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  991.             }
  992.             else
  993.             if( strcmp(draw_type,"line") == 0 ){
  994.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  995.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  996.                 if(reply_format < 1){reply_format = 11;}
  997.                 add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  998.             }
  999.             else
  1000.             if( strcmp(draw_type,"lines") == 0 ){
  1001.                 if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
  1002.                 if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
  1003.                 if(reply_format < 1){reply_format = 11;}
  1004.                 add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
  1005.             }
  1006.             else
  1007.             if( strcmp(draw_type,"rects") == 0){
  1008.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  1009.                 if(reply_format < 1){reply_format = 2;}
  1010.                 add_js_rect(js_include_file,2,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1011.             }
  1012.             else
  1013.             if( strcmp(draw_type,"roundrects") == 0){
  1014.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  1015.                 if(reply_format < 1){reply_format = 2;}
  1016.                 add_js_rect(js_include_file,2,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1017.             }
  1018.             else
  1019.             if( strcmp(draw_type,"rect") == 0){
  1020.                 if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
  1021.                 if(reply_format < 1){reply_format = 2;}
  1022.                 add_js_rect(js_include_file,1,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1023.             }
  1024.             else
  1025.             if( strcmp(draw_type,"roundrect") == 0){
  1026.                 if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
  1027.                 if(reply_format < 1){reply_format = 2;}
  1028.                 add_js_rect(js_include_file,1,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
  1029.             }
  1030.             else
  1031.             if( strcmp(draw_type,"text") == 0){
  1032.                 if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}      
  1033.                 if(reply_format < 1){reply_format = 17;}
  1034.                 add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity,use_rotate,angle,use_translate,translate_x,translate_y);
  1035.             }
  1036.             else
  1037.             {
  1038.                 canvas_error("unknown drawtype or typo? ");
  1039.             }
  1040.             reset();
  1041.         break;
  1042.         case PLOTSTEPS:
  1043.             /*
  1044.              @ plotsteps a_number
  1045.              @ default 150
  1046.              @ use with care !
  1047.             */
  1048.             plot_steps = (int) (get_real(infile,1));
  1049.             break;
  1050.         case FONTSIZE:
  1051.         /*
  1052.          @fontsize font_size
  1053.          @default value 12
  1054.         */
  1055.             font_size = (int) (get_real(infile,1));
  1056.             break;
  1057.         case FONTCOLOR:
  1058.         /*
  1059.          @fontcolor color
  1060.          @color: hexcolor or colorname
  1061.          @default: black
  1062.          @example usage: x/y-axis text
  1063.         */
  1064.             font_color = get_color(infile,1);
  1065.             break;
  1066.         case ANIMATE:
  1067.         /*
  1068.          @animate type
  1069.          @type may be "point" (nothing else , yet...)
  1070.          @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
  1071.          @will animate a point on the next plot/curve command
  1072.          @the curve will not be draw
  1073.          @moves repeatedly from xmin to xmax
  1074.         */
  1075.             if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
  1076.             break;
  1077.         case CURVE:
  1078.         /*
  1079.          @curve color,formula(x)
  1080.          @plot color,formula(x)
  1081.          @use command trange before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
  1082.          @use command "precision" to increase the number of digits of the plotted points
  1083.          @use command "plotsteps" to increase / decrease the amount of plotted points (default 150)
  1084.          @may be set draggable / onclick
  1085.         */
  1086.             if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
  1087.                 use_parametric = FALSE;
  1088.                 stroke_color = get_color(infile,0);
  1089.                 char *fun1 = get_string_argument(infile,0);
  1090.                 char *fun2 = get_string_argument(infile,1);
  1091.                 if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
  1092.                 use_parametric = FALSE;
  1093.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,animation_type,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  1094.                 click_cnt++;
  1095.             }
  1096.             else
  1097.             {
  1098.                 stroke_color = get_color(infile,0);
  1099.                 char *fun1 = get_string_argument(infile,1);
  1100.                 if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} 
  1101.                 fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,animation_type,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family);
  1102.                 click_cnt++;
  1103.             }
  1104.             animation_type = 9;/* rest to curve plotting without animation */
  1105.             reset();
  1106.             break;
  1107.         case FLY_TEXT:
  1108.         /*
  1109.         @ text fontcolor,x,y,font,text_string
  1110.         @ font may be described by keywords : giant,huge,normal,small,tiny
  1111.         @ use command 'fontsize' to increase base fontsize for the keywords
  1112.         @ may be set "onclick" or "drag xy"
  1113.         @ backwards compatible with flydraw
  1114.         @ unicode supported: text red,0,0,huge,\\u2232
  1115.         @ use command 'string' and 'fontfamily' for a more fine grained control over html5 canvas text element
  1116.         @ Avoid  mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case rested 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
  1117.         */
  1118.             for(i = 0; i < 5 ;i++){
  1119.                 switch(i){
  1120.                     case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
  1121.                     case 1: double_data[0] = get_real(infile,0);break; /* x */
  1122.                     case 2: double_data[1] = get_real(infile,0);break; /* y */
  1123.                     case 3: fly_font = get_string_argument(infile,0);
  1124.                             if(strcmp(fly_font,"giant") == 0){
  1125.                                 font_size = (int)(font_size + 24);
  1126.                             }
  1127.                             else
  1128.                             {
  1129.                                 if(strcmp(fly_font,"huge") == 0){
  1130.                                     font_size = (int)(font_size + 14);
  1131.                                 }
  1132.                                 else
  1133.                                 {
  1134.                                     if(strcmp(fly_font,"large") == 0){
  1135.                                         font_size = (int)(font_size + 6);
  1136.                                         }
  1137.                                         else
  1138.                                         {
  1139.                                             if(strcmp(fly_font,"small") == 0){
  1140.                                                 font_size = (int)(font_size - 4);
  1141.                                                 if(font_size<0){font_size = 8;}
  1142.                                         }
  1143.                                     }
  1144.                                 }
  1145.                             }
  1146.                             break; /* font_size ! */
  1147.                     case 4:
  1148.                         temp = get_string_argument(infile,1);
  1149.                         decimals = find_number_of_digits(precision);
  1150.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%d,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,0,0,temp,font_size,font_family);
  1151.                         click_cnt++;reset();break;
  1152.                     default:break;
  1153.                 }
  1154.             }
  1155.             break;
  1156.         case FLY_TEXTUP:
  1157.         /*
  1158.          @ textup fontcolor,x,y,font,text_string
  1159.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  1160.          @ font may be described by keywords : giant,huge,normal,small,tiny
  1161.          @ use command 'fontsize' to increase base fontsize for the keywords
  1162.          @ backwards compatible with flydraw
  1163.          @ unicode supported: textup red,0,0,huge,\\u2232
  1164.          @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
  1165.          @ Avoid  mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case rested 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
  1166.         */
  1167.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}  
  1168.             for(i = 0; i<5 ;i++){
  1169.                 switch(i){
  1170.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  1171.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  1172.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  1173.                     case 3: fly_font = get_string_argument(infile,0);
  1174.                             if(strcmp(fly_font,"giant") == 0){
  1175.                                 font_size = (int)(font_size + 24);
  1176.                             }
  1177.                             else
  1178.                             {
  1179.                                 if(strcmp(fly_font,"huge") == 0){
  1180.                                     font_size = (int)(font_size + 14);
  1181.                                 }
  1182.                                 else
  1183.                                 {
  1184.                                     if(strcmp(fly_font,"large") == 0){
  1185.                                         font_size = (int)(font_size + 6);
  1186.                                         }
  1187.                                         else
  1188.                                         {
  1189.                                             if(strcmp(fly_font,"small") == 0){
  1190.                                                 font_size = (int)(font_size - 4);
  1191.                                                 if(font_size<0){font_size = 8;}
  1192.                                         }
  1193.                                     }
  1194.                                 }
  1195.                             }
  1196.                             break; /* font_size ! */
  1197.                     case 4:
  1198.                     decimals = find_number_of_digits(precision);
  1199.                     temp = get_string_argument(infile,1);
  1200.                     string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_translate,translate_x,translate_y);
  1201.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1202.                     snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_translate,translate_x,translate_y);
  1203.                     add_to_buffer(tmp_buffer);
  1204.                     break;
  1205.                     default:break;
  1206.                 }
  1207.             }
  1208.             reset();
  1209.             break;
  1210.         case FONTFAMILY:
  1211.         /*
  1212.          @ fontfamily font_description
  1213.          @ set the font family; for browsers that support it
  1214.          @ font_description: Ariel ,Courier, Helvetica etc
  1215.          @ in case commands<br /> 'string color,x,y,the string'<br /> 'stringup color,x,y,rotation,the string'<br />fontfamily can be something like:<br />italic 34px Ariel
  1216.          @ use correct syntax : 'font style' 'font size'px 'fontfamily'
  1217.         */
  1218.             font_family = get_string(infile,1);
  1219.             break;
  1220.         case STRINGUP:
  1221.         /*
  1222.          @ stringup color,x,y,rotation_degrees,the text string
  1223.          @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
  1224.          @ unicode supported: stringup red,0,0,45,\\u2232
  1225.          @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
  1226.  
  1227.         */
  1228.             if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
  1229.             for(i=0;i<6;i++){
  1230.                 switch(i){
  1231.                     case 0: font_color = get_color(infile,0);break;/* name or hex color */
  1232.                     case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
  1233.                     case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
  1234.                     case 3: double_data[0] = get_real(infile,0);break;/* rotation */
  1235.                     case 4: decimals = find_number_of_digits(precision);
  1236.                             temp = get_string_argument(infile,1);
  1237.                             string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_translate,translate_x,translate_y);
  1238.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1239.                             snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,[%d,%d]);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_translate,translate_x,translate_y);
  1240.                             add_to_buffer(tmp_buffer);
  1241.                             break;
  1242.                     default:break;
  1243.                 }
  1244.             }
  1245.             reset();
  1246.             break;
  1247.         case STRING:
  1248.         /*
  1249.          @ string color,x,y,the text string
  1250.          @ may be set "onclick" or "drag xy"
  1251.          @ unicode supported: string red,0,0,\\u2232
  1252.          @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
  1253.         */
  1254.             for(i=0;i<5;i++){
  1255.                 switch(i){
  1256.                     case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
  1257.                     case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
  1258.                     case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
  1259.                     case 3: decimals = find_number_of_digits(precision);
  1260.                         temp = get_string_argument(infile,1);
  1261.                         decimals = find_number_of_digits(precision);
  1262.                         fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%d,\"%s\",%d,\"%s\"));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,0,0,temp,font_size,font_family);
  1263.                         click_cnt++;reset();break;
  1264.                             break;
  1265.                     default:break;
  1266.                 }
  1267.             }
  1268.             break;
  1269.         case MATHML:
  1270.         /*
  1271.         @ mathml x1,y1,x2,y2,mathml_string
  1272.         @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2)
  1273.         @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  1274.         @ 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 />attention: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();"
  1275.         @ 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....
  1276.         */
  1277.             if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
  1278.             for(i=0;i<5;i++){
  1279.                 switch(i){
  1280.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  1281.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  1282.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  1283.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  1284.                     case 4: decimals = find_number_of_digits(precision);
  1285.                             if(onclick == 1 ){ onclick = click_cnt;click_cnt++;}
  1286.                             temp = get_string(infile,1);
  1287.                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
  1288.                             string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick);
  1289.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1290.                             snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick);
  1291.                             add_to_buffer(tmp_buffer);
  1292.                             /*
  1293.                              in case inputs are present , trigger adding the read_mathml()
  1294.                              if no other reply_format is defined
  1295.                              note: all other reply types will include a reading of elements with id='mathml'+p)
  1296.                              */
  1297.                             if(strstr(temp,"mathml0") != NULL){
  1298.                              if(reply_format < 1 ){reply_format = 16;} /* no other reply type is defined */
  1299.                             }
  1300.                             break;
  1301.                     default:break;
  1302.                 }
  1303.             }
  1304.             reset();
  1305.             break;
  1306.         case HTTP:
  1307.         /*
  1308.          @http x1,y1,x2,y2,http://some_adress.com
  1309.          @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
  1310.          @do not use interactivity (or mouse) if the mouse needs to be active in the iframe
  1311.          @can not be 'set onclick' or 'drag xy'
  1312.         */
  1313.             if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}    
  1314.             for(i=0;i<5;i++){
  1315.                 switch(i){
  1316.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
  1317.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
  1318.                     case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
  1319.                     case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
  1320.                     case 4: decimals = find_number_of_digits(precision);
  1321.                             temp = get_string(infile,1);
  1322.                             if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
  1323.                             string_length = snprintf(NULL,0,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
  1324.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1325.                             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);
  1326.                             add_to_buffer(tmp_buffer);
  1327.                     break;
  1328.                 }
  1329.             }
  1330.             reset();
  1331.             break;
  1332.         case HTML:
  1333.         /*
  1334.          @ html x1,y1,x2,y2,html_string
  1335.          @ all tags are allowed
  1336.          @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
  1337.          @ if inputfields are incorporated  (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_canvas(); <br />If other inputfields (command input / command textarea) or userdraw is performed, these values will NOT be read as well.
  1338.          
  1339.          note: uses the same code as 'mathml'
  1340.         */
  1341.             break;
  1342.         case X_AXIS_STRINGS:
  1343.         /*
  1344.          @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1345.          @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1346.          @ use these x-axis values in stead of default xmin...xmax
  1347.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1348.          @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied
  1349.          @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 1,100,grey,1,4,6,grey
  1350.          @ example:<br />size 400,400<br />xrange -5*pi,5*pi<br />yrange -100,500<br />axis<br />xaxis -4*pi:-4\\u03c0:-3*pi:-3\\u03c0:-2*pi:-2\\u03c0:-1*pi:-\\u03c0:0:0:pi:\\u03c0:2*pi:2\\u03c01:3*pi:3\\u03c0:4*pi:4\\u03c0<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid pi,1,grey,1,3,6,grey
  1351.         */
  1352.             temp = get_string(infile,1);
  1353.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  1354.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  1355.             fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
  1356.             use_axis_numbering = 1;
  1357.             break;
  1358.         case Y_AXIS_STRINGS:
  1359.         /*
  1360.          @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1361.          @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
  1362.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1363.          @ use these y-axis values in stead of default ymin...ymax
  1364.          @ example:<br />size 400,400<br />yrange 0,13<br />xrange -100,500<br />axis<br />yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'ymajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 100,1,grey,4,1,6,grey
  1365.         */
  1366.             temp = get_string(infile,1);
  1367.             if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
  1368.             if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
  1369.             fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
  1370.             use_axis_numbering = 1;
  1371.             break;
  1372.          
  1373.         case AXIS_NUMBERING:
  1374.         /*
  1375.             @ axisnumbering
  1376.             @ keyword, no aguments required
  1377.         */
  1378.             use_axis_numbering = 1;
  1379.             break;
  1380.         case AXIS:
  1381.         /*
  1382.             @ axis
  1383.             @ keyword, no aguments required
  1384.  
  1385.         */
  1386.             use_axis = TRUE;
  1387.             break;
  1388.         case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/
  1389.         /*
  1390.          @ grid step_x,step_y,gridcolor
  1391.          @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
  1392.          @ if keywords "axis" or "axisnumbering" are set, use :<br />grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color<br />minor x step = step_x / minor_x
  1393.          @ can not be set "onclick" or "drag xy"
  1394.          @ use commands 'xlabel some_string' and/or 'ylabel some_string' to label axis;<br />use command "fontsize" to adjust size (the font family is non-configurable 'italic your_fontsize px Ariel')
  1395.          @ see commands "xaxis" or "xaxistext", "yaxis" or "yaxistext" to set tailormade values on axis (the used font is set by command fontfamily; default '12px Ariel')
  1396.          @ see command "legend" to set a legend for the graph ;<br />use command "fontsize" to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
  1397.         */
  1398.             if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
  1399.             for(i=0;i<4;i++){
  1400.                 switch(i){
  1401.                     case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
  1402.                     case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
  1403.                     case 2:
  1404.                     if( use_axis == TRUE ){
  1405.                         stroke_color = get_color(infile,0);
  1406.                         done = FALSE;
  1407.                         int_data[0] = (int) (get_real(infile,0));/* xminor */
  1408.                         int_data[1] = (int) (get_real(infile,0));/* yminor */
  1409.                         int_data[2] = (int) (get_real(infile,0));/* tic_length */
  1410.                         fill_color = get_color(infile,1); /* used as axis_color*/
  1411.                         fprintf(js_include_file,"var snap_x = %f;var snap_y = %f\n",double_data[0]/int_data[0],double_data[1]/int_data[1]);
  1412.                     }
  1413.                     else
  1414.                     {
  1415.                         int_data[0] = 1;
  1416.                         int_data[1] = 1;
  1417.                         stroke_color = get_color(infile,1);
  1418.                         fill_color = stroke_color;
  1419.                         fprintf(js_include_file,"var snap_x = %f;var snap_y = %f\n",double_data[0],double_data[1]);
  1420.                     }
  1421.                     if( double_data[0] <= 0 ||  double_data[1] <= 0 ||  int_data[0] <= 0 ||  int_data[1] <= 0 ){canvas_error("major or minor tickt must be positive !");}
  1422. /* draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_translate,vector,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){ */
  1423.  
  1424.                     string_length = snprintf(NULL,0,  "draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,[%d,%d],%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_translate,translate_x,translate_y,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
  1425.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1426.                     snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,[%d,%d],%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_translate,translate_x,translate_y,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
  1427.                     add_to_buffer(tmp_buffer);
  1428.                     break;
  1429.                 }
  1430.             }
  1431.             reset();
  1432.             break;
  1433.         case OPACITY:
  1434.         /*
  1435.         @ opacity 0-255,0-255
  1436.         @
  1437.         */
  1438.             for(i = 0 ; i<2;i++){
  1439.                 switch(i){
  1440.                     case 0: double_data[0]=(int)(get_real(infile,0));break;
  1441.                     case 1: double_data[1]=(int)(get_real(infile,1));break;
  1442.                     default: break;
  1443.                 }
  1444.             }
  1445.             if( double_data[0] < 0 || double_data[0] > 255 || double_data[1] < 0 || double_data[1] > 255  ){ canvas_error("opacity [0 - 255] , [0 - 255]");}/* typo or non-RGB ? */
  1446.             stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */
  1447.             fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */
  1448.             break;
  1449.         case ROTATE:
  1450.         /*
  1451.          @rotate rotation_angle
  1452.          @
  1453.         */
  1454.             use_rotate = TRUE;
  1455.             use_translate = TRUE;
  1456.             translate_x = x2px(0);
  1457.             translate_y = y2px(0);
  1458.             angle = get_real(infile,1);
  1459.             break;
  1460.         case KILLTRANSLATION:
  1461.         /*
  1462.          killtranslation
  1463.         */
  1464.             break;
  1465.         case TRANSLATION:
  1466.         /*
  1467.          @translation tx,ty
  1468.          @
  1469.         */
  1470.             use_translate = TRUE;
  1471.             translate_x = get_real(infile,0);
  1472.             translate_y = get_real(infile,1);
  1473.             break;
  1474.         case DASHED:
  1475.         /*
  1476.         @ keyword "dashed"
  1477.         @ next object will be drawn with a dashed line
  1478.         @ change dashing scheme by using command "dashtype int,int)
  1479.         */
  1480.             use_dashed = TRUE;
  1481.             break;
  1482.         case FILLED:
  1483.         /*
  1484.         @ keyword "filled"
  1485.         @ the next 'fillable' object (only) will be filled
  1486.         @ use command "fillcolor color" to set fillcolor
  1487.         @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
  1488.         @ use command "fill x,y,color" or "floodfill x,y,color" to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care !
  1489.         */
  1490.             use_filled = TRUE;
  1491.             break;
  1492.         case STYLE:
  1493.         /*
  1494.          @highlight color,opacity,linewidth
  1495.          @ NOT IMPLEMENTED
  1496.          @ use command "onclick" : when the object receives a userclick it will increase it's linewidth
  1497.         */
  1498.             break;
  1499.         case FILLCOLOR:
  1500.         /*
  1501.         @ fillcolor colorname or #hex
  1502.         @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
  1503.         @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...)
  1504.         */
  1505.             fill_color = get_color(infile,1);
  1506.             break;
  1507.         case STROKECOLOR:
  1508.         /*
  1509.         @ strokecolor colorname or #hex
  1510.         @ to be used for commands that do not supply a color argument (like command 'linegraph')
  1511.         */
  1512.             stroke_color = get_color(infile,1);
  1513.             break;
  1514.         case BGIMAGE:
  1515.         /*
  1516.          @bgimage image_location
  1517.          @use an image as background .<br />(we use the background of 'canvas_div' )
  1518.          @the background image will be resized to match "width = xsize" and "height = ysize"
  1519.         */
  1520.         URL = get_string(infile,1);
  1521.         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);
  1522.             break;
  1523.         case BGCOLOR:
  1524.         /*
  1525.          @bgcolor colorname or #hex
  1526.          @use this color as background of the "div" containing the canvas(es)
  1527.         */
  1528.         /* [255,255,255]*/
  1529.             bgcolor = get_string(infile,1);
  1530.             if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
  1531.                 int found = 0;
  1532.                 for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
  1533.                     if( strcmp( colors[i].name , bgcolor ) == 0 ){
  1534.                         bgcolor = colors[i].hex;
  1535.                         found = 1;
  1536.                         break;
  1537.                     }
  1538.                 }
  1539.                 if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
  1540.             }
  1541.             fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
  1542.             break;
  1543.         case COPY:
  1544.         /*
  1545.         @ copy x,y,x1,y1,x2,y2,[filename URL]
  1546.         @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
  1547.         @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
  1548.         @ [filename] is the URL of the image   
  1549.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  1550.         @ if command 'drag x/y/xy' 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 valuid for the next image<br />draggable / non-draggable images may be mixed
  1551.         @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
  1552.  
  1553.         context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  1554.         draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){
  1555.         */
  1556.             for(i = 0 ; i<7;i++){
  1557.                 switch(i){
  1558.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
  1559.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
  1560.                     case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
  1561.                     case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
  1562.                     case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
  1563.                     case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
  1564.                     case 6: URL = get_string(infile,1);
  1565.                             int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
  1566.                             int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
  1567.                             if( drag_type > -1 ){
  1568.                                 if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
  1569.                                 if(reply_format < 1 ){reply_format = 20;}
  1570.                                 string_length = snprintf(NULL,0,"drag_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],ext_img_cnt,1);
  1571.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1572.                                 snprintf(tmp_buffer,string_length,"drag_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],ext_img_cnt,1);                       
  1573.                                 drag_type = -1;
  1574.                                 ext_img_cnt++;
  1575.                             }
  1576.                             else
  1577.                             {
  1578.                                 if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  1579.                                 /*
  1580.                                 draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\
  1581.                                 */
  1582.                                 string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\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]);
  1583.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1584.                                 snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\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]);
  1585.                             }
  1586.                             add_to_buffer(tmp_buffer);
  1587.                             break;
  1588.                     default: break;
  1589.                 }
  1590.             }
  1591.             reset();
  1592.             break;
  1593. /*
  1594. context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
  1595. img     Specifies the image, canvas, or video element to use
  1596. sx      The x coordinate where to start clipping : x1 = int_data[0]
  1597. sy      The y coordinate where to start clipping : x2 = int_data[1]
  1598. swidth  The width of the clipped image : int_data[2] - int_data[0]
  1599. sheight The height of the clipped image : int_data[3] - int_data[1]
  1600. x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
  1601. y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
  1602. width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
  1603. height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
  1604. */
  1605.         case COPYRESIZED:
  1606.         /*
  1607.         @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
  1608.         @ 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
  1609.         @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
  1610.         @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
  1611.         @ if command 'drag x/y/xy' 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 valuid for the next image<br />draggable / non-draggable images may be mixed
  1612.         @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
  1613.         */
  1614.             for(i = 0 ; i<9;i++){
  1615.                 switch(i){
  1616.                     case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
  1617.                     case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
  1618.                     case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
  1619.                     case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
  1620.                     case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
  1621.                     case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
  1622.                     case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
  1623.                     case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
  1624.                     case 8: URL = get_string(infile,1);
  1625.                             if( drag_type > -1 ){
  1626.                                 if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
  1627.                                 if(reply_format < 1 ){reply_format = 20;}
  1628.                                 string_length = snprintf(NULL,0,"drag_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],ext_img_cnt,1);
  1629.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1630.                                 snprintf(tmp_buffer,string_length,"drag_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],ext_img_cnt,1);
  1631.                                 drag_type = -1;
  1632.                                 ext_img_cnt++;
  1633.                             }
  1634.                             else
  1635.                             {
  1636.                                 if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
  1637.                                 string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\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]);
  1638.                                 check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1639.                                 snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\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]);
  1640.                             }
  1641.                             add_to_buffer(tmp_buffer);
  1642.                     default: break;
  1643.                 }
  1644.             }
  1645.             reset();
  1646.             break;
  1647.         case BUTTON:
  1648.         /*
  1649.          button x,y,value
  1650.         */
  1651.         break;
  1652.         case INPUTSTYLE:
  1653.         /*
  1654.         @ inputstyle style_description
  1655.         @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
  1656.         */
  1657.             input_style = get_string(infile,1);
  1658.             break;
  1659.         case INPUT:
  1660.         /*
  1661.          @ input x,y,size,editable,value
  1662.          @ to set inputfield "readonly", use editable = 0
  1663.          @ only active inputfields (editable = 1) will be read with read_canvas();
  1664.          @ may be further controlled by "inputstyle" (inputcss is not yet implemented...)
  1665.          @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
  1666.         */
  1667.         if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}    
  1668.             for(i = 0 ; i<5;i++){
  1669.                 switch(i){
  1670.                     case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
  1671.                     case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
  1672.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
  1673.                     case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
  1674.                     case 4:
  1675.                             temp = get_string_argument(infile,1);
  1676.                             string_length = snprintf(NULL,0,  "draw_inputs(%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],input_style,temp);
  1677.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1678.                             snprintf(tmp_buffer,string_length,"draw_inputs(%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],input_style,temp);
  1679.                             add_to_buffer(tmp_buffer);
  1680.                             input_cnt++;break;
  1681.                     default: break;
  1682.                 }
  1683.             }
  1684.             if(reply_format < 1 ){reply_format = 15;}
  1685.             reset();
  1686.             break;
  1687.         case TEXTAREA:
  1688.         /*
  1689.          @ textarea x,y,cols,rows,readonly,value
  1690.          @ may be further controlled by "inputstyle"
  1691.          @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
  1692.         */
  1693.             if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}  
  1694.             for(i = 0 ; i<6;i++){
  1695.                 switch(i){
  1696.                     case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
  1697.                     case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
  1698.                     case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
  1699.                     case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
  1700.                     case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
  1701.                     case 5: temp = get_string_argument(infile,1);
  1702.                             string_length = snprintf(NULL,0,  "draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp);
  1703.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1704.                             snprintf(tmp_buffer,string_length,"draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp);
  1705.                             add_to_buffer(tmp_buffer);
  1706.                             input_cnt++;break;
  1707.                     default: break;
  1708.                 }
  1709.             }
  1710.             if(reply_format < 1 ){reply_format = 15;}
  1711.             reset();
  1712.             break;
  1713.         case MOUSE_PRECISION:
  1714.         /*
  1715.             @ precision int
  1716.             @ 10 = 1 decimal ; 100 = 2 decimals etc
  1717.             @ may be used / changed before every object
  1718.         */
  1719.             precision = (int) (get_real(infile,1));
  1720.             break;
  1721.         case ZOOM:
  1722.         /*
  1723.          @ zoom button_color
  1724.          @ introduce a controlpanel at the lower right corner
  1725.          @ giving six 15x15pixel 'active' rectangle areas<br />(for x,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image
  1726.          @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
  1727.          @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
  1728.          @ command 'opacity' may be used to set stroke_opacity of 'buttons
  1729.          @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned
  1730.          @ NOTE: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !!
  1731.         */
  1732.             fprintf(js_include_file,"use_pan_and_zoom = 1;\n");
  1733.             if( js_function[DRAW_ZOOM_BUTTONS] != 1 ){ js_function[DRAW_ZOOM_BUTTONS] = 1;}
  1734.             /* we use BG_CANVAS (0) */
  1735.             stroke_color = get_color(infile,1);
  1736.             string_length = snprintf(NULL,0," draw_zoom_buttons(%d,\"%s\",%f);\n",BG_CANVAS,stroke_color,stroke_opacity);
  1737.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1738.             snprintf(tmp_buffer,MAX_BUFFER-1,"draw_zoom_buttons(%d,\"%s\",%f);\n",BG_CANVAS,stroke_color,stroke_opacity);
  1739.             add_to_buffer(tmp_buffer);
  1740.             done = TRUE;
  1741.             break;
  1742.         case ONCLICK:
  1743.         /*
  1744.          @ onclick
  1745.          @ keyword, no arguments
  1746.          @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas();
  1747.          @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked.
  1748.          @ NOTE: not all objects  may be set clickable
  1749.         */
  1750.            
  1751.             onclick = 1;
  1752.             break;
  1753.         case DRAG:
  1754.         /*
  1755.          @ drag [x][y][xy]
  1756.          @ the next object will be draggable in x / y / xy direction
  1757.          @ the displacement can be read by 'javascript:read_dragdrop();'
  1758.          @ 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.
  1759.          @ NOTE: in case an object is dragged , zooming or panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !!
  1760.         */
  1761.             temp = get_string(infile,1);
  1762.             if(strstr(temp,"xy") != NULL ){
  1763.                 drag_type = 0;
  1764.             }
  1765.             else
  1766.             {
  1767.                 if(strstr(temp,"x") != NULL ){
  1768.                     drag_type = 1;
  1769.                 }
  1770.                 else
  1771.                 {
  1772.                     drag_type = 2;
  1773.                 }
  1774.             }
  1775.             onclick = 2;
  1776.             /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
  1777.             break;
  1778.         case BLINK:
  1779.         /*
  1780.          @ blink time(seconds)
  1781.          @ NOT IMPLEMETED -YET
  1782.         */
  1783.             break;
  1784.         case MOUSE:
  1785.         /*
  1786.          @ mouse color,fontsize
  1787.          @ will display the cursor coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
  1788.         */
  1789.             use_mouse_coordinates = TRUE; /* will add & call function "use_mouse_coordinates(){}" in current_canvas /current_context */
  1790.             stroke_color = get_color(infile,0);
  1791.             font_size = (int) (get_real(infile,1));
  1792.             add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity);
  1793.             break;
  1794.         case INTOOLTIP:
  1795.             /*
  1796.             @ intooltip link_text
  1797.             @ link_text is a single line (span-element)
  1798.             @ link_text may also be an image URL http://some_server/images/my_image.png
  1799.             @ link_text may contain HTML markup
  1800.             @ the canvas will be displayed in a tooltip on 'link_text'
  1801.             @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor.
  1802.             */
  1803.             use_tooltip = TRUE;
  1804.             tooltip_text = get_string(infile,1);
  1805.             if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
  1806.             break;
  1807.         case AUDIO:
  1808.         /*
  1809.         @ audio x,y,w,h,loop,visible,audiofile location
  1810.         @ x,y : left top corner of audio element (in xrange / yrange)
  1811.         @ w,y : width and height in pixels
  1812.         @ loop : 0 or 1 ( 1 = loop audio fragment)
  1813.         @ visible : 0 or 1 (1 = show controls)
  1814.         @ audio format may be in *.mp3 or *.ogg
  1815.         @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
  1816.         @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
  1817.         @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
  1818.         @ example: upload both audio1.ogg and audio1.mp3 to http://server/files/<br />audio 0,0,http://server/files/audio1.mp3<br />svdraw will copy html-tag audio1.mp3 to audio1.ogg<br /> and the browser will play the compatible file (audio1.ogg or audio1.mp3)<br />
  1819.         */
  1820.             if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
  1821.             for(i=0;i<7;i++){
  1822.                 switch(i){
  1823.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  1824.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  1825.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  1826.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  1827.                     case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
  1828.                     case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
  1829.                     case 6:
  1830.                     temp = get_string(infile,1);
  1831.                     if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
  1832.                     if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
  1833.                     string_length = snprintf(NULL,0,  "draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp);
  1834.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1835.                     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);
  1836.                     add_to_buffer(tmp_buffer);
  1837.                     break;
  1838.                     default:break;
  1839.                 }
  1840.             }
  1841.             reset();
  1842.             break;
  1843.         case VIDEO:
  1844.         /*
  1845.         @ video x,y,w,h,videofile location
  1846.         @ x,y : left top corner of audio element (in xrange / yrange)
  1847.         @ w,y : width and height in pixels
  1848.         @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
  1849.         @ video format may be in *.mp4 (todo:other formats)
  1850.         */
  1851.             if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
  1852.             for(i=0;i<5;i++){
  1853.                 switch(i){
  1854.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
  1855.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
  1856.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
  1857.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
  1858.                     case 4: temp = get_string(infile,1);
  1859.                             string_length = snprintf(NULL,0,  "draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
  1860.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1861.                             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);
  1862.                             add_to_buffer(tmp_buffer);
  1863.                             break;
  1864.                     default:break;
  1865.                 }
  1866.             }
  1867.             reset();
  1868.             break;
  1869.         case HATCHFILL:
  1870.         /*
  1871.         @ hatchfill x0,y0,dx,dy,color
  1872.         @ x0,y0 in xrange / yrange
  1873.         @ distances dx,dy in pixels
  1874.         */
  1875.             if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
  1876.             for(i=0;i<5;i++){
  1877.                 switch(i){
  1878.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  1879.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  1880.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  1881.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1882.                     case 4: stroke_color = get_color(infile,1);
  1883.                     /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  1884.                     string_length = snprintf(NULL,0,  "draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1885.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1886.                     snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1887.                     add_to_buffer(tmp_buffer);
  1888.                     break;
  1889.                     default:break;
  1890.                 }
  1891.             }
  1892.             reset();
  1893.         break;
  1894.         case GRIDFILL:
  1895.         /*
  1896.         @ gridfill x0,y0,dx,dy,color
  1897.         @ x0,y0 in xrange / yrange
  1898.         @ distances dx,dy in pixels
  1899.         */
  1900.             if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
  1901.             for(i=0;i<5;i++){
  1902.                 switch(i){
  1903.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  1904.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  1905.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  1906.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1907.                     case 4: stroke_color = get_color(infile,1);
  1908.                     /* draw_gridfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
  1909.                     string_length = snprintf(NULL,0,  "draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1910.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1911.                     snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1912.                     add_to_buffer(tmp_buffer);
  1913.                     break;
  1914.                     default:break;
  1915.                 }
  1916.             }
  1917.             reset();
  1918.         break;
  1919.         case DOTFILL:
  1920.         /*
  1921.         @ dotfill x0,y0,dx,dy,color
  1922.         @ x0,y0 in xrange / yrange
  1923.         @ distances dx,dy in pixels
  1924.         @ radius of dots is linewidth
  1925.         */
  1926.             if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
  1927.             for(i=0;i<5;i++){
  1928.                 switch(i){
  1929.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  1930.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  1931.                     case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
  1932.                     case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
  1933.                     case 4: stroke_color = get_color(infile,1);
  1934.                     /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
  1935.                     string_length = snprintf(NULL,0,  "draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1936.                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1937.                     snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
  1938.                     add_to_buffer(tmp_buffer);
  1939.                     break;
  1940.                     default:break;
  1941.                 }
  1942.             }
  1943.             reset();
  1944.         break;
  1945.         case IMAGEFILL:
  1946.         /*
  1947.         @ imagefill dx,dy,image_url
  1948.         @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
  1949.         @ After pattern filling ,the fill-color should be reset !
  1950.         @ wims getins / image from class directory : imagefill 80,80,my_image.gif
  1951.         @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
  1952.         @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
  1953.         @ if dx,dy is larger than the image, the whole image will be background to the next object.
  1954.         */
  1955.             if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
  1956.             for(i=0 ;i < 3 ; i++){
  1957.                 switch(i){
  1958.                     case 0:int_data[0] = (int) (get_real(infile,0));break;
  1959.                     case 1:int_data[1] = (int) (get_real(infile,0));break;
  1960.                     case 2: URL = get_string_argument(infile,1);
  1961.                             string_length = snprintf(NULL,0,  "draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize);
  1962.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1963.                             snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize);
  1964.                             add_to_buffer(tmp_buffer);
  1965.                     break;
  1966.                 }
  1967.             }
  1968.         break;
  1969.         case FILLTOBORDER:
  1970.         /*
  1971.         @ filltoborder x,y,bordercolor,color
  1972.         @ fill the region  of point (x:y) bounded by 'bordercolor' with color 'color'
  1973.         @ any other color will not act as border to the bucket fill
  1974.         @ use this command  after all boundary objects are declared.
  1975.         @ NOTE: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU..
  1976.         */
  1977.             for(i=0 ;i < 4 ; i++){
  1978.                 switch(i){
  1979.                     case 0:double_data[0] = get_real(infile,0);break;
  1980.                     case 1:double_data[1] = get_real(infile,0);break;
  1981.                     case 2:bgcolor = get_color(infile,0);break;
  1982.                     case 3:fill_color = get_color(infile,1);
  1983.                            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
  1984.                                 js_function[DRAW_FILLTOBORDER] = 1;
  1985.                                 add_js_filltoborder(js_include_file,canvas_root_id);
  1986.                            }
  1987.                            decimals = find_number_of_digits(precision);
  1988.                            string_length = snprintf(NULL,0,  "filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
  1989.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  1990.                            snprintf(tmp_buffer,string_length,"filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
  1991.                            add_to_buffer(tmp_buffer);
  1992.                            break;
  1993.                     default:break;
  1994.                     }
  1995.                 }
  1996.         break;
  1997.         case FLOODFILL:
  1998.         /*
  1999.         @ floodfill x,y,color
  2000.         @ alternative syntax: fill x,y,color
  2001.         @ fill the region of point (x:y) with color 'color'
  2002.         @ any other color or size of picture (borders of picture) will act as border to the bucket fill
  2003.         @ use this command  after all boundary objects are declared.
  2004.         @ Use command 'clickfill,color' for user click driven flood fill.
  2005.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  2006.         @ NOTE: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU..
  2007.         */
  2008.             for(i=0 ;i < 4 ; i++){
  2009.                 switch(i){
  2010.                     case 0:double_data[0] = get_real(infile,0);break;
  2011.                     case 1:double_data[1] = get_real(infile,0);break;
  2012.                     case 2:fill_color = get_color(infile,1);
  2013.                            if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  2014.                                 js_function[DRAW_FLOODFILL] = 1;
  2015.                                 add_js_floodfill(js_include_file,canvas_root_id);
  2016.                            }
  2017.                            decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */
  2018.                            string_length = snprintf(NULL,0,  "floodfill(0,%.*f,%.*f,[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
  2019.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2020.                            snprintf(tmp_buffer,string_length,"floodfill(0,%.*f,%.*f,[%s,%d]);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
  2021.                            add_to_buffer(tmp_buffer);
  2022.                            break;
  2023.                     default:break;
  2024.                     }
  2025.                 }
  2026.         break;
  2027.         case CLICKFILLMARGE:
  2028.             clickfillmarge = (int) (get_real(infile,1));
  2029.             break;
  2030.         /*
  2031.         @ clickfillmarge int
  2032.         @ default 20 (pixels)
  2033.         @ when using command "clickfill fillcolor" a coloured area my be reverted ("undo") <br />back to background colour with a middle mouse click<br />when the click is in a 40x40 rectangle around a stored m mouseclick (userdraw_x[] and userdraw_y[])
  2034.         */
  2035.         case CLICKFILL:
  2036.         /*
  2037.         @ clickfill fillcolor
  2038.         @ user left mouse click will floodfill the area with fillcolor
  2039.         @ multiple areas may be coloured
  2040.         @ the coloured areas can be removed (changed to "bgcolor") by  middle / right mouse click <br />(if the click is in an 40x40 pixel area of the click coordinate that "painted" the area)
  2041.         @ the answer will be read as the (x:y) click coordinates per coloured area
  2042.         @ background color of main div may be set by using command "bgcolor color"
  2043.         @ may not be combined with command "userdraw"
  2044.         @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
  2045.         */
  2046.          fill_color = get_color(infile,1);
  2047.          if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
  2048.             js_function[DRAW_FLOODFILL] = 1;
  2049.             add_js_floodfill(js_include_file,canvas_root_id);
  2050.          }
  2051.          fprintf(js_include_file,"<!-- begin command clickfill -->\nvar marge_xy = %d;var userdraw_x = new Array();var userdraw_y = new Array();var user_clickfill_cnt = 0;\ncanvas_div.addEventListener(\"mousedown\",clickfill,false);function clickfill(evt){var x = evt.clientX - findPosX(canvas_div) + document.body.scrollLeft + document.documentElement.scrollLeft;var y = evt.clientY - findPosY(canvas_div) + document.body.scrollTop + document.documentElement.scrollTop;if(evt.which != 1){for(var p=0; p < user_clickfill_cnt;p++){if(userdraw_x[p] + marge_xy > x && userdraw_x[p] - marge_xy < x){if(userdraw_y[p] + marge_xy > y && userdraw_y[p] - marge_xy < y){if(confirm(\"Clear ?\")){floodfill(1,userdraw_x[p],userdraw_y[p],canvas_div.style.backgroundColor);userdraw_x.splice(p,2);userdraw_y.splice(p,2);user_clickfill_cnt--;return;};};};};};userdraw_x[user_clickfill_cnt] = x;userdraw_y[user_clickfill_cnt] = y;user_clickfill_cnt++;floodfill(1,x,y,[%s,%d]);};\n<!-- end command clickfill -->\n",clickfillmarge,fill_color,(int) (fill_opacity/0.0039215));
  2052.          add_read_canvas(1);
  2053.         break;
  2054.         case SETPIXEL:
  2055.         /*
  2056.         @ setpixel x,y,color
  2057.         @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange
  2058.         @ pixels can not be dragged or clicked
  2059.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  2060.         */
  2061.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  2062.             for(i=0;i<3;i++){
  2063.                 switch(i){
  2064.                     case 0: double_data[0] = get_real(infile,0); break; /* x */
  2065.                     case 1: double_data[1] = get_real(infile,0); break; /* y  */
  2066.                     case 2: stroke_color = get_color(infile,1);
  2067.                            string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  2068.                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2069.                            snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
  2070.                            add_to_buffer(tmp_buffer);
  2071.                            break;
  2072.                     default:break;
  2073.                 }
  2074.             }
  2075.             reset();
  2076.         break;
  2077.         case PIXELSIZE:
  2078.         /*
  2079.         @ pixelsize int
  2080.         @ in case you want to deviate from default pixelsize = 1...
  2081.         */
  2082.             pixelsize = (int) get_real(infile,1);
  2083.         break;
  2084.         case PIXELS:
  2085.         /*
  2086.         @ pixels color,x1,y1,x2,y2,x3,y3...
  2087.         @ Draw  "points" with diameter 1 pixel
  2088.         @ pixels can not be dragged or clicked
  2089.         @ "pixelsize = 1" may be changed by command "pixelsize int"
  2090.         */
  2091.             if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
  2092.             stroke_color=get_color(infile,0);
  2093.             i=0;
  2094.             c=0;
  2095.             while( ! done ){     /* get next item until EOL*/
  2096.                 if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
  2097.                 for( c = 0 ; c < 2; c++){
  2098.                     if(c == 0 ){
  2099.                         double_data[i] = get_real(infile,0);
  2100.                         i++;
  2101.                     }
  2102.                     else
  2103.                     {
  2104.                         double_data[i] = get_real(infile,1);
  2105.                         i++;
  2106.                     }
  2107.                 }
  2108.             }
  2109.             decimals = find_number_of_digits(precision);
  2110.             /*  *double_xy2js_array(double xy[],int len,int decimals) */
  2111.             string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  2112.             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2113.             snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
  2114.             add_to_buffer(tmp_buffer);
  2115.             break;
  2116.         case DEBUG:
  2117.         /*
  2118.         @ debug
  2119.         @ keyword, no arguments
  2120.         @ use as first command (before 'size')
  2121.         @ will show a few buttons to read_canvas(); read_mathml(); and read_dragdrop();
  2122.         @ only to be used in a single canvasdraw instance <br />or in case of multiple canvasdraw images , only the last image
  2123.         */
  2124.         debug = 1;
  2125.         fprintf(stdout,"\n\
  2126. <!-- THIS IS JUST FOR DEBUGGING ANSWER TYPES IN A SINGLE CANVASDRAW INSTANCE -->\n\
  2127. <input type=\"button\" onclick=\"javascript:alert(read_canvas());\" value=\"read_canvas()\" />\n\
  2128. <input type=\"button\" onclick=\"javascript:alert(read_mathml());\" value=\"read_mathml()\" />\n\
  2129. <input type=\"button\" onclick=\"javascript:alert(read_dragdrop());\" value=\"read_dragdrop()\" />\n");
  2130.         done = TRUE;
  2131.  
  2132.         case REPLYFORMAT:
  2133.         /*
  2134.         @ replyformat number
  2135.         @ default values should be fine !
  2136.         @ use command "debug" to check return values of javascript function read_canvas();
  2137.         @ choose<ul><li>1 = x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n<br /><br />x/y in pixels</li><li>2 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  x/y in xrange / yrange coordinate system<br /></li><li>3 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in pixels <br />  r in pixels</li><li>4 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in xrange / yrange coordinate system<br />  r in pixels</li><li>5 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in pixels<br /></li><li>6 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in xrange / yrange coordinate system<br /></li><li>7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in pixels</li><li>8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in xrange / yrange coordinate system</li><li>9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in pixels</li><li>10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in xrange / yrange coordinate system</li><li>11 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />   Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in xrange / yrange coordinate system</li><li>12 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in pixels</li><li>13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2<br />  x/y in xrange / yrange coordinate system</li><li>14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2<br />  x/y in pixels</li><li>15 = reply from inputfields,textareas<br />  reply1,reply2,reply3,...,reply_n</li><li>16 = mathml input fields </li><li>17 = read "userdraw text,color" only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n</li><li>18 = read_canvas() will read all interactive clocks in H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</li><li>19 = read_canvas() will return the object number of marked / clicked object (clock)<br />analogue to (shape library) onclick command </li><li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li>22 = retruns an array .... reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n<br />  x/y in xrange / yrange coordinate system</ul>
  2138.         @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...)
  2139.         */
  2140.          reply_format = (int) get_real(infile,1);
  2141.         break;
  2142.         case LEGENDCOLORS:
  2143.         /*
  2144.         @ legendcolors color1:color2:color3:...:color_n
  2145.         @ will be used to colour a legend
  2146.         @ make sure the number of colours match the number of legend items
  2147.         @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
  2148.         */
  2149.             temp = get_string(infile,1);
  2150.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2151.             fprintf(js_include_file,"var legendcolors%d = [\"%s\"];\n",canvas_root_id,temp);
  2152.             break;
  2153.         case LEGEND:
  2154.         /*
  2155.         @ legend string1:string2:string3....string_n
  2156.         @ will be used to create a legend for a graph
  2157.         @ also see command 'piechart'  
  2158.         */
  2159.             temp = get_string(infile,1);
  2160.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2161.             fprintf(js_include_file,"var legend%d = [\"%s\"];\n",canvas_root_id,temp);
  2162.             break;
  2163.         case XLABEL:
  2164.         /*
  2165.         @ xlabel some_string
  2166.         @ will be used to create a label for the x-axis (label is in quadrant I)
  2167.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  2168.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  2169.         */
  2170.             temp = get_string(infile,1);
  2171.             fprintf(js_include_file,"var xaxislabel = \"%s\"; ",temp);
  2172.             break;
  2173.         case YLABEL:
  2174.         /*
  2175.         @ ylabel some_string
  2176.         @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
  2177.         @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
  2178.         @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
  2179.         */
  2180.             temp = get_string(infile,1);
  2181.             fprintf(js_include_file,"var yaxislabel = \"%s\"; ",temp);
  2182.             break;
  2183.         case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
  2184.         /*
  2185.         @ linegraph x1:y1;x2:y2...x_n:y;2
  2186.         @ will plot your data in a graph
  2187.         @ may only to be used together with command 'grid'
  2188.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  2189.         @ use command 'legend' to provide an optional legend in right-top-corner
  2190.         @ also see command 'piechart'
  2191.         @ multiple linegraphs may be used in a single plot
  2192.         @ <ul><li>use command 'strokecolor' before command 'linegraph' to set the color of this graph</li><li>use command 'linewidth' before command 'linegraph' to set linewidth of this graph</li><li>use command 'dashed' before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command 'dashtype' before command 'linegraph' to set the type of dashing of the graph</li></ul>
  2193.         */    
  2194.             temp = get_string(infile,1);
  2195.             if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
  2196.             fprintf(js_include_file,"var linegraph_%d = [\"%s\",\"%d\",\"%d\",\"%d\",\"%d\",\"%s\"];\n",linegraph_cnt,stroke_color,line_width,use_dashed,dashtype[0],dashtype[1],temp);
  2197.             linegraph_cnt++;
  2198.             reset();
  2199.             break;
  2200.         case CLOCK:
  2201.         /*
  2202.         @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
  2203.         @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
  2204.         @ colors are optional: if not defined, default values will be used<br />default colours: clock 0,0,60,4,35,45,1,2,[space]<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,white,white,black,yellow
  2205.         @ 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></ul>
  2206.         @ canvasdraw will not check validity of colornames...the javascript console is your best friend
  2207.         @ no combinations with other reply_types allowed, for now
  2208.         @ if command 'debug' is set, 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
  2209.         */
  2210.             if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
  2211.  
  2212.         /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
  2213.             for(i=0;i<9;i++){
  2214.              switch(i){
  2215.               case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
  2216.               case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
  2217.               case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
  2218.               case 3: int_data[3] = get_real(infile,0);break;/* hours */
  2219.               case 4: int_data[4] = get_real(infile,0);break;/* minutes */
  2220.               case 5: int_data[5] = get_real(infile,0);break;/* seconds */
  2221.               case 6:
  2222.               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 */
  2223.               case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/
  2224.                         switch(int_data[7]){
  2225.                          default:break;
  2226.                          case 1 :if(clock_cnt == 0){
  2227.                                     if( reply_format == 0 ){
  2228.                                      reply_format = 18; /* user sets clock */
  2229.                                      string_length = snprintf(NULL,0,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
  2230.                                      check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2231.                                      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");
  2232.                                      add_to_buffer(tmp_buffer);
  2233.                                     }
  2234.                                     else
  2235.                                     {
  2236.                                      canvas_error("interactive clock may not be used together with other reply_types...");
  2237.                                     }
  2238.                                   }
  2239.                                   if(debug == 1 ){
  2240.                                     fprintf(stdout,"<br /><input type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H-\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M-\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><input type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S-\" /><br />",clock_cnt,clock_cnt,clock_cnt,clock_cnt,clock_cnt,clock_cnt);
  2241.                                   }
  2242.                                   break;
  2243.                          case 2 :if( reply_format == 0 ){
  2244.                                     reply_format = 19; /* "onclick */
  2245.                                     fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();\n\ncanvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();\nvar x = evt.clientX - canvas_rect.left;\nvar y = evt.clientY - canvas_rect.top;\nvar p = 0;\nvar name;\nvar t = true;\nwhile(t){try{name = eval('clocks'+p);\nif( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;\nname = 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);\n};\n}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);\nname = 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};\np++;\n}catch(e){t=false;\n};\n};\n};\n};\n\n<!-- end onclick handler for clocks -->\n ");
  2246.                                  }
  2247.                                  else
  2248.                                  {
  2249.                                   if( reply_format != 19){
  2250.                                    canvas_error("clickable clock(s) may not be used together with other reply_types...");
  2251.                                   }
  2252.                                  }
  2253.                                  break;
  2254.                         }
  2255.                         break;
  2256.                 case 8:
  2257.                         temp = get_string(infile,1);
  2258.                         if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
  2259.                         if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";}
  2260.                         string_length = snprintf(NULL,0,"clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
  2261.                         check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2262.                         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);
  2263.                         add_to_buffer(tmp_buffer);
  2264.                         clock_cnt++;
  2265.                         break;
  2266.                 default:break;
  2267.              }
  2268.             }
  2269.             break;
  2270.         case BARCHART:
  2271.         /*
  2272.         @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
  2273.         @ will be used to create a legend for bar graph
  2274.         @ may only to be used together with command 'grid'
  2275.         @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
  2276.         @ use command 'legend' to provide an optional legend in right-top-corner
  2277.         @ also see command 'piechart'  
  2278.         */
  2279.             temp = get_string(infile,1);
  2280.             if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
  2281.             fprintf(js_include_file,"var barchart%d = [\"%s\"];\n",canvas_root_id,temp);
  2282.             reset();
  2283.             break;
  2284.         case PIECHART:
  2285.         /*
  2286.         @ piechart xc,yc,radius,'data+colorlist'
  2287.         @ (xc : yc) center of circle diagram in xrange/yrange
  2288.         @ radius in pixels
  2289.         @ 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
  2290.         @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
  2291.         @ the number of colors must match the number of data.
  2292.         @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours
  2293.         @ use command "legend string1:string2:...:string_n" to automatically create a legend <br />using the same colours as pie segments<br />unicode allowed in legend<br />expect javascript trouble if the amount of 'pie-slices', 'pie-colours' 'pie-legend-titles' do not match<br />a javascript console is your best friend...
  2294.         */
  2295.             if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}    
  2296.             for(i=0;i<5;i++){
  2297.                 switch(i){
  2298.                     case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
  2299.                     case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
  2300.                     case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
  2301.                     case 3: temp = get_string(infile,1);
  2302.                             if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
  2303.                             string_length = snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,font_size,font_family);
  2304.                             check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
  2305.                             snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,font_size,font_family);
  2306.                             add_to_buffer(tmp_buffer);
  2307.                            break;
  2308.                     default:break;
  2309.                 }
  2310.             }
  2311.             reset();
  2312.         break;
  2313.         case STATUS:
  2314.             fprintf(js_include_file,"\nstatus=\"waiting\";\n");
  2315.             break;
  2316.         case XLOGSCALE:
  2317.         /*
  2318.             @xlogscale g,xmajor,xminor
  2319.             @create a log grid in xrange
  2320.         */
  2321.             break;
  2322.         case YLOGSCALE:
  2323.             break;
  2324.         case XYLOGSCALE:
  2325.         default:sync_input(infile);
  2326.         break;
  2327.     }
  2328.   }
  2329.   /* we are done parsing script file */
  2330.  
  2331.   /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable shapes / objects  ! */
  2332.   add_javascript_functions(js_function,canvas_root_id);
  2333.    /* add read_canvas() etc functions if needed */
  2334.   if( reply_format > 0 ){ add_read_canvas(reply_format);}
  2335.   /* using mouse coordinate display ? */
  2336.   if( use_mouse_coordinates == TRUE ){
  2337.     tmp_buffer = my_newmem(26);
  2338.     snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
  2339.   }
  2340.   /* add global variables / contants */
  2341.   fprintf(js_include_file,"\n\
  2342.  <!-- some extra global stuff ... need to rethink this -->\n\
  2343.  var precision = %d;var xmin=%.*f;var xmax=%.*f;var ymin=%.*f;\
  2344.  var ymax=%.*f;var xmin_start=xmin;var xmax_start=xmax;\
  2345.  var ymin_start=ymin;var ymax_start=xmax;var zoom_increment = (xmax - xmin)/20;\
  2346.  var pan_x_increment = (xmax - xmin)/20;var pan_y_increment = (ymax - ymin)/20;\
  2347.  <!-- THIS ZOOM & PAN BUTTON STUFF IS JUST  A TEMPORARY SOLUTION -->\n\
  2348.  function start_canvas%d(type){\n\
  2349.   switch(type){\n\
  2350.    case 0:xmin = xmin + zoom_increment;ymin = ymin + zoom_increment;xmax = xmax - zoom_increment;ymax = ymax - zoom_increment;break;\n\
  2351.    case 1:xmin = xmin - zoom_increment;ymin = ymin - zoom_increment;xmax = xmax + zoom_increment;ymax = ymax + zoom_increment;break;\n\
  2352.    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\n\
  2353.    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\n\
  2354.    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\n\
  2355.    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\n\
  2356.    case 6:location.reload();break;\n\
  2357.    default:break;\n\
  2358.   };\n\
  2359.   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\n\
  2360.   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\n\
  2361.   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\n\
  2362.   <!-- buffer -->\n\
  2363.   %s\n\
  2364.  };\n\
  2365.  start_canvas%d(22);\n\
  2366. };\n\
  2367. <!-- end wims_canvas_function -->\n\
  2368. wims_canvas_function%d();\n",precision,decimals,xmin,decimals,xmax,decimals,ymin,decimals,ymax,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
  2369. /* done writing the javascript include file */
  2370. fclose(js_include_file);
  2371.  
  2372. }
  2373.  
  2374. /* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
  2375. if(use_tooltip == TRUE){
  2376.   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
  2377. }
  2378. exit(EXIT_SUCCESS);
  2379. }
  2380. /* end main() */
  2381.  
  2382. /******************************************************************************
  2383. **
  2384. **  sync_input
  2385. **
  2386. **  synchronises input line - reads to end of line, leaving file pointer
  2387. **  at first character of next line.
  2388. **
  2389. **  Used by:
  2390. **  main program - error handling.
  2391. **
  2392. ******************************************************************************/
  2393. void sync_input(FILE *infile)
  2394. {
  2395.         int c = 0;
  2396.  
  2397.         if( c == '\n' ) return;
  2398.         while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r')) ;
  2399.         if( c == EOF ) finished = 1;
  2400.         if( c == '\n' || c == '\r') line_number++;
  2401.         return;
  2402. }
  2403.  
  2404. /******************************************************************************/
  2405.  
  2406. char *str_replace(const char *str, const char *old, const char *new){
  2407. /* http://creativeandcritical.net/str-replace-c/ */
  2408.     if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
  2409.     char *ret, *r;
  2410.     const char *p, *q;
  2411.     size_t oldlen = strlen(old);
  2412.     size_t count = 0;
  2413.     size_t retlen = 0;
  2414.     size_t newlen = strlen(new);
  2415.     if (oldlen != newlen){
  2416.         for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
  2417.             count++;
  2418.             retlen = p - str + strlen(p) + count * (newlen - oldlen);
  2419.         }
  2420.     }
  2421.     else
  2422.     {
  2423.         retlen = strlen(str);
  2424.     }
  2425.    
  2426.     if ((ret = malloc(retlen + 1)) == NULL){
  2427.         ret = NULL;
  2428.         canvas_error("string argument is NULL");
  2429.     }
  2430.     else
  2431.     {
  2432.         for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
  2433.             size_t l = q - p;
  2434.             memcpy(r, p, l);
  2435.             r += l;
  2436.             memcpy(r, new, newlen);
  2437.             r += newlen;
  2438.         }
  2439.         strcpy(r, p);
  2440.     }
  2441.     return ret;
  2442. }
  2443.  
  2444. /******************************************************************************/
  2445. /*
  2446. avoid the use of ctypes.h for tolower() toupper();
  2447. it gives trouble in FreeBSD 9.0 / 9.1 when used in a chroot environment (C library bug) : Undefined symbol "_ThreadRuneLocale"
  2448. Upper case -> Lower case : c = c - 'A'+ 'a';
  2449. Lower case ->  Upper case  c = c + 'A'  - 'a';
  2450. */
  2451. int tolower(int c){
  2452.  if(c <= 'Z'){
  2453.   if (c >= 'A'){
  2454.    return c - 'A' + 'a';
  2455.   }
  2456.  }
  2457.  return c;
  2458. }
  2459.  
  2460. int toupper(int c){
  2461.  if(c >= 'a' && c <= 'z'){
  2462.    return c + 'A' - 'a';
  2463.  }
  2464.  return c;
  2465. }
  2466.  
  2467. char *get_color(FILE *infile , int last){
  2468.     int c,i = 0,is_hex = 0;
  2469.     char temp[MAX_COLOR_STRING], *string;
  2470.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) ){
  2471.         if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
  2472.         if( c == '#' ){
  2473.             is_hex = 1;
  2474.         }
  2475.         if( c != ' '){
  2476.             temp[i]=tolower(c);
  2477.             i++;
  2478.         }
  2479.     }
  2480.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  2481.     if( c == '\n' ){ done = TRUE; line_number++; }
  2482.     if( c == EOF ){finished = 1;}
  2483.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  2484.     temp[i]='\0';
  2485.     if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
  2486.     if( is_hex == 1 ){
  2487.         char red[3], green[3], blue[3];
  2488.         red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
  2489.         green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
  2490.         blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
  2491.         int r = (int) strtol(red,   NULL, 16);
  2492.         int g = (int) strtol(green, NULL, 16);
  2493.         int b = (int) strtol(blue,  NULL, 16);
  2494.         string = (char *)my_newmem(12);
  2495.         snprintf(string,11,"%d,%d,%d",r,g,b);
  2496.         return string;
  2497.     }
  2498.     else
  2499.     {
  2500.         string = (char *)my_newmem(sizeof(temp));
  2501.         snprintf(string,sizeof(temp),"%s",temp);
  2502.         for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){
  2503.             if( strcmp( colors[i].name , string ) == 0 ){
  2504.                 return colors[i].rgb;
  2505.             }
  2506.         }
  2507.     }
  2508.     /* not found...return error */
  2509.     free(string);string = NULL;
  2510.     canvas_error("I was expecting a color name or hexnumber...but found nothing.");
  2511.     return NULL;
  2512. }
  2513.  
  2514. char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
  2515.     int c,i=0;
  2516.     char  temp[MAX_BUFFER], *string;
  2517.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
  2518.         temp[i]=c;
  2519.         i++;
  2520.         if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
  2521.     }
  2522.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  2523.     if( c == '\n' ) { done = TRUE; line_number++; }
  2524.     if( c == EOF ) {
  2525.         finished = 1;
  2526.         if( last != 1 ){ canvas_error("expected more arguments");}
  2527.     }
  2528.     temp[i]='\0';
  2529.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
  2530.     string=(char *)my_newmem(strlen(temp));
  2531.     snprintf(string,sizeof(temp),"%s",temp);
  2532.     return string;
  2533. }
  2534.  
  2535. char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
  2536.     int c,i=0;
  2537.     char temp[MAX_BUFFER], *string;
  2538.     while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',') ){
  2539.         temp[i]=c;
  2540.         i++;
  2541.         if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
  2542.     }
  2543.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  2544.     if( c == '\n' ) { line_number++; }
  2545.     if( c == EOF ) {finished = 1;}
  2546.     if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
  2547.     temp[i]='\0';
  2548.     if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
  2549.     string=(char *)my_newmem(sizeof(temp));
  2550.     snprintf(string,sizeof(temp),"%s",temp);
  2551.     done = TRUE;
  2552.     return string;
  2553. }
  2554.  
  2555. double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
  2556.     int c,i=0,found_calc = 0;
  2557.     double y;
  2558.     char tmp[MAX_INT];
  2559.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') ){
  2560.      if( c != ' ' ){
  2561.      /*
  2562.      libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used
  2563.      We will check after assert() if it's a NULL pointer...and exit program via :
  2564.      canvas_error("I'm having trouble parsing your \"expression\" ");
  2565.      */
  2566.       if( i == 0 &&  c == '+' ){
  2567.        continue;
  2568.       }
  2569.       else
  2570.       {
  2571.        if(canvas_iscalculation(c) != 0){
  2572.         found_calc = 1;
  2573.         c = tolower(c);
  2574.        }
  2575.        tmp[i] = c;
  2576.        i++;
  2577.       }
  2578.      }
  2579.      if( i > MAX_INT - 1){canvas_error("number too large");}
  2580.     }
  2581.     if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
  2582.     if( c == '\n' ){ done = TRUE; line_number++; }
  2583.     if( c == EOF ){done = TRUE ; finished = 1;}
  2584.     tmp[i]='\0';
  2585.     if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
  2586.     if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
  2587.      void *f = evaluator_create(tmp);
  2588.      assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
  2589.      y = evaluator_evaluate_x(f, 1);
  2590.      /* if function is bogus; y = 1 : so no core dumps */
  2591.      evaluator_destroy(f);
  2592.     }
  2593.     else
  2594.     {
  2595.      y = atof(tmp);
  2596.     }
  2597.     return y;
  2598. }
  2599.  
  2600. double get_double(FILE *infile , int orientation , int last){  /* last = 0 : more arguments ; last=1 final argument */
  2601. /* orientation=0 : x-values ...  orientation=1 :y-values */
  2602.     int c;
  2603.     int i = 0;
  2604.     int found_calc = 0; /* signal user input like : 2*pi/3 */
  2605.     char tmp[MAX_INT];
  2606.     double dx;
  2607.     while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n')){
  2608.         if( c != ' '){/* no spaces in numbers */
  2609.             if(canvas_iscalculation(c) != 0 ){
  2610.         found_calc = 1;
  2611.         c = tolower(c);
  2612.             }
  2613.             tmp[i]=c;
  2614.             i++;
  2615.             if( i > MAX_INT-1){canvas_error("number too large");}
  2616.         }
  2617.     }
  2618.     if( c == '\n' || c == EOF ){
  2619.         if( last == 0 ){canvas_error("expecting more arguments");}
  2620.         if( c == EOF ){finished = TRUE;}
  2621.         done = TRUE;
  2622.         /*return 0; */
  2623.     }
  2624.     tmp[i]='\0';
  2625.    
  2626.     if( strlen(tmp) == 0 || i == 0){
  2627.         if( orientation == 0 ){
  2628.             canvas_error("expected a x-value \n e.g. a number in x-range / y-range coordinate system\nbut found nothing !!");
  2629.         }
  2630.         else
  2631.         {
  2632.             canvas_error("expected a y-value \n e.g. a number in x-range / y-range coordinate system\nbut found nothing !!");
  2633.         }
  2634.     }
  2635.     if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
  2636.         void *f = evaluator_create(tmp);
  2637.         assert(f);
  2638.         if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ");}
  2639.         dx = evaluator_evaluate_x(f, 1);
  2640.         evaluator_destroy(f);
  2641.     }
  2642.     else
  2643.     {
  2644.         dx = atof(tmp); /* no pi/e/sin(2*pi/3) found : will use atof to convert inputstring  to float */
  2645.     }
  2646.     if( c == '\n') { line_number++; }
  2647.     if( c != EOF ) {
  2648.         if( c == '\n' ) {
  2649.             done = TRUE;
  2650.         }
  2651.     }
  2652.     else
  2653.     {
  2654.         finished = TRUE;
  2655.     }
  2656.     if( (done == TRUE || finished == TRUE) && last != 1 ){ canvas_error("expected more arguments");}
  2657.     if(orientation == 0){
  2658.         return x2px( dx ); /* convert to pixels according xrange */
  2659.     }
  2660.     else
  2661.     {
  2662.         return y2px( dx );/* convert to pixels according yrange */
  2663.     }
  2664. }
  2665. void canvas_error(char *msg){
  2666.     fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg);
  2667.     finished = 1;
  2668.     exit(EXIT_SUCCESS);
  2669. }
  2670.  
  2671.  
  2672. /* convert x/y coordinates to pixel */
  2673. int x2px(double x){
  2674.  return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
  2675. }
  2676.  
  2677. int y2px(double y){
  2678.  return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
  2679. }
  2680.  
  2681. double px2x(int x){
  2682.  return (x*(xmax - xmin)/xsize + xmin);
  2683. }
  2684. double px2y(int y){
  2685.  return (y*(ymax - ymin)/ysize + ymin);
  2686. }
  2687.  
  2688. void add_to_buffer(char *tmp){
  2689.  if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
  2690.  /*  do we have enough space left in buffer[MAX_BUFFER] ? */
  2691.  int space_left = (int) (sizeof(buffer) - strlen(buffer));
  2692.  if( space_left > strlen(tmp)){
  2693.   strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
  2694.  }
  2695.  else
  2696.  {
  2697.   canvas_error("buffer is too big\n");
  2698.  }
  2699.  tmp = NULL;free(tmp);
  2700.  return;
  2701. }
  2702.  
  2703. void reset(){
  2704.  if(use_filled == TRUE){use_filled = FALSE;}
  2705.  if(use_dashed == TRUE){use_dashed = FALSE;}
  2706.  if(use_translate == TRUE){use_translate = FALSE;}
  2707.  if(use_rotate == TRUE){use_rotate = FALSE;}
  2708.  onclick = 0;
  2709. }
  2710.  
  2711.  
  2712.  
  2713. /* What reply format in read_canvas();
  2714.  
  2715. note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  2716. 1 = x1,x2,x3,x4....x_n
  2717.     y1,y2,y3,y4....y_n
  2718.  
  2719.     x/y in pixels
  2720.  
  2721. 2 = x1,x2,x3,x4....x_n
  2722.     y1,y2,y3,y4....y_n
  2723.     x/y in  xrange / yrange coordinate system
  2724.  
  2725. 3 = x1,x2,x3,x4....x_n
  2726.     y1,y2,y3,y4....y_n
  2727.     r1,r2,r3,r4....r_n
  2728.  
  2729.     x/y in pixels
  2730.     r in pixels
  2731.  
  2732. 4 = x1,x2,x3,x4....x_n
  2733.     y1,y2,y3,y4....y_n
  2734.     r1,r2,r3,r4....r_n
  2735.  
  2736.     x/y in  xrange / yrange coordinate system
  2737.     r in pixels
  2738.  
  2739. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  2740.     Ay1,Ay2,Ay3,Ay4....Ay_n
  2741.     Bx1,Bx2,Bx3,Bx4....Bx_n
  2742.     By1,By2,By3,By4....By_n
  2743.     Cx1,Cx2,Cx3,Cx4....Cx_n
  2744.     Cy1,Cy2,Cy3,Cy4....Cy_n
  2745.     ....
  2746.     Zx1,Zx2,Zx3,Zx4....Zx_n
  2747.     Zy1,Zy2,Zy3,Zy4....Zy_n
  2748.    
  2749.     x/y in pixels
  2750.  
  2751. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  2752.     Ay1,Ay2,Ay3,Ay4....Ay_n
  2753.     Bx1,Bx2,Bx3,Bx4....Bx_n
  2754.     By1,By2,By3,By4....By_n
  2755.     Cx1,Cx2,Cx3,Cx4....Cx_n
  2756.     Cy1,Cy2,Cy3,Cy4....Cy_n
  2757.     ....
  2758.     Zx1,Zx2,Zx3,Zx4....Zx_n
  2759.     Zy1,Zy2,Zy3,Zy4....Zy_n
  2760.  
  2761.     x/y in  xrange / yrange coordinate system
  2762.    
  2763. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  2764.    
  2765.     x/y in pixels
  2766.  
  2767. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  2768.    
  2769.     x/y in  xrange / yrange coordinate system
  2770.  
  2771. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  2772.  
  2773.     x/y in pixels
  2774.  
  2775. 10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
  2776.  
  2777.     x/y in  xrange / yrange coordinate system
  2778.  
  2779. 11 = Ax1,Ay1,Ax2,Ay2
  2780.      Bx1,By1,Bx2,By2
  2781.      Cx1,Cy1,Cx2,Cy2
  2782.      Dx1,Dy1,Dx2,Dy2
  2783.      ......
  2784.      Zx1,Zy1,Zx2,Zy2
  2785.      
  2786.     x/y in  xrange / yrange coordinate system
  2787.  
  2788. 12 = Ax1,Ay1,Ax2,Ay2
  2789.      Bx1,By1,Bx2,By2
  2790.      Cx1,Cy1,Cx2,Cy2
  2791.      Dx1,Dy1,Dx2,Dy2
  2792.      ......
  2793.      Zx1,Zy1,Zx2,Zy2
  2794.      
  2795.     x/y in pixels
  2796.  
  2797. 13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
  2798.  
  2799.     x/y in  xrange / yrange coordinate system
  2800. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  2801.     x/y in pixels
  2802. 15 = reply from inputfields,textareas
  2803.     reply1,reply2,reply3,...,reply_n
  2804.  
  2805. 16 = read mathml inputfields only
  2806.  
  2807. 17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
  2808.  when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
  2809.  
  2810. 18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  2811. 19 = return clicked object number (analogue to shape-library onclick)
  2812. 20 = return x/y-data in x-range/y-range of all 'draggable' images
  2813. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  2814. 22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  2815.     x/y in  xrange / yrange coordinate system
  2816.  
  2817. */
  2818.  
  2819.  
  2820. void add_read_canvas(int type_reply){
  2821. /* just 1 reply type allowed */
  2822. switch(type_reply){
  2823. /*  TO DO
  2824. !!!!  NEED TO SIMPLIFY !!!!  
  2825. answers may have:
  2826. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  2827. */
  2828.     case 1: fprintf(js_include_file,"\
  2829. <!-- begin function 1 read_canvas() -->\n\
  2830. function read_canvas(){\
  2831. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  2832. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  2833.  var p = 0;var input_reply = new Array();\
  2834.  if( document.getElementById(\"canvas_input0\")){\
  2835.   var t = 0;\
  2836.   while(document.getElementById(\"canvas_input\"+t)){\
  2837.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  2838.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  2839.     p++;\
  2840.    };\
  2841.    t++;\
  2842.   };\
  2843.  };\
  2844.  if( typeof userdraw_text != 'undefined' ){\
  2845.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
  2846.  }\
  2847.  else\
  2848.  {\
  2849.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
  2850.  }\
  2851. }\
  2852. else\
  2853. {\
  2854.  if( typeof userdraw_text != 'undefined' ){\
  2855.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
  2856.  }\
  2857.  else\
  2858.  {\
  2859.   return userdraw_x+\"\\n\"+userdraw_y;\
  2860.  }\
  2861. };\
  2862. };\
  2863. this.read_canvas = read_canvas;\n\
  2864. <!-- end function 1 read_canvas() -->\n");
  2865.     break;
  2866.     case 2: fprintf(js_include_file,"\
  2867. <!-- begin function 2 read_canvas() -->\n\
  2868. function read_canvas(){\
  2869. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  2870. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  2871. while(userdraw_x[p]){\
  2872.  reply_x[p] = px2x(userdraw_x[p]);\
  2873.  reply_y[p] = px2y(userdraw_y[p]);\
  2874.  p++;\
  2875. };\
  2876. if(p == 0){alert(\"nothing drawn...\");return;};\
  2877. if( document.getElementById(\"canvas_input0\")){\
  2878.  var p = 0;var input_reply = new Array();\
  2879.  if( document.getElementById(\"canvas_input0\")){\
  2880.   var t = 0;\
  2881.   while(document.getElementById(\"canvas_input\"+t)){\
  2882.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  2883.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  2884.     p++;\
  2885.    };\
  2886.    t++;\
  2887.   };\
  2888.  };\
  2889.  if( typeof userdraw_text != 'undefined' ){\
  2890.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  2891.  }\
  2892.  else\
  2893.  {\
  2894.   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
  2895.  }\
  2896. }\
  2897. else\
  2898. {\
  2899.  if( typeof userdraw_text != 'undefined' ){\
  2900.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
  2901.  }\
  2902.  else\
  2903.  {\
  2904.   return reply_x+\"\\n\"+reply_y;\
  2905.  };\
  2906. };\
  2907. };\
  2908. this.read_canvas = read_canvas;\n\
  2909. <!-- end function 2 read_canvas() -->\n");
  2910.     break;
  2911.     case 3: fprintf(js_include_file,"\
  2912. <!-- begin function 3 read_canvas() -->\n\
  2913. function read_canvas(){\
  2914. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  2915. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  2916.  var p = 0;var input_reply = new Array();\
  2917.  if( document.getElementById(\"canvas_input0\")){\
  2918.   var t = 0;\
  2919.   while(document.getElementById(\"canvas_input\"+t)){\
  2920.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  2921.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  2922.     p++;\
  2923.    };\
  2924.    t++;\
  2925.   };\
  2926.  };\
  2927.  if( typeof userdraw_text != 'undefined' ){\
  2928.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  2929.  }\
  2930.  else\
  2931.  {\
  2932.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  2933.  }\
  2934. }\
  2935. else\
  2936. {\
  2937.  if( typeof userdraw_text != 'undefined' ){\
  2938.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
  2939.  }\
  2940.  else\
  2941.  {\
  2942.   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  2943.  }\
  2944. }\
  2945. };\
  2946. this.read_canvas = read_canvas;\n\
  2947. <!-- end function 3 read_canvas() -->\n");
  2948.     break;
  2949.     case 4: fprintf(js_include_file,"\
  2950. <!-- begin function 4 read_canvas() -->\n\
  2951. function read_canvas(){\
  2952. var reply_x = new Array();var reply_y = new Array();var p = 0;\
  2953. while(userdraw_x[p]){\
  2954.  reply_x[p] = px2x(userdraw_x[p]);\
  2955.  reply_y[p] = px2y(userdraw_y[p]);\
  2956.  p++;\
  2957. };\
  2958. if(p == 0){alert(\"nothing drawn...\");return;};\
  2959. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  2960.  var p = 0;var input_reply = new Array();\
  2961.  if( document.getElementById(\"canvas_input0\")){\
  2962.   var t = 0;\
  2963.   while(document.getElementById(\"canvas_input\"+t)){\
  2964.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  2965.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  2966.     p++;\
  2967.    };\
  2968.    t++;\
  2969.   };\
  2970.  };\
  2971.  if( typeof userdraw_text != 'undefined' ){\
  2972.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  2973.  }\
  2974.  else\
  2975.  {\
  2976.   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
  2977.  }\
  2978. }\
  2979. else\
  2980. {\
  2981.  if( typeof userdraw_text != 'undefined' ){\
  2982.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
  2983.  }\
  2984.  else\
  2985.  {\
  2986.   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  2987.  }\
  2988. };\
  2989. };\
  2990. this.read_canvas = read_canvas;\n\
  2991. <!-- end function 4 read_canvas() -->\n");
  2992.     break;
  2993.     /*
  2994.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  2995.         used for userdraw multiple paths
  2996.     */
  2997.     case 5: fprintf(js_include_file,"\
  2998. <!-- begin function 5 read_canvas() -->\n\
  2999. function read_canvas(){\
  3000. var p = 0;\
  3001. var reply = \"\";\
  3002. for(p = 0; p < userdraw_x.length;p++){\
  3003.  if(userdraw_x[p] != null ){\
  3004.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  3005.  };\
  3006. };\
  3007. if(p == 0){alert(\"nothing drawn...\");return;};\
  3008. userdraw_x = [];userdraw_y = [];\
  3009. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3010.  var p = 0;var input_reply = new Array();\
  3011.  if( document.getElementById(\"canvas_input0\")){\
  3012.   var t = 0;\
  3013.   while(document.getElementById(\"canvas_input\"+t)){\
  3014.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3015.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3016.     p++;\
  3017.    };\
  3018.    t++;\
  3019.   };\
  3020.  };\
  3021.  if( typeof userdraw_text != 'undefined' ){\
  3022.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3023.  }\
  3024.  else\
  3025.  {\
  3026.   return reply +\"\\n\"+input_reply;\
  3027.  }\
  3028. }\
  3029. else\
  3030. {\
  3031.  if( typeof userdraw_text != 'undefined' ){\
  3032.   return reply+\"\\n\"+userdraw_text;\
  3033.  }\
  3034.  else\
  3035.  {\
  3036.   return reply;\
  3037.  }\
  3038. };\
  3039. };\
  3040. this.read_canvas = read_canvas;\n\
  3041. <!-- end function 5 read_canvas() -->\n");
  3042.     break;
  3043.     /*
  3044.         attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
  3045.         used for userdraw multiple paths
  3046.     */
  3047.     case 6: fprintf(js_include_file,"\
  3048. <!-- begin function 6 read_canvas() -->\n\
  3049. function read_canvas(){\
  3050. var p = 0;\
  3051. var reply = \"\";\
  3052. var tmp_x = new Array();\
  3053. var tmp_y = new Array();\
  3054. for(p = 0 ; p < userdraw_x.length; p++){\
  3055.  tmp_x = userdraw_x[p];\
  3056.  tmp_y = userdraw_y[p];\
  3057.  if(tmp_x != null){\
  3058.   for(var i = 0 ; i < tmp_x.length ; i++){\
  3059.    tmp_x[i] = px2x(tmp_x[i]);\
  3060.    tmp_y[i] = px2y(tmp_y[i]);\
  3061.   };\
  3062.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  3063.  };\
  3064. };\
  3065. if(p == 0){alert(\"nothing drawn...\");return;};\
  3066. userdraw_x = [];userdraw_y = [];\
  3067. if( document.getElementById(\"canvas_input0\") ){\
  3068.  var p = 0;var input_reply = new Array();\
  3069.  if( document.getElementById(\"canvas_input0\")){\
  3070.   var t = 0;\
  3071.   while(document.getElementById(\"canvas_input\"+t)){\
  3072.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3073.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3074.     p++;\
  3075.    };\
  3076.    t++;\
  3077.   };\
  3078.  };\
  3079.  if( typeof userdraw_text != 'undefined' ){\
  3080.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3081.  }\
  3082.  else\
  3083.  {\
  3084.   return reply +\"\\n\"+input_reply;\
  3085.  }\
  3086. }\
  3087. else\
  3088. {\
  3089.  if( typeof userdraw_text != 'undefined' ){\
  3090.   return reply +\"\\n\"+userdraw_text;\
  3091.  }\
  3092.  else\
  3093.  {\
  3094.   return reply;\
  3095.  }\
  3096. };\
  3097. };\
  3098. this.read_canvas = read_canvas;\n\
  3099. <!-- end function 6 read_canvas() -->\n");
  3100.     break;
  3101.     case 7: fprintf(js_include_file,"\
  3102. <!-- begin function 7 read_canvas() -->\n\
  3103. function read_canvas(){\
  3104. var reply = new Array();\
  3105. var p = 0;\
  3106. while(userdraw_x[p]){\
  3107.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  3108.  p++;\
  3109. };\
  3110. if(p == 0){alert(\"nothing drawn...\");return;};\
  3111. if( document.getElementById(\"canvas_input0\") ){\
  3112.  var p = 0;var input_reply = new Array();\
  3113.  if( document.getElementById(\"canvas_input0\")){\
  3114.   var t = 0;\
  3115.   while(document.getElementById(\"canvas_input\"+t)){\
  3116.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3117.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3118.     p++;\
  3119.    };\
  3120.    t++;\
  3121.   };\
  3122.  };\
  3123.  if( typeof userdraw_text != 'undefined' ){\
  3124.   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3125.  }\
  3126.  else\
  3127.  {\
  3128.   return reply+\"\\n\"+input_reply;\
  3129.  }\
  3130. };\
  3131. else\
  3132. {\
  3133.  if( typeof userdraw_text != 'undefined' ){\
  3134.   return reply+\"\\n\"+userdraw_text;\
  3135.  }\
  3136.  else\
  3137.  {\
  3138.   return reply;\
  3139.  }\
  3140. };\
  3141. };\
  3142. this.read_canvas = read_canvas;\n\
  3143. <!-- end function 7 read_canvas() -->\n");
  3144.     break;
  3145.     case 8: fprintf(js_include_file,"\
  3146. <!-- begin function 8 read_canvas() -->\n\
  3147. function read_canvas(){\
  3148. var reply = new Array();\
  3149. var p = 0;\
  3150. while(userdraw_x[p]){\
  3151.  reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]);\
  3152.  p++;\
  3153. };\
  3154. if(p == 0){alert(\"nothing drawn...\");return;};\
  3155. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3156.  var p = 0;var input_reply = new Array();\
  3157.  if( document.getElementById(\"canvas_input0\")){\
  3158.   var t = 0;\
  3159.   while(document.getElementById(\"canvas_input\"+t)){\
  3160.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3161.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3162.     p++;\
  3163.    };\
  3164.    t++;\
  3165.   };\
  3166.  };\
  3167.  if( typeof userdraw_text != 'undefined' ){\
  3168.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3169.  }\
  3170.  else\
  3171.  {\
  3172.   return reply +\"\\n\"+input_reply;\
  3173.  }\
  3174. }\
  3175. else\
  3176. {\
  3177.  if( typeof userdraw_text != 'undefined' ){\
  3178.   return reply +\"\\n\"+userdraw_text;\
  3179.  }\
  3180.  else\
  3181.  {\
  3182.   return reply;\
  3183.  }\
  3184. };\
  3185. };\
  3186. this.read_canvas = read_canvas;\n\
  3187. <!-- end function 8 read_canvas() -->\n");
  3188.     break;
  3189.     case 9: fprintf(js_include_file,"\
  3190. <!-- begin function 9 read_canvas() -->\n\
  3191. function read_canvas(){\
  3192. var reply = new Array();\
  3193. var p = 0;\
  3194. while(userdraw_x[p]){\
  3195.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  3196.  p++;\
  3197. };\
  3198. if(p == 0){alert(\"nothing drawn...\");return;};\
  3199. if( document.getElementById(\"canvas_input0\") ){\
  3200.  var p = 0;var input_reply = new Array();\
  3201.  if( document.getElementById(\"canvas_input0\")){\
  3202.   var t = 0;\
  3203.   while(document.getElementById(\"canvas_input\"+t)){\
  3204.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3205.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3206.     p++;\
  3207.    };\
  3208.    t++;\
  3209.   };\
  3210.  };\
  3211.  if( typeof userdraw_text != 'undefined' ){\
  3212.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3213.  }\
  3214.  else\
  3215.  {\
  3216.   return reply +\"\\n\"+input_reply;\
  3217.  }\
  3218. }\
  3219. else\
  3220. {\
  3221.  if( typeof userdraw_text != 'undefined' ){\
  3222.   return reply +\"\\n\"+userdraw_text;\
  3223.  }\
  3224.  else\
  3225.  {\
  3226.   return reply;\
  3227.  }\
  3228. };\
  3229. };\
  3230. this.read_canvas = read_canvas;\n\
  3231. <!-- end function 9 read_canvas() -->\n");
  3232.     break;
  3233.     case 10: fprintf(js_include_file,"\
  3234. <!-- begin function 10 read_canvas() -->\n\
  3235. function read_canvas(){\
  3236. var reply = new Array();\
  3237. var p = 0;\
  3238. while(userdraw_x[p]){\
  3239.  reply[p] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + userdraw_radius[p];\
  3240.  p++;\
  3241. };\
  3242. if(p == 0){alert(\"nothing drawn...\");return;};\
  3243. if( document.getElementById(\"canvas_input0\") ){\
  3244.  var p = 0;var input_reply = new Array();\
  3245.  if( document.getElementById(\"canvas_input0\")){\
  3246.   var t = 0;\
  3247.   while(document.getElementById(\"canvas_input\"+t)){\
  3248.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3249.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3250.     p++;\
  3251.    };\
  3252.    t++;\
  3253.   };\
  3254.  };\
  3255.  if( typeof userdraw_text != 'undefined' ){\
  3256.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3257.  }\
  3258.  else\
  3259.  {\
  3260.   return reply +\"\\n\"+input_reply;\
  3261.  }\
  3262. }\
  3263. else\
  3264. {\
  3265.  if( typeof userdraw_text != 'undefined' ){\
  3266.   return reply +\"\\n\"+userdraw_text;\
  3267.  }\
  3268.  else\
  3269.  {\
  3270.   return reply;\
  3271.  }\
  3272. };\
  3273. };\
  3274. this.read_canvas = read_canvas;\n\
  3275. <!-- end function 10 read_canvas() -->\n");
  3276.     break;
  3277.     case 11: fprintf(js_include_file,"\
  3278. <!-- begin function 11 read_canvas() -->\n\
  3279. function read_canvas(){\
  3280. var reply = \"\";\
  3281. var p = 0;\
  3282. while(userdraw_x[p]){\
  3283.  reply = reply + px2x(userdraw_x[p]) +\",\" + px2y(userdraw_y[p]) +\",\" + px2x(userdraw_x[p+1]) +\",\" + px2y(userdraw_y[p+1]) +\"\\n\" ;\
  3284.  p = p+2;\
  3285. };\
  3286. if(p == 0){alert(\"nothing drawn...\");return;};\
  3287. if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
  3288.  var p = 0;var input_reply = new Array();\
  3289.  if( document.getElementById(\"canvas_input0\")){\
  3290.   var t = 0;\
  3291.   while(document.getElementById(\"canvas_input\"+t)){\
  3292.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3293.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3294.     p++;\
  3295.    };\
  3296.    t++;\
  3297.   };\
  3298.  };\
  3299.  if( typeof userdraw_text != 'undefined' ){\
  3300.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3301.  }\
  3302.  else\
  3303.  {\
  3304.   return reply +\"\\n\"+input_reply;\
  3305.  }\
  3306. }\
  3307. else\
  3308. {\
  3309.  if( typeof userdraw_text != 'undefined' ){\
  3310.   return reply +\"\\n\"+userdraw_text;\
  3311.  }\
  3312.  else\
  3313.  {\
  3314.   return reply;\
  3315.  }\
  3316. };\
  3317. };\
  3318. this.read_canvas = read_canvas;\n\
  3319. <!-- end function 11 read_canvas() -->\n");
  3320.     break;
  3321.     case 12: fprintf(js_include_file,"\
  3322. <!-- begin function 12 read_canvas() -->\n\
  3323. function read_canvas(){\
  3324. var reply = \"\";\
  3325. var p = 0;\
  3326. for(p = 0; p< userdraw_x.lenght;p = p+2){\
  3327.  if(userdraw_x[p] != null){\
  3328.    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  3329.  };\
  3330. };\
  3331. if(p == 0){alert(\"nothing drawn...\");return;};\
  3332. if( document.getElementById(\"canvas_input0\") ){\
  3333.  var p = 0;var input_reply = new Array();\
  3334.  if( document.getElementById(\"canvas_input0\")){\
  3335.   var t = 0;\
  3336.   while(document.getElementById(\"canvas_input\"+t)){\
  3337.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3338.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3339.     p++;\
  3340.    };\
  3341.    t++;\
  3342.   };\
  3343.  };\
  3344.  if( typeof userdraw_text != 'undefined' ){\
  3345.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3346.  }\
  3347.  else\
  3348.  {\
  3349.   return reply +\"\\n\"+input_reply;\
  3350.  }\
  3351. }\
  3352. else\
  3353. {\
  3354.  if( typeof userdraw_text != 'undefined' ){\
  3355.   return reply +\"\\n\"+userdraw_text\
  3356.  }\
  3357.  else\
  3358.  {\
  3359.   return reply;\
  3360.  }\
  3361. };\
  3362. };\
  3363. this.read_canvas = read_canvas;\n\
  3364. <!-- end function 12 read_canvas() -->\n");
  3365.     break;
  3366.     case 13: fprintf(js_include_file,"\
  3367. <!-- begin function 13 read_canvas() -->\n\
  3368. function read_canvas(){\
  3369. var reply = new Array();\
  3370. var p = 0;var i = 0;\
  3371. while(userdraw_x[p]){\
  3372.  reply[i] = px2x(userdraw_x[p]) +\":\" + px2y(userdraw_y[p]) +\":\" + px2x(userdraw_x[p+1]) +\":\" + px2y(userdraw_y[p+1]);\
  3373.  p = p+2;i++;\
  3374. };\
  3375. if(p == 0){alert(\"nothing drawn...\");return;};\
  3376. if( document.getElementById(\"canvas_input0\") ){\
  3377.  var p = 0;var input_reply = new Array();\
  3378.  if( document.getElementById(\"canvas_input0\")){\
  3379.   var t = 0;\
  3380.   while(document.getElementById(\"canvas_input\"+t)){\
  3381.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3382.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3383.     p++;\
  3384.    };\
  3385.    t++;\
  3386.   };\
  3387.  };\
  3388.  if( typeof userdraw_text != 'undefined' ){\
  3389.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3390.  }\
  3391.  else\
  3392.  {\
  3393.   return reply +\"\\n\"+input_reply;\
  3394.  }\
  3395. }\
  3396. else\
  3397. {\
  3398.  if( typeof userdraw_text != 'undefined' ){\
  3399.   return reply +\"\\n\"+userdraw_text\
  3400.  }\
  3401.  else\
  3402.  {\
  3403.   return reply;\
  3404.  }\
  3405. };\
  3406. };\
  3407. this.read_canvas = read_canvas;\n\
  3408. <!-- end function 13 read_canvas() -->\n");
  3409.     break;
  3410.     case 14: fprintf(js_include_file,"\
  3411. <!-- begin function 14 read_canvas() -->\n\
  3412. function read_canvas(){\
  3413. var reply = new Array();\
  3414. var p = 0;var i = 0;\
  3415. while(userdraw_x[p]){\
  3416.  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  3417.  p = p+2;i++;\
  3418. };\
  3419. if(p == 0){alert(\"nothing drawn...\");return;};\
  3420. if( document.getElementById(\"canvas_input0\") ){\
  3421.  var p = 0;var input_reply = new Array();\
  3422.  if( document.getElementById(\"canvas_input0\")){\
  3423.   var t = 0;\
  3424.   while(document.getElementById(\"canvas_input\"+t)){\
  3425.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3426.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3427.     p++;\
  3428.    };\
  3429.    t++;\
  3430.   };\
  3431.  };\
  3432.  if( typeof userdraw_text != 'undefined' ){\
  3433.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3434.  }\
  3435.  else\
  3436.  {\
  3437.   return reply +\"\\n\"+input_reply;\
  3438.  }\
  3439. }\
  3440. else\
  3441. {\
  3442.  if( typeof userdraw_text != 'undefined' ){\
  3443.   return reply +\"\\n\"+userdraw_text;\
  3444.  }\
  3445.  else\
  3446.  {\
  3447.   return reply;\
  3448.  }\
  3449. };\
  3450. };\
  3451. this.read_canvas = read_canvas;\n\
  3452. <!-- end function 14 read_canvas() -->\n");
  3453.     break;
  3454.     case 15: fprintf(js_include_file,"\
  3455. <!-- begin function 15  read_canvas() -->\n\
  3456. function read_canvas(){\
  3457. var input_reply = new Array();\
  3458. var p = 0;\
  3459. if( document.getElementById(\"canvas_input0\")){\
  3460.  var t = 0;\
  3461.  while(document.getElementById(\"canvas_input\"+t)){\
  3462.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3463.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3464.    p++;\
  3465.   };\
  3466.   t++;\
  3467.  };\
  3468. };\
  3469. if( typeof userdraw_text != 'undefined' ){\
  3470.   return input_reply +\"\\n\"+userdraw_text;\
  3471. }\
  3472. else\
  3473. {\
  3474.  return input_reply;\
  3475. };\
  3476. };\
  3477. this.read_canvas = read_canvas;\n\
  3478. <!-- end function 15 read_canvas() -->\n");
  3479.     break;
  3480.     case 16: fprintf(js_include_file,"\
  3481. <!-- begin function 16 read_mathml() -->\n\
  3482. function read_mathml(){\
  3483. var reply = new Array();\
  3484. var p = 0;\
  3485. if( document.getElementById(\"mathml0\")){\
  3486.  while(document.getElementById(\"mathml\"+p)){\
  3487.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  3488.   p++;\
  3489.  };\
  3490. };\
  3491. return reply;\
  3492. };\
  3493. this.read_mathml = read_mathml;\n\
  3494. <!-- end function 16 read_mathml() -->\n");
  3495.     break;
  3496.     case 17:  fprintf(js_include_file,"\
  3497. <!-- begin function 17 read_canvas() -->\n\
  3498. function read_canvas(){\
  3499. if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
  3500. return userdraw_text;\
  3501. };\
  3502. this.read_canvas = read_canvas;\n\
  3503. <!-- end function 17 read_canvas() -->\n");
  3504.     break;
  3505.     case 18: fprintf(js_include_file,"\
  3506. <!-- begin function 18 read_canvas() -->\n\
  3507. function read_canvas(){\
  3508. var p = 0;\
  3509. var reply = new Array();\
  3510. var name;\
  3511. var t = true;\
  3512. while(t){\
  3513.  try{ name = eval('clocks'+p);\
  3514.  reply[p] = parseInt((name.H+name.M/60+name.S/3600)%%12)+\":\"+parseInt((name.M + name.S/60)%%60)+\":\"+(name.S)%%60;p++}catch(e){t=false;};\
  3515. };\
  3516. if( p == 0){alert(\"clock(s) not modified...\");return;}\
  3517. return reply;\
  3518. };\
  3519. this.read_canvas = read_canvas;\n\
  3520. <!-- end function 18 read_canvas() -->\n");
  3521.     break;
  3522.     case 19: fprintf(js_include_file,"\
  3523. <!-- begin function 19 read_canvas() -->\n\
  3524. function read_canvas(){\
  3525. return reply[0];\
  3526. };\
  3527. this.read_canvas = read_canvas;\n\
  3528. <!-- end function 19 read_canvas() -->\n");
  3529.     case 20: fprintf(js_include_file,"\
  3530. <!-- begin function 20 read_canvas() -->\n\
  3531. function read_canvas(){\
  3532. var len  = ext_drag_images.length;\
  3533. var reply = new Array(len);\
  3534. for(var p = 0 ; p < len ; p++){\
  3535.    var img = ext_drag_images[p];\
  3536.    reply[p] = px2x(img[6])+\":\"+px2y(img[7]);\
  3537. };\
  3538. return reply;\
  3539. };\
  3540. this.read_canvas = read_canvas;\n\
  3541. <!-- end function 20 read_canvas() -->\n");
  3542.     break;
  3543.     case 21: fprintf(js_include_file,"\
  3544. <!-- begin function 21 read_canvas() -->\n\
  3545. function read_canvas(){\
  3546. if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
  3547. var reply_coord = new Array();var p = 0;\
  3548. while(userdraw_x[p]){\
  3549.  reply_coord[p] = \"(\"+px2x(userdraw_x[p])+\":\"+px2y(userdraw_y[p])+\")\";\
  3550.  p++;\
  3551. };\
  3552. if(p == 0){alert(\"nothing drawn...\");return;};\
  3553. if( document.getElementById(\"canvas_input0\") ){\
  3554.  var p = 0;var input_reply = new Array();\
  3555.  if( document.getElementById(\"canvas_input0\")){\
  3556.   var t = 0;\
  3557.   while(document.getElementById(\"canvas_input\"+t)){\
  3558.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3559.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3560.     p++;\
  3561.    };\
  3562.    t++;\
  3563.   };\
  3564.  };\
  3565.  if( typeof userdraw_text != 'undefined' ){\
  3566.   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3567.  }\
  3568.  else\
  3569.  {\
  3570.   return reply_coord+\"\\n\"+input_reply;\
  3571.  }\
  3572. }\
  3573. else\
  3574. {\
  3575.  if( typeof userdraw_text != 'undefined' ){\
  3576.   return reply_coord+\"\\n\"+userdraw_text;\
  3577.  }\
  3578.  else\
  3579.  {\
  3580.   return reply_coord;\
  3581.  };\
  3582. };\
  3583. };\
  3584. this.read_canvas = read_canvas;\n\
  3585. <!-- end function 21 read_canvas() -->\n");
  3586.     break;
  3587.     case 22: fprintf(js_include_file,"\
  3588. <!-- begin function 22 read_canvas() -->\n\
  3589. function read_canvas(){\
  3590. var reply = new Array();\
  3591. var p = 0;\
  3592. var idx = 0;\
  3593. while(userdraw_x[p]){\
  3594.  reply[idx] = px2x(userdraw_x[p]);\
  3595.  idx++;\
  3596.  reply[idx] = px2y(userdraw_y[p]);\
  3597.  idx++;p++;\
  3598. };\
  3599. if(p == 0){alert(\"nothing drawn...\");return;};\
  3600. if( document.getElementById(\"canvas_input0\") ){\
  3601.  var p = 0;var input_reply = new Array();\
  3602.  if( document.getElementById(\"canvas_input0\")){\
  3603.   var t = 0;\
  3604.   while(document.getElementById(\"canvas_input\"+t)){\
  3605.    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  3606.     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  3607.     p++;\
  3608.    };\
  3609.    t++;\
  3610.   };\
  3611.  };\
  3612.  if( typeof userdraw_text != 'undefined' ){\
  3613.   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
  3614.  }\
  3615.  else\
  3616.  {\
  3617.   return reply +\"\\n\"+input_reply;\
  3618.  }\
  3619. }\
  3620. else\
  3621. {\
  3622.  if( typeof userdraw_text != 'undefined' ){\
  3623.   return reply +\"\\n\"+userdraw_text;\
  3624.  }\
  3625.  else\
  3626.  {\
  3627.   return reply;\
  3628.  }\
  3629. };\
  3630. };\
  3631. this.read_canvas = read_canvas;\n\
  3632. <!-- end function 22 read_canvas() -->\n");
  3633.     break;
  3634.  
  3635.     default: canvas_error("hmmm unknown replyformat...");break;
  3636. }
  3637.  return;
  3638. }
  3639.  
  3640.  
  3641. /*
  3642.  add drawfunction :
  3643.  - functions used by userdraw_primitives (circle,rect,path,triangle...)
  3644.  - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
  3645.  - grid / mathml
  3646.  - will not scale or zoom in
  3647.  - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
  3648.  - is printed directly into 'js_include_file'
  3649. */
  3650.  
  3651. void add_javascript_functions(int js_functions[],int canvas_root_id){
  3652. int i;
  3653. for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
  3654.  if( js_functions[i] == 1){
  3655.     switch(i){
  3656.     case DRAG_EXTERNAL_IMAGE:
  3657. fprintf(js_include_file,"\n<!-- drag external images --->\n\
  3658. var external_canvas = create_canvas%d(7,xsize,ysize);\n\
  3659. var external_ctx = external_canvas.getContext(\"2d\");\n\
  3660. var external_canvas_rect = external_canvas.getBoundingClientRect();\n\
  3661. canvas_div.addEventListener(\"mousedown\",setxy,false);\n\
  3662. canvas_div.addEventListener(\"mouseup\",dragstop,false);\n\
  3663. canvas_div.addEventListener(\"mousemove\",dragxy,false);\n\
  3664. var selected_image = null;\n\
  3665. var ext_image_cnt = 0;\n\
  3666. var ext_drag_images = new Array();\n\
  3667. function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\n\
  3668. ext_image_cnt = idx;\n\
  3669. var image = new Image();\n\
  3670. image.src = URL;\n\
  3671. image.onload = function(){\n\
  3672.  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\n\
  3673.  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\n\
  3674.  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\n\
  3675.  img = new Array(10);\n\
  3676.  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\n\
  3677.  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\n\
  3678.  ext_drag_images[idx] = img;\n\
  3679.  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\n\
  3680. };\n\
  3681. };\n\
  3682. function dragstop(evt){\n\
  3683. selected_image = null;return;\n\
  3684. };\n\
  3685. function dragxy(evt){\n\
  3686. if( selected_image != null ){\n\
  3687.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\n\
  3688.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop :document.body.scrollTop);\n\
  3689.  var s_img = ext_drag_images[selected_image];\n\
  3690.  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\n\
  3691.  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\n\
  3692.  ext_drag_images[selected_image] = s_img;\n\
  3693.  external_ctx.clearRect(0,0,xsize,ysize);\n\
  3694.  for(var i = 0; i <= ext_image_cnt ; i++){\n\
  3695.   var img = ext_drag_images[i];\n\
  3696.   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\n\
  3697.  };\n\
  3698. };\n\
  3699. };\n\
  3700. function setxy(evt){\n\
  3701. if( ! selected_image && evt.which == 1 ){\n\
  3702.  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\n\
  3703.  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop :document.body.scrollTop);\n\
  3704.  var xm = evt.clientX - external_canvas_rect.left + xoff;\n\
  3705.  var ym = evt.clientY - external_canvas_rect.top + yoff;\n\
  3706.  for(var p = 0 ; p <= ext_image_cnt ; p++){\n\
  3707.   var img = ext_drag_images[p];\n\
  3708.   if( img[0] == 1 ){\n\
  3709.    var w = img.width;\n\
  3710.    var h = img.height;\n\
  3711.    if( xm > img[6] && xm < img[6] + img[4]){\n\
  3712.     if( ym > img[7] && ym < img[7] + img[5]){\n\
  3713.      img[6] = xm;\n\
  3714.      img[7] = ym;\n\
  3715.      ext_drag_images[p] = img;\n\
  3716.      selected_image = p;\n\
  3717.      dragxy(evt);\n\
  3718.     };\n\
  3719.    };\n\
  3720.   };\n\
  3721.  };\n\
  3722. }\n\
  3723. else\n\
  3724. {\n\
  3725.  selected_image = null;\n\
  3726. }\n\
  3727. };",canvas_root_id);
  3728.     break;
  3729.  
  3730.     case DRAW_EXTERNAL_IMAGE:
  3731. fprintf(js_include_file,"\n<!-- draw external images -->\n\
  3732. draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
  3733. var image = new Image();\
  3734. image.src = URL;\
  3735. var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
  3736. image.onload = function(){\
  3737.  if( x0 < 1 ){ x0 = 0; };\
  3738.  if( y0 < 1 ){ y0 = 0; };\
  3739.  if( sx < 1 ){ sx = 0; };\
  3740.  if( sy < 1 ){ sy = 0; };\
  3741.  if( width < 1 ){ width = image.width;};\
  3742.  if( height < 1 ){ height = image.height;};\
  3743.  if( swidth < 1 ){ swidth = image.width;};\
  3744.  if( sheight < 1 ){ sheight = image.height;};\
  3745.  var ml = x0 - sx;\
  3746.  var mh = y0 - sy;\
  3747.  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
  3748.  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
  3749.  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
  3750.  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
  3751.  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
  3752. };\
  3753. };\n",canvas_root_id);    
  3754.     break;
  3755.    
  3756.     case DRAW_ZOOM_BUTTONS: /* 6 rectangles 15x15 px  forbidden zone for drawing : y < ysize - 15*/
  3757. fprintf(js_include_file,"\n<!-- draw zoom buttons -->\n\
  3758. draw_zoom_buttons = function(canvas_type,color,opacity){\
  3759. var obj;\
  3760. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  3761.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  3762. }\
  3763. else\
  3764. {\
  3765.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  3766. };\
  3767. var ctx = obj.getContext(\"2d\");\
  3768. ctx.font =\"18px Ariel\";\
  3769. ctx.textAlign = \"right\";\
  3770. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  3771. ctx.fillText(\"+\",xsize,ysize);\
  3772. ctx.fillText(\"\\u2212\",xsize - 15,ysize);\
  3773. ctx.fillText(\"\\u2192\",xsize - 30,ysize-2);\
  3774. ctx.fillText(\"\\u2190\",xsize - 45,ysize-2);\
  3775. ctx.fillText(\"\\u2191\",xsize - 60,ysize-2);\
  3776. ctx.fillText(\"\\u2193\",xsize - 75,ysize-2);\
  3777. ctx.fillText(\"\\u00D7\",xsize - 90,ysize-2);\
  3778. ctx.stroke();\
  3779. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  3780.    
  3781.     break;
  3782.     case DRAW_GRIDFILL:/* not used for userdraw */
  3783. fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
  3784. draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
  3785. var obj;\
  3786. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  3787.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  3788. }\
  3789. else\
  3790. {\
  3791.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  3792. };\
  3793. var ctx = obj.getContext(\"2d\");\
  3794. var x,y;\
  3795. ctx.save();\
  3796. ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  3797. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  3798.    ctx.moveTo(x,y0);\
  3799.    ctx.lineTo(x,ysize);\
  3800. };\
  3801. for( y = y0 ; y < ysize +dx; y = y + dy ){\
  3802.    ctx.moveTo(x0,y);\
  3803.    ctx.lineTo(xsize,y);\
  3804. };\
  3805. ctx.stroke();\
  3806. ctx.restore();\
  3807. return;};\n",canvas_root_id,canvas_root_id,canvas_root_id);
  3808.     break;
  3809.    
  3810.     case DRAW_IMAGEFILL:/* not  used for userdraw */
  3811. fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
  3812. draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
  3813. var obj;\
  3814. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  3815.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  3816. }\
  3817. else\
  3818. {\
  3819.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  3820. };\
  3821. var ctx = obj.getContext(\"2d\");\
  3822. ctx.save();\
  3823. var img = new Image();\
  3824. img.src = URL;\
  3825. img.onload = function(){\
  3826.  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
  3827.    ctx.drawImage(img,x0,y0,xsize,ysize);\
  3828.  }\
  3829.  else\
  3830.  {\
  3831.    var repeat = \"repeat\";\
  3832.    if(img.width > xsize - x0){\
  3833.         repeat = \"repeat-y\";\
  3834.    }\
  3835.    else\
  3836.    {\
  3837.     if( img.height > ysize -x0 ){\
  3838.      repeat = \"repeat-x\";\
  3839.     }\
  3840.    }\
  3841.    var pattern = ctx.createPattern(img,repeat);\
  3842.    ctx.rect(x0,y0,xsize,ysize);\
  3843.    ctx.fillStyle = pattern;\
  3844.  }\
  3845.  ctx.fill();\
  3846. };\
  3847. ctx.restore();\
  3848. return;\
  3849. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  3850.     break;
  3851.    
  3852.     case DRAW_DOTFILL:/* not  used for userdraw */
  3853. fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
  3854. draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
  3855. var obj;\
  3856. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  3857.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  3858. }\
  3859. else\
  3860. {\
  3861.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  3862. };\
  3863. var ctx = obj.getContext(\"2d\");\
  3864. var x,y;\
  3865. ctx.closePath();\
  3866. ctx.save();\
  3867. ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
  3868. for( x = x0 ; x < xsize+dx ; x = x + dx ){\
  3869.  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
  3870.   ctx.arc(x,y,radius,0,2*Math.PI,false);\
  3871.   ctx.closePath();\
  3872.  }\
  3873. }\
  3874. ctx.fill();\
  3875. ctx.restore();\
  3876. return;};\n",canvas_root_id,canvas_root_id,canvas_root_id);
  3877.     break;
  3878.    
  3879.     case DRAW_HATCHFILL:/* not used for userdraw */
  3880. fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
  3881. draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
  3882.  var obj;\
  3883. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  3884.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  3885. }\
  3886. else\
  3887. {\
  3888.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  3889. };\
  3890. var ctx = obj.getContext(\"2d\");\
  3891. var x;\
  3892. var y;\
  3893. ctx.save();\
  3894. ctx.lineWidth = linewidth;\
  3895. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  3896. y = ysize;\
  3897. for( x = x0 ; x < xsize ; x = x + dx ){\
  3898.  ctx.moveTo(x,y0);\
  3899.  ctx.lineTo(xsize,y);\
  3900.  y = y - dy;\
  3901. };\
  3902. y = y0;\
  3903. for( x = xsize ; x > 0 ; x = x - dx){\
  3904.  ctx.moveTo(x,ysize);\
  3905.  ctx.lineTo(x0,y);\
  3906.  y = y + dy;\
  3907. };\
  3908. x = x0;\
  3909. for( y = y0 ; y < ysize ; y = y + dy ){\
  3910.  ctx.moveTo(xsize,y);\
  3911.  ctx.lineTo(x,ysize);\
  3912.  x = x + dx;\
  3913. };\
  3914. x = xsize;\
  3915. for( y = ysize ; y > y0 ; y = y - dy ){\
  3916.  ctx.moveTo(x,y0);\
  3917.  ctx.lineTo(x0,y);\
  3918.  x = x - dx;\
  3919. };\
  3920. ctx.stroke();\
  3921. ctx.restore();\
  3922. return;\
  3923. }\n",canvas_root_id,canvas_root_id,canvas_root_id);
  3924.     break;
  3925.    
  3926.     case DRAW_CIRCLES:/*  used for userdraw */
  3927. fprintf(js_include_file,"\n<!-- draw circles -->\n\
  3928. draw_circles = function(ctx,x_points,y_points,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  3929. ctx.save();\
  3930. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  3931. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  3932. ctx.lineWidth = line_width;\
  3933. for(var p = 0 ; p < x_points.length ; p++ ){\
  3934.  ctx.beginPath();\
  3935.  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
  3936.  ctx.closePath();\
  3937.  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  3938.  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  3939.  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  3940.  ctx.stroke();\
  3941. }\
  3942. ctx.restore();\
  3943. return;\
  3944. };\n");
  3945.     break;
  3946.    
  3947.     case DRAW_SEGMENTS:/*  used for userdraw */
  3948. fprintf(js_include_file,"\n<!-- draw segments -->\n\
  3949. draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  3950. ctx.save();\
  3951. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  3952. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  3953. ctx.lineWidth = line_width;\
  3954. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  3955. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  3956. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  3957.  ctx.beginPath();\
  3958.  ctx.moveTo(x_points[p],y_points[p]);\
  3959.  ctx.lineTo(x_points[p+1],y_points[p+1]);\
  3960.  ctx.closePath();\
  3961.  ctx.stroke();\
  3962.  }\
  3963.  ctx.restore();\
  3964.  return;\
  3965. };");
  3966.     break;
  3967.    
  3968.     case DRAW_LINES:/*  used for userdraw */
  3969. fprintf(js_include_file,"\n<!-- draw lines -->\n\
  3970. function calc_line(x1,x2,y1,y2){\
  3971. var marge = 2;\
  3972. if(x1 < x2+marge && x1>x2-marge){\
  3973.  return [x1,0,x1,ysize];\
  3974. };\
  3975. if(y1 < y2+marge && y1>y2-marge){\
  3976.  return [0,y1,xsize,y1];\
  3977. };\
  3978. var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
  3979. var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
  3980. return [0,Y1,xsize,Y2];\
  3981. };\
  3982. draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  3983. ctx.save();\
  3984. var line = new Array(4);\
  3985. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  3986. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  3987. ctx.lineWidth = line_width;\
  3988. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  3989. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  3990. for(var p = 0 ; p < x_points.length ; p = p+2 ){\
  3991.  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
  3992.  ctx.beginPath();\
  3993.  ctx.moveTo(line[0],line[1]);\
  3994.  ctx.lineTo(line[2],line[3]);\
  3995.  ctx.closePath();\
  3996.  ctx.stroke();\
  3997.  }\
  3998.  ctx.restore();\
  3999.  return;\
  4000. };");
  4001.     break;
  4002.  
  4003.     case DRAW_CROSSHAIRS:/*  used for userdraw */
  4004. fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
  4005. draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_translate,vector){\
  4006. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4007. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4008. ctx.lineWidth = line_width;\
  4009. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4010. var x1,x2,y1,y2;\
  4011. for(var p = 0 ; p < x_points.length ; p++ ){\
  4012.  x1 = x_points[p] - crosshair_size;\
  4013.  x2 = x_points[p] + crosshair_size;\
  4014.  y1 = y_points[p] - crosshair_size;\
  4015.  y2 = y_points[p] + crosshair_size;\
  4016.  ctx.beginPath();\
  4017.  ctx.moveTo(x1,y1);\
  4018.  ctx.lineTo(x2,y2);\
  4019.  ctx.closePath();\
  4020.  ctx.stroke();\
  4021.  ctx.beginPath();\
  4022.  ctx.moveTo(x2,y1);\
  4023.  ctx.lineTo(x1,y2);\
  4024.  ctx.closePath();\
  4025.  ctx.stroke();\
  4026. }\
  4027. ctx.restore();\
  4028.  return;\
  4029. };\n");
  4030.     break;
  4031.  
  4032.     case DRAW_RECTS:/*  used for userdraw */
  4033. fprintf(js_include_file,"\n<!-- draw rects -->\n\
  4034. draw_rects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_translate,vector){\
  4035. ctx.save();\
  4036. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4037. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4038. ctx.lineWidth = line_width;\
  4039. ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
  4040. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
  4041. for(var p = 0 ; p < x_points.length ; p = p + 2){\
  4042.  ctx.beginPath();\
  4043.  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
  4044.  ctx.closePath();\
  4045.  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4046.  ctx.stroke();\
  4047. };\
  4048. ctx.restore();\
  4049. return;\
  4050. };\n");
  4051.     break;
  4052.  
  4053.     case DRAW_ROUNDRECTS:/*  used for userdraw */
  4054. fprintf(js_include_file,"\n<!-- draw round rects -->\n\
  4055. draw_roundrects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  4056. ctx.save();\
  4057. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4058. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4059. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4060. var x,y,w,h,r;\
  4061. for(var p = 0; p < x_points.length; p = p+2){\
  4062.  x = x_points[p];y = y_points[p];w = x_points[p+1] - x;h = y_points[p+1] - y;r = parseInt(0.1*w);\
  4063.  ctx.beginPath();ctx.moveTo(x + r, y);\
  4064.  ctx.lineTo(x + w - r, y);\
  4065.  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
  4066.  ctx.lineTo(x + w, y + h - r);\
  4067.  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
  4068.  ctx.lineTo(x + r, y + h);\
  4069.  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
  4070.  ctx.lineTo(x, y + r);\
  4071.  ctx.quadraticCurveTo(x, y, x + r, y);\
  4072.  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
  4073.  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4074.  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
  4075.  ctx.stroke();\
  4076. }\
  4077. ctx.restore();\
  4078. };\n");
  4079.     break;
  4080.  
  4081.     case DRAW_ELLIPSES:/* not  used for userdraw */
  4082. fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
  4083. draw_ellipses = function(canvas_type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  4084. var obj;\
  4085. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4086.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4087. }\
  4088. else\
  4089. {\
  4090.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4091. };\
  4092. var ctx = obj.getContext(\"2d\");\
  4093. ctx.save();\
  4094. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4095. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4096. var cx,cy,ry,rx;\
  4097. ctx.lineWidth = line_width;\
  4098. if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
  4099. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4100. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4101. for(var p=0;p< x_points.length;p = p+2){\
  4102.  ctx.beginPath();\
  4103.  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
  4104.  ctx.translate(cx - rx, cy - ry);\
  4105.  ctx.scale(rx, ry);\
  4106.  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
  4107.  if( use_filled == 1 ){ctx.fill();}\
  4108.  ctx.stroke();\
  4109. };\
  4110. ctx.restore();\
  4111. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  4112.     break;
  4113.  
  4114.     case DRAW_PATHS: /*  used for userdraw */
  4115. fprintf(js_include_file,"\n<!-- draw paths -->\n\
  4116. draw_paths = function(ctx,x_points,y_points,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  4117. ctx.save();\
  4118. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4119. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4120. ctx.lineWidth = line_width;\
  4121. ctx.lineJoin = \"round\";\
  4122. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4123. ctx.beginPath();\
  4124. ctx.moveTo(x_points[0],y_points[0]);\
  4125. for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
  4126. if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
  4127. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4128. if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
  4129. ctx.stroke();\
  4130. ctx.restore();\
  4131. return;\
  4132. };");
  4133.    
  4134.     break;
  4135.     case DRAW_ARROWS:/*  used for userdraw */
  4136. fprintf(js_include_file,"\n<!-- draw arrows -->\n\
  4137. draw_arrows = function(ctx,x_points,y_points,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,use_translate,vector){\
  4138. ctx.save();\
  4139. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4140. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4141. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4142. ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4143. ctx.lineWidth = line_width;\
  4144. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4145. ctx.lineCap = \"round\";\
  4146. ctx.save();\
  4147. var x1,y1,x2,y2,dx,dy,len;\
  4148. for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
  4149.   ctx.restore();ctx.save();\
  4150.   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
  4151.   len = Math.sqrt(dx*dx+dy*dy);\
  4152.   ctx.translate(x2,y2);\
  4153.   ctx.rotate(Math.atan2(dy,dx));\
  4154.   ctx.lineCap = \"round\";\
  4155.   ctx.beginPath();\
  4156.   ctx.moveTo(0,0);\
  4157.   ctx.lineTo(-len,0);\
  4158.   ctx.closePath();\
  4159.   ctx.stroke();\
  4160.   ctx.beginPath();\
  4161.   ctx.moveTo(0,0);\
  4162.   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  4163.   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  4164.   ctx.closePath();\
  4165.   ctx.fill();\
  4166.   if( type == 2 ){\
  4167.     ctx.restore();\
  4168.     ctx.save();\
  4169.     ctx.translate(x1,y1);\
  4170.     ctx.rotate(Math.atan2(-dy,-dx));\
  4171.     ctx.beginPath();\
  4172.     ctx.moveTo(0,0);\
  4173.     ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
  4174.     ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
  4175.     ctx.closePath();\
  4176.     ctx.stroke();\
  4177.     ctx.fill();\
  4178.   }\
  4179.  }\
  4180.  ctx.restore();\
  4181.  return;\
  4182. };\n");
  4183.     break;
  4184.  
  4185.     case DRAW_VIDEO:/* not  used for userdraw */
  4186. fprintf(js_include_file,"\n<!-- draw video -->\n\
  4187. draw_video = function(canvas_root_id,x,y,w,h,URL){\
  4188. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4189. var video_div = document.createElement(\"div\");\
  4190. canvas_div.appendChild(video_div);\
  4191. video_div.style.position = \"absolute\";\
  4192. video_div.style.left = x+\"px\";\
  4193. video_div.style.top = y+\"px\";\
  4194. video_div.style.width = w+\"px\";\
  4195. video_div.style.height = h+\"px\";\
  4196. var video = document.createElement(\"video\");\
  4197. video_div.appendChild(video);\
  4198. video.style.width = w+\"px\";\
  4199. video.style.height = h+\"px\";\
  4200. video.autobuffer = true;\
  4201. video.controls = true;video.autoplay = false;\
  4202. var src = document.createElement(\"source\");\
  4203. src.type = \"video/mp4\";\
  4204. src.src = URL;\
  4205. video.appendChild(src);\
  4206. video.load();\
  4207. return;\
  4208. };\n");    
  4209.     break;
  4210.    
  4211.     case DRAW_AUDIO:/* not used for userdraw */
  4212. fprintf(js_include_file,"\n<!-- draw audio -->\n\
  4213. draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
  4214. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4215. var audio_div = document.createElement(\"div\");\
  4216. canvas_div.appendChild(audio_div);\
  4217. audio_div.style.position = \"absolute\";\
  4218. audio_div.style.left = x+\"px\";\
  4219. audio_div.style.top = y+\"px\";\
  4220. audio_div.style.width = w+\"px\";\
  4221. audio_div.style.height = h+\"px\";\
  4222. var audio = document.createElement(\"audio\");\
  4223. audio_div.appendChild(audio);\
  4224. audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
  4225. audio.autobuffer = true;\
  4226. if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
  4227. if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
  4228. var src1 = document.createElement(\"source\");\
  4229. src1.type = \"audio/ogg\";\
  4230. src1.src = URL1;\
  4231. audio.appendChild(src1);\
  4232. var src2 = document.createElement(\"source\");\
  4233. src2.type = \"audio/mpeg\";\
  4234. src2.src = URL2;\
  4235. audio.appendChild(src2);\
  4236. audio.load();\
  4237. return;\
  4238. };\n");
  4239.     break;
  4240.    
  4241.     case DRAW_HTTP:/* not  used for userdraw */
  4242. fprintf(js_include_file,"\n<!-- draw http -->\n\
  4243. draw_http = function(canvas_root_id,x,y,w,h,URL){\
  4244. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4245. var http_div = document.createElement(\"div\");\
  4246. var iframe = document.createElement(\"iframe\");\
  4247. canvas_div.appendChild(http_div);\
  4248. http_div.appendChild(iframe);\
  4249. iframe.src = URL;\
  4250. iframe.setAttribute(\"width\",w);\
  4251. iframe.setAttribute(\"height\",h);\
  4252. return;\
  4253. };\n");
  4254.     break;
  4255.    
  4256.     case DRAW_XML:
  4257. fprintf(js_include_file,"\n<!-- draw xml -->\n\
  4258. draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
  4259. var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
  4260. var xml_div = document.createElement(\"div\");\
  4261. canvas_div.appendChild(xml_div);\
  4262. xml_div.innerHTML = mathml;\
  4263. if(onclick != 0){\
  4264.  xml_div.onclick = function(){\
  4265.   reply[0] = onclick;\
  4266.   alert(\"send \"+onclick+\" ?\");\
  4267.  };\
  4268. };\
  4269. xml_div.style.position = \"absolute\";\
  4270. xml_div.style.left = x+\"px\";\
  4271. xml_div.style.top = y+\"px\";\
  4272. xml_div.style.width = w+\"px\";\
  4273. xml_div.style.height = h+\"px\";\
  4274. return;\
  4275. };\n"
  4276. );
  4277.     break;
  4278.  
  4279.     case DRAW_GRID:/* not used for userdraw */
  4280. fprintf(js_include_file,"\n<!-- draw grid -->\n\
  4281. draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_translate,vector,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\
  4282. var obj;\
  4283. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4284. obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4285. }\
  4286. else\
  4287. {\
  4288. obj = create_canvas%d(canvas_type,xsize,ysize);\
  4289. };\
  4290. var ctx = obj.getContext(\"2d\");\
  4291. ctx.clearRect(0,0,xsize,ysize);\
  4292. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4293. ctx.save();\
  4294. if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\
  4295. if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
  4296. var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4297. ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
  4298. var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
  4299. ctx.font = font_family;\
  4300. var xstep = xsize*xmajor/(xmax - xmin);\
  4301. var ystep = ysize*ymajor/(ymax - ymin);\
  4302. var x2step = xstep / xminor;\
  4303. var y2step = ystep / yminor;\
  4304. var zero_y = y2px(0);\
  4305. var zero_x = x2px(0);\
  4306. ctx.beginPath();\
  4307. ctx.lineWidth = line_width;\
  4308. ctx.strokeStyle = stroke_color;\
  4309. for(var p = zero_x ; p < xsize; p = p + xstep){\
  4310. ctx.moveTo(p,0);\
  4311. ctx.lineTo(p,ysize);\
  4312. };\
  4313. for(var p = zero_x ; p > 0; p = p - xstep){\
  4314. ctx.moveTo(p,0);\
  4315. ctx.lineTo(p,ysize);\
  4316. };\
  4317. for(var p = zero_y ; p < ysize; p = p + ystep){\
  4318. ctx.moveTo(0,p);\
  4319. ctx.lineTo(xsize,p);\
  4320. };\
  4321. for(var p = zero_y ; p > 0; p = p - ystep){\
  4322. ctx.moveTo(0,p);\
  4323. ctx.lineTo(xsize,p);\
  4324. };\
  4325. if( typeof xaxislabel !== 'undefined' ){\
  4326. ctx.save();\
  4327. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  4328. var corr =  ctx.measureText(xaxislabel).width;\
  4329. ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
  4330. ctx.restore();\
  4331. };\
  4332. if( typeof yaxislabel !== 'undefined' ){\
  4333. ctx.save();\
  4334. ctx.font = \"italic \"+font_size+\"px Ariel\";\
  4335. corr =  ctx.measureText(yaxislabel).width;\
  4336. ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
  4337. ctx.rotate(-0.5*Math.PI);\
  4338. ctx.fillText(yaxislabel,0,0);\
  4339. ctx.restore();\
  4340. };\
  4341. ctx.stroke();\
  4342. ctx.closePath();\
  4343. if( use_axis == 1 ){\
  4344. ctx.beginPath();\
  4345. ctx.strokeStyle = stroke_color;\
  4346. ctx.lineWidth = 0.6*line_width;\
  4347. for(var p = zero_x ; p < xsize; p = p + x2step){\
  4348.  ctx.moveTo(p,0);\
  4349.  ctx.lineTo(p,ysize);\
  4350. };\
  4351. for(var p = zero_x ; p > 0; p = p - x2step){\
  4352.  ctx.moveTo(p,0);\
  4353.  ctx.lineTo(p,ysize);\
  4354. };\
  4355. for(var p = zero_y ; p < ysize; p = p + y2step){\
  4356.  ctx.moveTo(0,p);\
  4357.  ctx.lineTo(xsize,p);\
  4358. };\
  4359. for(var p = zero_y ; p > 0; p = p - y2step){\
  4360.  ctx.moveTo(0,p);\
  4361.  ctx.lineTo(xsize,p);\
  4362. };\
  4363. ctx.stroke();\
  4364. ctx.closePath();\
  4365. ctx.beginPath();\
  4366. ctx.lineWidth = 2*line_width;\
  4367. ctx.strokeStyle = axis_color;\
  4368. ctx.moveTo(0,zero_y);\
  4369. ctx.lineTo(xsize,zero_y);\
  4370. ctx.moveTo(zero_x,0);\
  4371. ctx.lineTo(zero_x,ysize);\
  4372. ctx.stroke();\
  4373. ctx.closePath();\
  4374. ctx.lineWidth = line_width+0.5;\
  4375. ctx.beginPath();\
  4376. for(var p = zero_x ; p < xsize; p = p + xstep){\
  4377.  ctx.moveTo(p,zero_y-tics_length);\
  4378.  ctx.lineTo(p,zero_y+tics_length);\
  4379. };\
  4380. for(var p = zero_x ; p > 0; p = p - xstep){\
  4381.  ctx.moveTo(p,zero_y-tics_length);\
  4382.  ctx.lineTo(p,zero_y+tics_length);\
  4383. };\
  4384. for(var p = zero_y ; p < ysize; p = p + ystep){\
  4385.  ctx.moveTo(zero_x-tics_length,p);\
  4386.  ctx.lineTo(zero_x+tics_length,p);\
  4387. };\
  4388. for(var p = zero_y ; p > 0; p = p - ystep){\
  4389.  ctx.moveTo(zero_x-tics_length,p);\
  4390.  ctx.lineTo(zero_x+tics_length,p);\
  4391. };\
  4392. for(var p = zero_x ; p < xsize; p = p + x2step){\
  4393.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  4394.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  4395. };\
  4396. for(var p = zero_x ; p > 0; p = p - x2step){\
  4397.  ctx.moveTo(p,zero_y-0.5*tics_length);\
  4398.  ctx.lineTo(p,zero_y+0.5*tics_length);\
  4399. };\
  4400. for(var p = zero_y ; p < ysize; p = p + y2step){\
  4401.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  4402.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  4403. };\
  4404. for(var p = zero_y ; p > 0; p = p - y2step){\
  4405.  ctx.moveTo(zero_x-0.5*tics_length,p);\
  4406.  ctx.lineTo(zero_x+0.5*tics_length,p);\
  4407. };\
  4408. ctx.stroke();\
  4409. ctx.closePath();\
  4410. if( use_axis_numbering == 1 ){\
  4411.  var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
  4412.  if( x_strings != null ){\
  4413.   var f = 1.4;\
  4414.   var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
  4415.   for(var p = 0 ; p < len ; p = p+2){\
  4416.     var x_nums = x2px(eval(x_strings[p]));\
  4417.     var x_text = x_strings[p+1];\
  4418.     corr = ctx.measureText(x_text).width;\
  4419.     skip = 1.2*corr/xstep;\
  4420.     if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
  4421.     if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
  4422.     ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
  4423.   }\
  4424.  }\
  4425.  else\
  4426.  {\
  4427.   corr=0;skip = 0;cnt = xmajor;\
  4428.   prec = Math.log(precision)/(Math.log(10));\
  4429.   for( var p = zero_x + xstep ; p < xsize ; p = p+xstep){\
  4430.    if(skip == 0 ){\
  4431.      disp_cnt = cnt.toFixed(prec);\
  4432.      corr = ctx.measureText(disp_cnt).width;\
  4433.      skip = parseInt(1.2*corr/xstep);\
  4434.      ctx.fillText(disp_cnt,p-0.5*corr,zero_y+1.4*font_size);\
  4435.    }\
  4436.    else\
  4437.    {\
  4438.     skip--;\
  4439.    };\
  4440.    cnt = cnt + xmajor;\
  4441.   };\
  4442.   cnt = -1*xmajor;skip = 0;\
  4443.   for( var p = zero_x - xstep ; p > 0 ; p = p-xstep){\
  4444.    if(skip == 0 ){\
  4445.     disp_cnt = cnt.toFixed(prec);\
  4446.     corr = ctx.measureText(disp_cnt).width;\
  4447.     skip = parseInt(1.2*corr/xstep);\
  4448.     ctx.fillText(disp_cnt,p-0.5*corr,zero_y+1.4*font_size);\
  4449.    }\
  4450.    else\
  4451.    {\
  4452.     skip--;\
  4453.    };\
  4454.    cnt = cnt - xmajor;\
  4455.   };\
  4456.  };\
  4457.  if( y_strings != null ){\
  4458.   var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
  4459.   for(var p = 0 ; p < len ; p = p+2){\
  4460.    var y_nums = y2px(eval(y_strings[p]));\
  4461.    var y_text = y_strings[p+1];\
  4462.    var f = 1.4;\
  4463.    corr = 2 + tics_length + ctx.measureText(y_text).width;\
  4464.    if( corr > zero_x){corr = parseInt(zero_x+2); }\
  4465.    ctx.fillText(y_text,zero_x - corr,y_nums);\
  4466.   };\
  4467.  }\
  4468.  else\
  4469.  {\
  4470.   corr = 0;cnt = -1*ymajor;skip = 0;\
  4471.   for( var p = zero_y + ystep ; p < ysize ; p = p+ystep){\
  4472.    if(skip == 0 ){\
  4473.     skip = parseInt(1.4*font_size/ystep);\
  4474.     disp_cnt = cnt.toFixed(prec);\
  4475.     corr = 2 + tics_length + ctx.measureText(disp_cnt).width;\
  4476.     ctx.fillText(disp_cnt,zero_x - corr,p+0.4*font_size);\
  4477.    }\
  4478.    else\
  4479.    {\
  4480.     skip--;\
  4481.    };\
  4482.    cnt = cnt - ymajor;\
  4483.   }\
  4484.   cnt = ymajor;skip = 0;\
  4485.   for( var p = zero_y - ystep ; p > 0 ; p = p-ystep){\
  4486.    if(skip == 0 ){\
  4487.     skip = parseInt(1.4*font_size/ystep);\
  4488.     disp_cnt = cnt.toFixed(prec);\
  4489.     corr = 2 + tics_length + ctx.measureText(disp_cnt).width;\
  4490.     ctx.fillText(disp_cnt,zero_x - corr,p+0.4*font_size);\
  4491.    }\
  4492.    else\
  4493.    {\
  4494.     skip--;\
  4495.    };\
  4496.    cnt = cnt + ymajor;\
  4497.   }\
  4498.  };\
  4499. };\
  4500. ctx.strokeStyle = stroke_color;\
  4501. ctx.lineWidth = 2;\
  4502. ctx.beginPath();\
  4503. ctx.rect(0,0,xsize,ysize);\
  4504. ctx.closePath();\
  4505. ctx.stroke();\
  4506. };\
  4507. if( typeof linegraph_0 !== 'undefined' ){\
  4508. ctx.restore();\
  4509. ctx.save();\
  4510. ctx.globalAlpha = 1.0;\
  4511. var i = 0;\
  4512. var line_name = eval('linegraph_'+i);\
  4513. while ( typeof line_name !== 'undefined' ){\
  4514.  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
  4515.  ctx.lineWidth = parseInt(line_name[1]);\
  4516.  if(line_name[2] == \"1\"){\
  4517.   var d1 = parseInt(line_name[3]);\
  4518.   var d2 = parseInt(line_name[4]);\
  4519.   if(ctx.setLineDash){ ctx.setLineDash(d1,d2); } else { ctx.mozDash = [d1,d2];};\
  4520.  }\
  4521.  else\
  4522.  {\
  4523.  if(ctx.setLineDash){ctx.setLineDash = null;}\
  4524.  if(ctx.mozDash){ctx.mozDash = null;}\
  4525.  };\
  4526.  var data_x = new Array();\
  4527.  var data_y = new Array();\
  4528.  var lb = line_name.length;\
  4529.  var idx = 0;\
  4530.  for( var p = 5 ; p < lb ; p = p + 2 ){\
  4531.   data_x[idx] = x2px(line_name[p]);\
  4532.   data_y[idx] = y2px(line_name[p+1]);\
  4533.   idx++;\
  4534.  };\
  4535.  for( var p = 0; p < idx ; p++){\
  4536.   ctx.beginPath();\
  4537.   ctx.moveTo(data_x[p],data_y[p]);\
  4538.   ctx.lineTo(data_x[p+1],data_y[p+1]);\
  4539.   ctx.stroke();\
  4540.   ctx.closePath();\
  4541.  };\
  4542.  i++;\
  4543.  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
  4544. };\
  4545. };\
  4546. var barcolor = new Array();\
  4547. if( typeof barchart%d  !== 'undefined' ){\
  4548. ctx.restore();\
  4549. ctx.save();\
  4550. ctx.globalAlpha = 1.0;\
  4551. var bar_x = new Array();\
  4552. var bar_y = new Array();\
  4553. var lb = barchart%d.length;\
  4554. var idx = 0;\
  4555. for( var p = 0 ; p < lb ; p = p + 3 ){\
  4556.  bar_x[idx] = x2px(barchart%d[p]);\
  4557.  bar_y[idx] = y2px(barchart%d[p+1]);\
  4558.  barcolor[idx] = barchart%d[p+2];\
  4559.  idx++;\
  4560. };\
  4561. var dx = parseInt(0.6*xstep);\
  4562. ctx.globalAlpha = fill_opacity;\
  4563. for( var p = 0; p < idx ; p++ ){\
  4564.  ctx.beginPath();\
  4565.  ctx.strokeStyle = barcolor[p];\
  4566.  ctx.fillStyle = barcolor[p];\
  4567.  ctx.rect(bar_x[p]-0.5*dx,bar_y[p],dx,zero_y - bar_y[p]);\
  4568.  ctx.fill();\
  4569.  ctx.stroke();\
  4570.  ctx.closePath();\
  4571. };\
  4572. };\
  4573. if( typeof legend%d  !== 'undefined' ){\
  4574. ctx.globalAlpha = 1.0;\
  4575. ctx.font = \"bold \"+font_size+\"px Ariel\";\
  4576. var y_offset = 2*font_size;\
  4577. var txt;var txt_size;\
  4578. var x_offset = xsize - 2*font_size;\
  4579. var l_length = legend%d.length;\
  4580. if( typeof legendcolors%d !== 'undefined' ){\
  4581.  for(var p = 0 ; p < l_length ; p++){\
  4582.    barcolor[p] = legendcolors%d[p];\
  4583.  };\
  4584. }else{\
  4585.  if( barcolor.length == 0 ){\
  4586.   for(var p = 0 ; p < l_length ; p++){\
  4587.    barcolor[p] = stroke_color;\
  4588.   };\
  4589.  };\
  4590. };\
  4591. for(var p = 0; p < l_length; p++){\
  4592.  ctx.fillStyle = barcolor[p];\
  4593.  txt = legend%d[p];\
  4594.  txt_size = ctx.measureText(txt).width;\
  4595.  ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
  4596.  y_offset = parseInt(y_offset + 1.5*font_size);\
  4597. };\
  4598. };\
  4599. ctx.restore();\
  4600. return;\
  4601. };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  4602.     break;
  4603.    
  4604.     case DRAW_PIECHART:
  4605. fprintf(js_include_file,"\n<!-- draw piechars -->\n\
  4606. function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,font_size,font_family){\
  4607. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4608.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4609. }\
  4610. else\
  4611. {\
  4612.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4613. };\
  4614. var ld = data_color_list.length;\
  4615. var sum = 0;\
  4616. var idx = 0;\
  4617. var colors = new Array();\
  4618. var data = new Array();\
  4619. for(var p = 0;p < ld; p = p + 2){\
  4620.  data[idx] = parseFloat(data_color_list[p]);\
  4621.  sum = sum + data[idx];\
  4622.  colors[idx] = data_color_list[p+1];\
  4623.  idx++;\
  4624. };\
  4625. var ctx = obj.getContext(\"2d\");\
  4626. ctx.save();\
  4627. var angle;\
  4628. var angle_end = 0;\
  4629. var offset = Math.PI / 2;\
  4630. ctx.globalAlpha = fill_opacity;\
  4631. for(var p=0; p < idx; p++){\
  4632.  ctx.beginPath();\
  4633.  ctx.fillStyle = colors[p];\
  4634.  ctx.moveTo(x_center,y_center);\
  4635.  angle = Math.PI * (2 * data[p] / sum);\
  4636.  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
  4637.  ctx.lineTo(x_center, y_center);\
  4638.  ctx.fill();\
  4639.  ctx.closePath();\
  4640.  angle_end  = angle_end + angle;\
  4641. };\
  4642. if( typeof legend%d  !== 'undefined' ){\
  4643.  ctx.globalAlpha = 1.0;\
  4644.  ctx.font = font_size+\"px \"+font_family;\
  4645.  var y_offset = font_size; \
  4646.  var x_offset = 0;\
  4647.  var txt;var txt_size;\
  4648.  for(var p = 0; p < idx; p++){\
  4649.   ctx.fillStyle = colors[p];\
  4650.   txt = legend%d[p];\
  4651.   txt_size = ctx.measureText(txt).width;\
  4652.   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
  4653.   ctx.fillText(legend%d[p],x_center + radius - x_offset, y_center - radius + y_offset);\
  4654.   y_offset = parseInt(y_offset + 1.5*font_size);\
  4655.  };\
  4656. };\
  4657. ctx.restore();\
  4658. };\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
  4659.    
  4660.     break;
  4661.     case DRAW_ARCS:
  4662. fprintf(js_include_file,"\n<!-- draw arcs -->\n\
  4663. draw_arc = function(canvas_type,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  4664. var obj;\
  4665. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4666.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4667. }\
  4668. else\
  4669. {\
  4670.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4671. };\
  4672. var ctx = obj.getContext(\"2d\");\
  4673. ctx.save();\
  4674. if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
  4675. if( use_translate == 1 ){ctx.translate(vector[0],vector[1]);};\
  4676. if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
  4677. if(end < start){var tmp = end;end = start;start=tmp;};\
  4678. start=360-start;\
  4679. end=360-end;\
  4680. ctx.lineWidth = line_width;\
  4681. ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4682. if( use_filled == 1 ){\
  4683.  ctx.beginPath();\
  4684.  ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
  4685.  var x1 = xc + r*Math.cos(Math.PI*start/180);\
  4686.  var y1 = yc + r*Math.sin(Math.PI*start/180);\
  4687.  var x2 = xc + r*Math.cos(Math.PI*end/180);\
  4688.  var y2 = yc + r*Math.sin(Math.PI*end/180);\
  4689.  ctx.beginPath();\
  4690.  ctx.moveTo(x1,y1);\
  4691.  ctx.lineTo(xc,yc);\
  4692.  ctx.moveTo(xc,yc);\
  4693.  ctx.lineTo(x2,y2);\
  4694.  ctx.closePath();\
  4695.  ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  4696.  ctx.fill();\
  4697.  ctx.stroke();\
  4698. }\
  4699. else\
  4700. {\
  4701.    ctx.beginPath();\
  4702.    ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
  4703.    ctx.stroke();\
  4704.    ctx.closePath();\
  4705. }\
  4706. ctx.restore();\
  4707. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  4708.    
  4709.     break;
  4710.     case DRAW_TEXTS:
  4711. fprintf(js_include_file,"\n<!-- draw text -->\n\
  4712. draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_translate,vector){\
  4713.  var obj;\
  4714.  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4715.   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4716.  }\
  4717.  else\
  4718.  {\
  4719.   obj = create_canvas%d(canvas_type,xsize,ysize);\
  4720.  };\
  4721.  var ctx = obj.getContext(\"2d\");\
  4722.  if(angle2 == 0 && angle != 0){\
  4723.   ctx.save();\
  4724.   if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4725.   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4726.  };\
  4727.  if( font_family.indexOf('px') != null ){\
  4728.   ctx.font = font_family;\
  4729.  }\
  4730.  else\
  4731.  {\
  4732.   ctx.font = \"+font_size+'px '+font_family \";\
  4733.  };\
  4734.  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4735.  if(angle2 != 0){\
  4736.   ctx.save();\
  4737.   ctx.translate(x,y);\
  4738.   ctx.rotate((360-angle2)*(Math.PI / 180));\
  4739.   ctx.fillText(text,0,0);\
  4740.   ctx.restore();\
  4741.  }else{ctx.fillText(text,x,y);};\
  4742. ctx.restore();\
  4743. return;\
  4744. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  4745.    
  4746.     break;
  4747.     case DRAW_CURVE:
  4748. fprintf(js_include_file,"\n<!-- draw curve -->\n\
  4749. draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_translate,vector){\
  4750. var obj;\
  4751. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4752.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4753. }\
  4754. else\
  4755. {\
  4756.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4757. };\
  4758. var ctx = obj.getContext(\"2d\");\
  4759. ctx.save();\
  4760. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4761. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4762. ctx.beginPath();ctx.lineWidth = line_width;\
  4763. if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
  4764. ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4765. ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
  4766. for(var p = 1 ; p < x_points.length ; p++){\
  4767.  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
  4768.  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
  4769.  }\
  4770.  else\
  4771.  {\
  4772.   ctx.stroke();\
  4773.   ctx.beginPath();\
  4774.   p++;\
  4775.   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
  4776.  };\
  4777. };\
  4778. ctx.stroke();\
  4779. ctx.restore();\
  4780. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  4781.     break;
  4782.    
  4783.     case DRAW_INPUTS:
  4784. fprintf(js_include_file,"\n<!-- draw input fields -->\n\
  4785. draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
  4786. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  4787. var input = document.createElement(\"input\");\
  4788. input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  4789. input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  4790. input.setAttribute(\"size\",size);\
  4791. input.setAttribute(\"value\",value);\
  4792. if( readonly == 0 ){ input.setAttribute(\"readonly\",\"readonly\");};\
  4793. canvas_div.appendChild(input);\n};");
  4794.     break;
  4795.    
  4796.     case DRAW_TEXTAREAS:
  4797. fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
  4798. draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
  4799. var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
  4800. var textarea = document.createElement(\"textarea\");\
  4801. textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
  4802. textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
  4803. textarea.setAttribute(\"cols\",cols);\
  4804. textarea.setAttribute(\"rows\",rows);\
  4805. textarea.innerHTML = value;\
  4806. canvas_div.appendChild(textarea);\n};");
  4807.     break;
  4808.    
  4809. case DRAW_PIXELS:
  4810. fprintf(js_include_file,"\n<!-- draw pixel -->\n\
  4811. draw_setpixel = function(x,y,color,opacity,pixelsize){\
  4812. var canvas = create_canvas%d(10,xsize,ysize);\
  4813. var d = 0.5*pixelsize;\
  4814. var ctx = canvas.getContext(\"2d\");\
  4815. ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
  4816. ctx.clearRect(0,0,xsize,ysize);\
  4817. for(var p=0; p<x.length;p++){\
  4818.  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
  4819. };\
  4820. ctx.fill();ctx.stroke();\
  4821. };",canvas_root_id);
  4822. break;
  4823.  
  4824. case DRAW_CLOCK:
  4825. fprintf(js_include_file,"\n<!-- begin command clock -->\n\
  4826. var clock_canvas = create_canvas%d(%d,xsize,ysize);\
  4827. var clock_ctx = clock_canvas.getContext(\"2d\");\
  4828. var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
  4829. clock_ctx.save();\
  4830. this.type = type || 0;\
  4831. this.interaction = interaction || 0;\
  4832. this.H = H || parseInt(110*(Math.random()));\
  4833. this.M = M || parseInt(590*(Math.random()));\
  4834. this.S = S || parseInt(590*(Math.random()));\
  4835. this.xc = xc || xsize/2;\
  4836. this.yc = yc || ysize/2;\
  4837. this.radius = radius || xsize/4;\
  4838. var font_size = parseInt(0.2*this.radius);\
  4839. this.H_color = h_color || \"blue\";\
  4840. this.M_color = m_color || \"blue\";\
  4841. this.S_color = s_color || \"blue\";\
  4842. this.fg_color = fg_color || \"red\";\
  4843. this.bg_color = bg_color || \"white\";\
  4844. clock_ctx.translate(this.xc,this.yc);\
  4845. clock_ctx.beginPath();\
  4846. clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
  4847. clock_ctx.fillStyle = this.bg_color;\
  4848. clock_ctx.fill();\
  4849. clock_ctx.closePath();\
  4850. clock_ctx.beginPath();\
  4851. clock_ctx.font = font_size+\"px Arial\";\
  4852. clock_ctx.fillStyle = this.fg_color;\
  4853. clock_ctx.textAlign = \"center\";\
  4854. clock_ctx.textBaseline = 'middle';\
  4855. var angle;var x1,y1,x2,y2;\
  4856. var angle_cos;var angle_sin;\
  4857. switch(type){\
  4858. case 0:clock_ctx.beginPath();\
  4859. for(var p = 1; p <= 12 ; p++){\
  4860.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  4861.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  4862.  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  4863.  clock_ctx.moveTo(x1,y1);\
  4864.  clock_ctx.lineTo(x2,y2);\
  4865. };\
  4866. for(var p = 1; p <= 60 ; p++){\
  4867.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  4868.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  4869.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  4870.  clock_ctx.moveTo(x1,y1);\
  4871.  clock_ctx.lineTo(x2,y2);\
  4872. };\
  4873. clock_ctx.closePath();\
  4874. clock_ctx.stroke();\
  4875. break;\
  4876. case 1:\
  4877. for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.9*this.radius*Math.cos(angle);y1 = 0.9*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};break;\
  4878. case 2:for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 1.1*this.radius*Math.cos(angle);y1 = 1.1*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\
  4879. clock_ctx.beginPath();\
  4880. for(var p = 1; p <= 12 ; p++){\
  4881.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
  4882.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
  4883.  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  4884.  clock_ctx.moveTo(x1,y1);\
  4885.  clock_ctx.lineTo(x2,y2);\
  4886. };\
  4887. for(var p = 1; p <= 60 ; p++){\
  4888.  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
  4889.  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
  4890.  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
  4891.  clock_ctx.moveTo(x1,y1);\
  4892.  clock_ctx.lineTo(x2,y2);\
  4893. };\
  4894. clock_ctx.closePath();\
  4895. clock_ctx.stroke();\
  4896. break;\
  4897. };\
  4898. angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
  4899. clock_ctx.rotate(angle);\
  4900. clock_ctx.beginPath();\
  4901. clock_ctx.moveTo(-3, -2);\
  4902. clock_ctx.lineTo(-3, 2);\
  4903. clock_ctx.lineTo(this.radius * 0.7, 1);\
  4904. clock_ctx.lineTo(this.radius  * 0.7, -1);\
  4905. clock_ctx.fillStyle = this.H_color;\
  4906. clock_ctx.fill();\
  4907. clock_ctx.rotate(-angle);\
  4908. angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
  4909. clock_ctx.rotate(angle);\
  4910. clock_ctx.beginPath();\
  4911. clock_ctx.moveTo(-3, -2);\
  4912. clock_ctx.lineTo(-3, 2);\
  4913. clock_ctx.lineTo(this.radius  * 0.8, 1);\
  4914. clock_ctx.lineTo(this.radius  * 0.8, -1);\
  4915. clock_ctx.fillStyle = this.M_color;\
  4916. clock_ctx.fill();\
  4917. clock_ctx.rotate(-angle);\
  4918. angle = (this.S - 15) * 2 * Math.PI / 60;\
  4919. clock_ctx.rotate(angle);\
  4920. clock_ctx.beginPath();\
  4921. clock_ctx.moveTo(0,0);\
  4922. clock_ctx.lineTo(this.radius  * 0.95, 0);\
  4923. clock_ctx.lineTo(this.radius  * 0.9, -1);\
  4924. clock_ctx.strokeStyle = this.S_color;\
  4925. clock_ctx.stroke();\
  4926. clock_ctx.restore();\
  4927. };\
  4928. \n<!-- end command clock -->\n",canvas_root_id,CLOCK_CANVAS);
  4929. break;
  4930.  
  4931. case DRAW_LATTICE:
  4932. fprintf(js_include_file,"\n<!-- draw lattice -->\n\
  4933. draw_lattice = function(canvas_type,line_width,x0,y0,dx1,dy1,dx2,dy2,n1,n2,fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_translate,vector){\
  4934. var obj;\
  4935. if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
  4936.  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
  4937. }\
  4938. else\
  4939. {\
  4940.  obj = create_canvas%d(canvas_type,xsize,ysize);\
  4941. };\
  4942. var ctx = obj.getContext(\"2d\");\
  4943. ctx.save();\
  4944. if(use_translate == 1 ){ctx.translate(vector[0],vector[1]);}\
  4945. if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
  4946. ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4947. ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
  4948. var radius = line_width;\
  4949. var x = 0;\
  4950. var y = 0;\
  4951. var x_step_px = xsize/(xmax-xmin);\
  4952. var y_step_px = ysize/(ymax-ymin);\
  4953. var xv1 = dx1*x_step_px;\
  4954. var yv1 = dy1*y_step_px;\
  4955. var xv2 = dx2*x_step_px;\
  4956. var yv2 = dy2*y_step_px;\
  4957. for(var p = 0; p < n1 ;p++){\
  4958.  x = p*xv1 + x0;\
  4959.  y = p*yv1 + y0;\
  4960.  for(var c = 0; c < n2 ; c++){\
  4961.   ctx.beginPath();\
  4962.   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
  4963.   ctx.fill();\
  4964.   ctx.stroke();\
  4965.   ctx.closePath();\
  4966.  };\
  4967. };\
  4968. ctx.restore();\
  4969. return;\
  4970. };\n",canvas_root_id,canvas_root_id,canvas_root_id);
  4971.     break;
  4972.  
  4973.     default:break;
  4974.    }
  4975.   }
  4976.  }
  4977.   return;
  4978. }
  4979.  
  4980. void check_string_length(int L){
  4981.  if(L<1 || L > MAX_BUFFER-1){
  4982.   canvas_error("problem with your arguments to command...");
  4983.  }
  4984.  return;
  4985. }
  4986.  
  4987.  
  4988. int get_token(FILE *infile){
  4989.         int     c,i=0;
  4990.         char    temp[MAX_INT], *input_type;
  4991.         char    *line="line",
  4992.         *audio="audio",
  4993.         *blink="blink",
  4994.         *arrowhead="arrowhead",
  4995.         *crosshairsize="crosshairsize",
  4996.         *crosshair="crosshair",
  4997.         *crosshairs="crosshairs",
  4998.         *audioobject="audioobject",
  4999.         *style="style",
  5000.         *mouse="mouse",
  5001.         *userdraw="userdraw",
  5002.         *highlight="highlight",
  5003.         *http="http",
  5004.         *rays="rays",
  5005.         *dashtype="dashtype",
  5006.         *dashed="dashed",
  5007.         *filled="filled",
  5008.         *lattice="lattice",
  5009.         *parallel="parallel",
  5010.         *segment="segment",
  5011.         *dsegment="dsegment",
  5012.         *seg="seg",
  5013.         *bgimage="bgimage",
  5014.         *bgcolor="bgcolor",
  5015.         *strokecolor="strokecolor",
  5016.         *backgroundimage="backgroundimage",
  5017.         *text="text",
  5018.         *textup="textup",
  5019.         *mouseprecision="mouseprecision",
  5020.         *precision="precision",
  5021.         *plotsteps="plotsteps",
  5022.         *plotstep="plotstep",
  5023.         *tsteps="tsteps",
  5024.         *curve="curve",
  5025.         *dcurve="dcurve",
  5026.         *plot="plot",
  5027.         *dplot="dplot",
  5028.         *fontsize="fontsize",
  5029.         *fontcolor="fontcolor",
  5030.         *axis="axis",
  5031.         *axisnumbering="axisnumbering",
  5032.         *axisnumbers="axisnumbers",
  5033.         *arrow="arrow",
  5034.         *darrow="darrow",
  5035.         *arrow2="arrow2",
  5036.         *darrow2="darrow2",
  5037.         *zoom="zoom",
  5038.         *grid="grid",
  5039.         *hline="hline",
  5040.         *drag="drag",
  5041.         *horizontalline="horizontalline",
  5042.         *vline="vline",
  5043.         *verticalline="verticalline",
  5044.         *triangle="triangle",
  5045.         *ftriangle="ftriangle",
  5046.         *mathml="mathml",
  5047.         *html="html",
  5048.         *input="input",
  5049.         *button="button",
  5050.         *inputstyle="inputstyle",
  5051.         *textarea="textarea",
  5052.         *trange="trange",
  5053.         *ranget="ranget",
  5054.         *xrange="xrange",
  5055.         *yrange="yrange",
  5056.         *rangex="rangex",
  5057.         *rangey="rangey",
  5058.         *polyline="polyline",
  5059.         *lines="lines",
  5060.         *poly="poly",
  5061.         *polygon="polygon",
  5062.         *fpolygon="fpolygon",
  5063.         *fpoly="fpoly",
  5064.         *filledpoly="filledpoly",
  5065.         *filledpolygon="filledpolygon",
  5066.         *rect="rect",
  5067.         *frect="frect",
  5068.         *rectangle="rectangle",
  5069.         *frectangle="frectangle",
  5070.         *square="square",
  5071.         *fsquare="fsquare",
  5072.         *dline="dline",
  5073.         *arc="arc",
  5074.         *filledarc="filledarc",
  5075.         *size="size",
  5076.         *string="string",
  5077.         *stringup="stringup",
  5078.         *copy="copy",
  5079.         *copyresized="copyresized",
  5080.         *opacity="opacity",
  5081.         *transparent="transparent",
  5082.         *fill="fill",
  5083.         *slider="slider",
  5084.         *point="point",
  5085.         *points="points",
  5086.         *linewidth="linewidth",
  5087.         *circle="circle",
  5088.         *fcircle="fcircle",
  5089.         *disk="disk",
  5090.         *comment="#",
  5091.         *end="end",
  5092.         *ellipse="ellipse",
  5093.         *fellipse="fellipse",
  5094.         *rotate="rotate",
  5095.         *fontfamily="fontfamily",
  5096.         *fillcolor="fillcolor",
  5097.         *clicktile="clicktile",
  5098.         *clicktile_colors="clicktile_colors",
  5099.         *translation="translation",
  5100.         *translate="translate",
  5101.         *killtranslation="killtranslation",
  5102.         *killtranslate="killtranslate",
  5103.         *onclick="onclick",
  5104.         *roundrect="roundrect",
  5105.         *froundrect="froundrect",
  5106.         *roundrectangle="roundrectangle",
  5107.         *patternfill="patternfill",
  5108.         *hatchfill="hatchfill",
  5109.         *diafill="diafill",
  5110.         *dotfill="dotfill",
  5111.         *gridfill="gridfill",
  5112.         *imagefill="imagefill",
  5113.         *logbase="logbase",
  5114.         *xlogscale="xlogscale",
  5115.         *ylogscale="ylogscale",
  5116.         *xylogscale="xylogscale",
  5117.         *intooltip="intooltip",
  5118.         *replyformat="replyformat",
  5119.         *floodfill="floodfill",
  5120.         *filltoborder="filltoborder",
  5121.         *clickfill="clickfill",
  5122.         *debug="debug",
  5123.         *setpixel="setpixel",
  5124.         *pixels="pixels",
  5125.         *pixelsize="pixelsize",
  5126.         *clickfillmarge="clickfillmarge",
  5127.         *xaxis="xaxis",
  5128.         *yaxis="yaxis",
  5129.         *xaxistext="xaxistext",
  5130.         *yaxistext="yaxistext",
  5131.         *piechart="piechart",
  5132.         *legend="legend",
  5133.         *legendcolors="legendcolors",
  5134.         *xlabel="xlabel",
  5135.         *ylabel="ylabel",
  5136.         *barchart="barchart",
  5137.         *linegraph="linegraph",
  5138.         *clock="clock",
  5139.         *animate="animate",
  5140.         *video="video",
  5141.         *status="status",
  5142.         *snaptogrid="snaptogrid";
  5143.  
  5144.         while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
  5145.             if( i == 0 && (c == ' ' || c == '\t') ){
  5146.         continue; /* white spaces or tabs allowed before first command identifier */
  5147.             }
  5148.             else
  5149.             {
  5150.         if( c == ' ' || c == '\t' ){
  5151.             break;
  5152.         }
  5153.         else
  5154.         {
  5155.             temp[i] = c;
  5156.             if(i > MAX_INT - 2){canvas_error("command string too long !");}
  5157.             i++;
  5158.         }
  5159.             }
  5160.             if(temp[0] == '#') break;
  5161.         }
  5162.         if (c == EOF) finished = 1;
  5163.  
  5164.         if (c == '\n' || c == '\r') {
  5165.         line_number++;
  5166.         if (i == 0) { return EMPTY; }
  5167.         } else if (c == EOF) {
  5168.         return 0;
  5169.         }
  5170.  
  5171.         temp[i]='\0';
  5172.         input_type=(char*)my_newmem(strlen(temp));
  5173.         snprintf(input_type,sizeof(temp),"%s",temp);
  5174.  
  5175.         if( strcmp(input_type, size) == 0 ){
  5176.         free(input_type);
  5177.         return SIZE;
  5178.         }
  5179.         if( strcmp(input_type, xrange) == 0 ){
  5180.         free(input_type);
  5181.         return XRANGE;
  5182.         }
  5183.         if( strcmp(input_type, rangex) == 0 ){
  5184.         free(input_type);
  5185.         return XRANGE;
  5186.         }
  5187.         if( strcmp(input_type, trange) == 0 ){
  5188.         free(input_type);
  5189.         return TRANGE;
  5190.         }
  5191.         if( strcmp(input_type, ranget) == 0 ){
  5192.         free(input_type);
  5193.         return TRANGE;
  5194.         }
  5195.         if( strcmp(input_type, yrange) == 0 ){
  5196.         free(input_type);
  5197.         return YRANGE;
  5198.         }
  5199.         if( strcmp(input_type, rangey) == 0 ){
  5200.         free(input_type);
  5201.         return YRANGE;
  5202.         }
  5203.         if( strcmp(input_type, linewidth) == 0 ){
  5204.         free(input_type);
  5205.         return LINEWIDTH;
  5206.         }
  5207.         if( strcmp(input_type, dashed) == 0 ){
  5208.         free(input_type);
  5209.         return DASHED;
  5210.         }
  5211.         if( strcmp(input_type, dashtype) == 0 ){
  5212.         free(input_type);
  5213.         return DASHTYPE;
  5214.         }
  5215.         if( strcmp(input_type, axisnumbering) == 0 ){
  5216.         free(input_type);
  5217.         return AXIS_NUMBERING;
  5218.         }
  5219.         if( strcmp(input_type, axisnumbers) == 0 ){
  5220.         free(input_type);
  5221.         return AXIS_NUMBERING;
  5222.         }
  5223.         if( strcmp(input_type, axis) == 0 ){
  5224.         free(input_type);
  5225.         return AXIS;
  5226.         }
  5227.         if( strcmp(input_type, grid) == 0 ){
  5228.         free(input_type);
  5229.         return GRID;
  5230.         }
  5231.         if( strcmp(input_type, parallel) == 0 ){
  5232.         free(input_type);
  5233.         return PARALLEL;
  5234.         }
  5235.         if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
  5236.         free(input_type);
  5237.         return HLINE;
  5238.         }
  5239.         if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
  5240.         free(input_type);
  5241.         return VLINE;
  5242.         }
  5243.         if( strcmp(input_type, line) == 0 ){
  5244.         free(input_type);
  5245.         return LINE;
  5246.         }
  5247.         if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
  5248.         free(input_type);
  5249.         return SEGMENT;
  5250.         }
  5251.         if( strcmp(input_type, dsegment) == 0 ){
  5252.         free(input_type);
  5253.         use_dashed = TRUE;
  5254.         return SEGMENT;
  5255.         }
  5256.         if( strcmp(input_type, crosshairsize) == 0 ){
  5257.         free(input_type);
  5258.         return CROSSHAIRSIZE;
  5259.         }
  5260.         if( strcmp(input_type, arrowhead) == 0 ){
  5261.         free(input_type);
  5262.         return ARROWHEAD;
  5263.         }
  5264.         if( strcmp(input_type, crosshairs) == 0 ){
  5265.         free(input_type);
  5266.         return CROSSHAIRS;
  5267.         }
  5268.         if( strcmp(input_type, crosshair) == 0 ){
  5269.         free(input_type);
  5270.         return CROSSHAIR;
  5271.         }
  5272.         if( strcmp(input_type, onclick) == 0 ){
  5273.         free(input_type);
  5274.         return ONCLICK;
  5275.         }
  5276.         if( strcmp(input_type, drag) == 0 ){
  5277.         free(input_type);
  5278.         return DRAG;
  5279.         }
  5280.         if( strcmp(input_type, userdraw) == 0 ){
  5281.         free(input_type);
  5282.         return USERDRAW;
  5283.         }
  5284.         if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
  5285.         free(input_type);
  5286.         return STYLE;
  5287.         }
  5288.         if( strcmp(input_type, fillcolor) == 0 ){
  5289.         free(input_type);
  5290.         return FILLCOLOR;
  5291.         }
  5292.         if( strcmp(input_type, strokecolor) == 0 ){
  5293.         free(input_type);
  5294.         return STROKECOLOR;
  5295.         }
  5296.         if( strcmp(input_type, filled) == 0  ){
  5297.         free(input_type);
  5298.         return FILLED;
  5299.         }
  5300.         if( strcmp(input_type, http) == 0 ){
  5301.         free(input_type);
  5302.         return HTTP;
  5303.         }
  5304.         if( strcmp(input_type, rays) == 0 ){
  5305.         free(input_type);
  5306.         return RAYS;
  5307.         }
  5308.         if( strcmp(input_type, lattice) == 0 ){
  5309.         free(input_type);
  5310.         return LATTICE;
  5311.         }
  5312.         if( strcmp(input_type, bgimage) == 0 ){
  5313.         free(input_type);
  5314.         return BGIMAGE;
  5315.         }
  5316.         if( strcmp(input_type, bgcolor) == 0 ){
  5317.         free(input_type);
  5318.         return BGCOLOR;
  5319.         }
  5320.         if( strcmp(input_type, backgroundimage) == 0 ){
  5321.         free(input_type);
  5322.         return BGIMAGE;
  5323.         }
  5324.         if( strcmp(input_type, text) == 0 ){
  5325.         free(input_type);
  5326.         return FLY_TEXT;
  5327.         }
  5328.         if( strcmp(input_type, textup) == 0 ){
  5329.         free(input_type);
  5330.         return FLY_TEXTUP;
  5331.         }
  5332.         if( strcmp(input_type, mouse) == 0 ){
  5333.         free(input_type);
  5334.         return MOUSE;
  5335.         }
  5336.         if( strcmp(input_type, mouseprecision) == 0 ){
  5337.         free(input_type);
  5338.         return MOUSE_PRECISION;
  5339.         }
  5340.         if( strcmp(input_type, precision) == 0 ){
  5341.         free(input_type);
  5342.         return MOUSE_PRECISION;
  5343.         }
  5344.         if( strcmp(input_type, curve) == 0 ){
  5345.         free(input_type);
  5346.         return CURVE;
  5347.         }
  5348.         if( strcmp(input_type, dcurve) == 0 ){
  5349.         free(input_type);
  5350.         return CURVE;
  5351.         }
  5352.         if( strcmp(input_type, plot) == 0 ){
  5353.         free(input_type);
  5354.         return CURVE;
  5355.         }
  5356.         if( strcmp(input_type, dplot) == 0 ){
  5357.         free(input_type);
  5358.         return CURVE;
  5359.         }
  5360.         if( strcmp(input_type, plotsteps) == 0 ){
  5361.         free(input_type);
  5362.         return PLOTSTEPS;
  5363.         }
  5364.         if( strcmp(input_type, plotstep) == 0 ){
  5365.         free(input_type);
  5366.         return PLOTSTEPS;
  5367.         }
  5368.         if( strcmp(input_type, tsteps) == 0 ){
  5369.         free(input_type);
  5370.         return PLOTSTEPS;
  5371.         }
  5372.         if( strcmp(input_type, fontsize) == 0 ){
  5373.         free(input_type);
  5374.         return FONTSIZE;
  5375.         }
  5376.         if( strcmp(input_type, fontcolor) == 0 ){
  5377.         free(input_type);
  5378.         return FONTCOLOR;
  5379.         }
  5380.         if( strcmp(input_type, arrow) == 0 ){
  5381.         free(input_type);
  5382.         return ARROW;
  5383.         }
  5384.         if( strcmp(input_type, arrow2) == 0 ){
  5385.         free(input_type);
  5386.         return ARROW2;
  5387.         }
  5388.         if( strcmp(input_type, darrow) == 0 ){
  5389.         free(input_type);
  5390.         return ARROW;
  5391.         }
  5392.         if( strcmp(input_type, darrow2) == 0 ){
  5393.         free(input_type);
  5394.         use_dashed = TRUE;
  5395.         return ARROW2;
  5396.         }
  5397.         if( strcmp(input_type, zoom) == 0 ){
  5398.         free(input_type);
  5399.         return ZOOM;
  5400.         }
  5401.         if( strcmp(input_type, triangle) == 0 ){
  5402.         free(input_type);
  5403.         return TRIANGLE;
  5404.         }
  5405.         if( strcmp(input_type, ftriangle) == 0 ){
  5406.         free(input_type);
  5407.         use_filled = TRUE;
  5408.         return TRIANGLE;
  5409.         }
  5410.         if( strcmp(input_type, input) == 0 ){
  5411.         free(input_type);
  5412.         return INPUT;
  5413.         }
  5414.         if( strcmp(input_type, inputstyle) == 0 ){
  5415.         free(input_type);
  5416.         return INPUTSTYLE;
  5417.         }
  5418.         if( strcmp(input_type, textarea) == 0 ){
  5419.         free(input_type);
  5420.         return TEXTAREA;
  5421.         }
  5422.         if( strcmp(input_type, mathml) == 0 ){
  5423.         free(input_type);
  5424.         return MATHML;
  5425.         }
  5426.         if( strcmp(input_type, html) == 0 ){
  5427.         free(input_type);
  5428.         return MATHML;
  5429.         }
  5430.         if( strcmp(input_type, fontfamily) == 0 ){
  5431.         free(input_type);
  5432.         return FONTFAMILY;
  5433.         }
  5434.         if( strcmp(input_type, lines) == 0  ||  strcmp(input_type, polyline) == 0 ){
  5435.         free(input_type);
  5436.         return POLYLINE;
  5437.         }
  5438.         if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
  5439.         free(input_type);
  5440.         return RECT;
  5441.         }
  5442.         if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
  5443.         free(input_type);
  5444.         return ROUNDRECT;
  5445.         }
  5446.         if( strcmp(input_type, froundrect) == 0 ){
  5447.         free(input_type);
  5448.         use_filled = TRUE;
  5449.         return ROUNDRECT;
  5450.         }
  5451.         if( strcmp(input_type, square) == 0 ){
  5452.         free(input_type);
  5453.         return SQUARE;
  5454.         }
  5455.         if( strcmp(input_type, fsquare) == 0 ){
  5456.         free(input_type);
  5457.         use_filled = TRUE;
  5458.         return SQUARE;
  5459.         }
  5460.         if( strcmp(input_type, dline) == 0 ){
  5461.         use_dashed = TRUE;
  5462.         free(input_type);
  5463.         return LINE;
  5464.         }
  5465.         if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
  5466.         use_filled = TRUE;
  5467.         free(input_type);
  5468.         return RECT;
  5469.         }
  5470.         if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
  5471.         use_filled = TRUE;
  5472.         free(input_type);
  5473.         return CIRCLE;
  5474.         }
  5475.         if( strcmp(input_type, circle) == 0 ){
  5476.         free(input_type);
  5477.         return CIRCLE;
  5478.         }
  5479.         if( strcmp(input_type, point) == 0 ){
  5480.         free(input_type);
  5481.         return POINT;
  5482.         }
  5483.         if( strcmp(input_type, points) == 0 ){
  5484.         free(input_type);
  5485.         return POINTS;
  5486.         }
  5487.         if( strcmp(input_type, filledarc) == 0 ){
  5488.         use_filled = TRUE;
  5489.         free(input_type);
  5490.         return ARC;
  5491.         }
  5492.         if( strcmp(input_type, arc) == 0 ){
  5493.         free(input_type);
  5494.         return ARC;
  5495.         }
  5496.         if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
  5497.         free(input_type);
  5498.         return POLY;
  5499.         }
  5500.         if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
  5501.         use_filled = TRUE;
  5502.         free(input_type);
  5503.         return POLY;
  5504.         }
  5505.         if( strcmp(input_type, ellipse) == 0){
  5506.         free(input_type);
  5507.         return ELLIPSE;
  5508.         }
  5509.         if( strcmp(input_type, fill) == 0 ){
  5510.         free(input_type);
  5511.         return FLOODFILL;
  5512.         }
  5513.         if( strcmp(input_type, string) == 0 ){
  5514.         free(input_type);
  5515.         return STRING;
  5516.         }
  5517.         if( strcmp(input_type, stringup) == 0 ){
  5518.         free(input_type);
  5519.         return STRINGUP;
  5520.         }
  5521.         if( strcmp(input_type, opacity) == 0 ){
  5522.         free(input_type);
  5523.         return OPACITY;
  5524.         }
  5525.         if( strcmp(input_type, comment) == 0){
  5526.         free(input_type);
  5527.         return COMMENT;
  5528.         }
  5529.         if( strcmp(input_type, end) == 0){
  5530.         free(input_type);
  5531.         return END;
  5532.         }
  5533.         if( strcmp(input_type, fellipse) == 0){
  5534.         free(input_type);
  5535.         use_filled = TRUE;
  5536.         return ELLIPSE;
  5537.         }      
  5538.         if( strcmp(input_type, blink) == 0 ){
  5539.         free(input_type);
  5540.         return BLINK;
  5541.         }
  5542.         if( strcmp(input_type, button) == 0){
  5543.         free(input_type);
  5544.         return BUTTON;
  5545.         }
  5546.         if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
  5547.         free(input_type);
  5548.         return TRANSLATION;
  5549.         }
  5550.         if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
  5551.         free(input_type);
  5552.         return KILLTRANSLATION;
  5553.         }
  5554.         if( strcmp(input_type, rotate) == 0){
  5555.         free(input_type);
  5556.         return ROTATE;
  5557.         }
  5558.         if( strcmp(input_type, audio) == 0 ){
  5559.         free(input_type);
  5560.         return AUDIO;
  5561.         }
  5562.         if( strcmp(input_type, audioobject) == 0 ){
  5563.         free(input_type);
  5564.         return AUDIOOBJECT;
  5565.         }
  5566.         if( strcmp(input_type, slider) == 0 ){
  5567.         free(input_type);
  5568.         return SLIDER;
  5569.         }
  5570.         if( strcmp(input_type, copy) == 0 ){
  5571.         free(input_type);
  5572.         return COPY;
  5573.         }
  5574.         if( strcmp(input_type, copyresized) == 0 ){
  5575.         free(input_type);
  5576.         return COPYRESIZED;
  5577.         }
  5578.         if( strcmp(input_type, patternfill) == 0 ){
  5579.         free(input_type);
  5580.         return PATTERNFILL;
  5581.         }
  5582.         if( strcmp(input_type, hatchfill) == 0 ){
  5583.         free(input_type);
  5584.         return HATCHFILL;
  5585.         }
  5586.         if( strcmp(input_type, diafill) == 0 ){
  5587.         free(input_type);
  5588.         return DIAFILL;
  5589.         }
  5590.         if( strcmp(input_type, dotfill) == 0 ){
  5591.         free(input_type);
  5592.         return DOTFILL;
  5593.         }
  5594.         if( strcmp(input_type, gridfill) == 0 ){
  5595.         free(input_type);
  5596.         return GRIDFILL;
  5597.         }
  5598.         if( strcmp(input_type, imagefill) == 0 ){
  5599.         free(input_type);
  5600.         return IMAGEFILL;
  5601.         }
  5602.         if( strcmp(input_type, clicktile_colors) == 0 ){
  5603.         free(input_type);
  5604.         return CLICKTILE_COLORS;
  5605.         }
  5606.         if( strcmp(input_type, clicktile) == 0 ){
  5607.         free(input_type);
  5608.         return CLICKTILE;
  5609.         }
  5610.         if( strcmp(input_type, xlogscale) == 0 ){
  5611.         free(input_type);
  5612.         return XLOGSCALE;
  5613.         }
  5614.         if( strcmp(input_type, ylogscale) == 0 ){
  5615.         free(input_type);
  5616.         return YLOGSCALE;
  5617.         }
  5618.         if( strcmp(input_type, xylogscale) == 0 ){
  5619.         free(input_type);
  5620.         return XYLOGSCALE;
  5621.         }
  5622.         if( strcmp(input_type, ylogscale) == 0 ){
  5623.         free(input_type);
  5624.         return YLOGSCALE;
  5625.         }
  5626.         if( strcmp(input_type, logbase) == 0 ){
  5627.         free(input_type);
  5628.         return LOGBASE;
  5629.         }
  5630.         if( strcmp(input_type, intooltip) == 0 ){
  5631.         free(input_type);
  5632.         return INTOOLTIP;
  5633.         }
  5634.         if( strcmp(input_type,video) == 0 ){
  5635.         free(input_type);
  5636.         return VIDEO;
  5637.         }
  5638.         if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
  5639.         free(input_type);
  5640.         return FLOODFILL;
  5641.         }      
  5642.         if( strcmp(input_type,filltoborder) == 0 ){
  5643.         free(input_type);
  5644.         return FILLTOBORDER;
  5645.         }      
  5646.         if( strcmp(input_type,clickfill) == 0 ){
  5647.         free(input_type);
  5648.         return CLICKFILL;
  5649.         }      
  5650.         if( strcmp(input_type, replyformat) == 0 ){
  5651.         free(input_type);
  5652.         return REPLYFORMAT;
  5653.         }
  5654.         if( strcmp(input_type, debug) == 0 ){
  5655.         free(input_type);
  5656.         return DEBUG;
  5657.         }
  5658.         if( strcmp(input_type, pixelsize) == 0 ){
  5659.         free(input_type);
  5660.         return PIXELSIZE;
  5661.         }
  5662.         if( strcmp(input_type, setpixel) == 0 ){
  5663.         free(input_type);
  5664.         return SETPIXEL;
  5665.         }
  5666.         if( strcmp(input_type, pixels) == 0 ){
  5667.         free(input_type);
  5668.         return PIXELS;
  5669.         }
  5670.         if( strcmp(input_type, clickfillmarge) == 0 ){
  5671.         free(input_type);
  5672.         return CLICKFILLMARGE;
  5673.         }
  5674.         if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
  5675.         free(input_type);
  5676.         return X_AXIS_STRINGS;
  5677.         }
  5678.         if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
  5679.         free(input_type);
  5680.         return Y_AXIS_STRINGS;
  5681.         }
  5682.         if( strcmp(input_type, piechart) == 0  ){
  5683.         free(input_type);
  5684.         return PIECHART;
  5685.         }
  5686.         if( strcmp(input_type, barchart) == 0  ){
  5687.         free(input_type);
  5688.         return BARCHART;
  5689.         }
  5690.         if( strcmp(input_type, linegraph) == 0  ){
  5691.         free(input_type);
  5692.         return LINEGRAPH;
  5693.         }
  5694.         if( strcmp(input_type, clock) == 0  ){
  5695.         free(input_type);
  5696.         return CLOCK;
  5697.         }
  5698.         if( strcmp(input_type, legend) == 0  ){
  5699.         free(input_type);
  5700.         return LEGEND;
  5701.         }
  5702.         if( strcmp(input_type, legendcolors) == 0  ){
  5703.         free(input_type);
  5704.         return LEGENDCOLORS;
  5705.         }
  5706.         if( strcmp(input_type, xlabel) == 0  ){
  5707.         free(input_type);
  5708.         return XLABEL;
  5709.         }
  5710.         if( strcmp(input_type, ylabel) == 0  ){
  5711.         free(input_type);
  5712.         return YLABEL;
  5713.         }
  5714.         if( strcmp(input_type, animate) == 0  ){
  5715.         free(input_type);
  5716.         return ANIMATE;
  5717.         }
  5718.         /* these are bitmap related flydraw commmands...must be removed. eventually */
  5719.         if( strcmp(input_type, transparent) == 0 ){
  5720.         free(input_type);
  5721.         return TRANSPARENT;
  5722.         }
  5723.         if( strcmp(input_type, status) == 0 ){
  5724.         free(input_type);
  5725.         return STATUS;
  5726.         }
  5727.         if( strcmp(input_type, snaptogrid) == 0 ){
  5728.         free(input_type);
  5729.         return SNAPTOGRID;
  5730.         }
  5731.         free(input_type);
  5732.         ungetc(c,infile);
  5733.         return 0;
  5734. }
  5735.  
  5736.