Subversion Repositories wimsdev

Rev

Rev 8099 | Rev 8105 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7614 schaersvoo 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
*/
7856 schaersvoo 12
 
7848 bpr 13
#include "../../Lib/libwims.h"
14
#include "canvasdraw.h"
7842 bpr 15
#include <assert.h>
7848 bpr 16
#include "canvasmacro.c"
7614 schaersvoo 17
 
18
/******************************************************************************
19
**  Internal Functions
20
******************************************************************************/
21
void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
22
void    sync_input(FILE *infile);/* proceed with inputfile */
23
void    canvas_error(char *msg);
24
void    add_javascript_functions(int js_functions[], int canvas_root_id);
25
void    reset();/* reset some global variables like "use_filled" , "use_dashed" */
26
int     get_token(FILE *infile); /* read next char until EOL*/
27
int     x2px(double x);
28
int     y2px(double y);
29
double  px2x(int x);
30
double  px2y(int y);
7906 schaersvoo 31
double  get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */
7614 schaersvoo 32
char    *str_replace ( const char *word, const char *sub_word, const char *rep_word );
33
char    *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */
7906 schaersvoo 34
char    *get_string(FILE *infile,int last); /* get the string at the end of a command */
7614 schaersvoo 35
char    *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as  separator */
36
char    *convert_hex2rgb(char *hexcolor);
8074 schaersvoo 37
void    add_read_canvas(int reply_format,int reply_precision);
7614 schaersvoo 38
void    make_js_include(int canvas_root_id);
39
void    check_string_length(int length);/* checks if the length of string argument of command is correct */
7956 schaersvoo 40
FILE    *js_include_file;
7614 schaersvoo 41
FILE    *get_file(int *line_number, char **filename);
42
FILE    *infile;    /* will be stdin */
43
/******************************************************************************
44
** global
45
******************************************************************************/
46
int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */
47
int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */
48
/* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */
49
int xsize = 320;
50
int ysize = 320;
51
double xmin = 0.0;
52
double xmax = 320.0;
53
double ymin = 0.0;
54
double ymax = 320.0;
55
double tmax = 2;
56
double tmin = -2;
57
/* flag to indicate parsing of line status */
7956 schaersvoo 58
int done = FALSE;
7614 schaersvoo 59
int type; /* eg command number */
60
int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/
8097 schaersvoo 61
int slider = 0;/* slider=1 : x-values ; slider=2 : y-values;slider=3 angle values */
7785 schaersvoo 62
int use_affine = FALSE;
7614 schaersvoo 63
int use_rotate = FALSE;
64
int use_filled = FALSE;
65
int use_dashed = FALSE; /* dashing not natively supported in firefox  , for now... */
8097 schaersvoo 66
 
7614 schaersvoo 67
char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
68
 
69
/******************************************************************************
70
** Main Program
71
******************************************************************************/
72
int main(int argc, char *argv[]){
73
    /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */
74
    struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
75
    infile = stdin;/* read flyscript via stdin */
76
    int i,c;
77
    double double_data[MAX_INT+1];
78
    int int_data[MAX_INT+1];
79
    for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
80
    int use_parametric = FALSE;/* will be reset after parametric plotting */
81
    int use_axis = FALSE;
82
    int use_axis_numbering = FALSE;
7797 schaersvoo 83
    int use_pan_and_zoom = FALSE;
7956 schaersvoo 84
    int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */
7858 schaersvoo 85
    int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
86
    int use_js_plot = FALSE; /* if true , let js-engine plot the curve */
7614 schaersvoo 87
    int line_width = 1;
88
    int decimals = 2;
89
    int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */
90
    int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */
91
    int drag_type = -1;/* 0,1,2 : xy,x,y */
92
    int use_tooltip = FALSE;
93
    char *tooltip_text = "Click here";
94
    char *temp = ""; /* */
95
    char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
96
    char *stroke_color = "255,0,0";
97
    char *fill_color = "0,255,0";
98
    char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
99
    char *font_color = "#00000";
100
    char *draw_type = "points";
101
    char *fly_font = "normal";
102
    char *input_style = "";
103
    char *flytext = "";
7785 schaersvoo 104
    char *affine_matrix = "[1,0,0,1,0,0]";
7614 schaersvoo 105
    int pixelsize = 1;
106
    int reply_format = 0;
107
    int input_cnt = 0;
108
    int ext_img_cnt = 0;
8071 schaersvoo 109
    int slider_cnt = 0;
7614 schaersvoo 110
    int font_size = 12;
8071 schaersvoo 111
    int dashtype[2] = { 4 , 4 };
7614 schaersvoo 112
    int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
113
    for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
114
    int arrow_head = 8; /* size in px*/
7833 schaersvoo 115
    int crosshair_size = 5; /* size in px*/
7956 schaersvoo 116
    int plot_steps = 250;
7983 schaersvoo 117
    int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange*/
7614 schaersvoo 118
    int click_cnt = 1;
119
    int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
120
    int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
7989 schaersvoo 121
    int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
7956 schaersvoo 122
    int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
8074 schaersvoo 123
    int reply_precision = 100; /* used for precision of student answers / drawings */
7614 schaersvoo 124
    double angle = 0.0;
125
    int clickfillmarge = 20;
126
    int animation_type = 9; /* == object type curve in drag library */
7823 schaersvoo 127
    int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
7614 schaersvoo 128
    size_t string_length = 0;
129
    double stroke_opacity = 0.8;
130
    double fill_opacity = 0.8;
131
    char *URL = "http://localhost/images";
132
    memset(buffer,'\0',MAX_BUFFER);
133
    void *tmp_buffer = "";
7956 schaersvoo 134
 
7614 schaersvoo 135
    /* default writing a unzipped js-include file into wims getfile directory */
136
    char *w_wims_session = getenv("w_wims_session");
7956 schaersvoo 137
    if(  w_wims_session == NULL || *w_wims_session == 0 ){
7614 schaersvoo 138
        canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");
139
    }
140
    int L0=strlen(w_wims_session) + 21;
141
    char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
142
    snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
143
    mode_t process_mask = umask(0); /* check if file exists */
144
    int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
145
    if( result == 0 || errno == EEXIST ){
146
     umask(process_mask); /* be sure to set correct permission */
7956 schaersvoo 147
     char *w_session = getenv("w_session");
7614 schaersvoo 148
     int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
149
    char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
7956 schaersvoo 150
     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 */   
7614 schaersvoo 151
    /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
152
    /* now write file into getfile dir*/
153
    char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
154
    int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
155
    char *location = my_newmem(L2); /* create memory to fit string precisely */
156
    snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
157
    js_include_file = fopen(location,"w");/* open the file location for writing */
158
    /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
159
    if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
160
 
161
/* ----------------------------------------------------- */
162
/* while more lines to process */
163
 
164
    while(!finished){
7983 schaersvoo 165
        if(line_number>1 && found_size_command == 0){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
7614 schaersvoo 166
        type = get_token(infile);
167
        done = FALSE;
168
        /*
169
        @canvasdraw
7956 schaersvoo 170
        @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...)
8083 schaersvoo 171
        @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><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();
172
        The replyformat is : object_number : x-orig : y-orig : x-drag : y-drag<br />The x-orig/y-orig will be returned in maximium precision...the x-drag/y-drag will be returned in defined 'precision' number of decimals<br />Multiple objects may be set draggable / clickable (no limit)<br /> not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on 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><li><b>remarks using a ';' as command separator</b><br />commands with only numeric or colour arguments may be using a ';' as command separator (in stead of a new line)<br />commands with a string argument may not use a ';' as command separator !<br />these exceptions are not really straight forward... so keep this in mind.<br />example:<br />size 200,200;xrange -5,5;yrange -5,5;hline 0,0,black;vline 0,0,black<br />plot red,sin(x)<br />drag xy<br />html 0,0,5,-5, &amp;euro; <br />lines green,2,0,2,-2,-2,2,-2,0;rectangle 1,1,4,4,purple;frectangle -1,-1,-4,-4,yellow</li></ul>
7614 schaersvoo 173
        */
174
        switch(type){
175
        case END:
176
        finished = 1;
177
        done = TRUE;
178
        break;
179
        case 0:
180
            sync_input(infile);
181
            break;
182
        case COMMENT:
183
            sync_input(infile);
184
            break;
185
        case EMPTY:
186
            sync_input(infile);
187
            break;
188
        case SIZE:
189
            /*
190
            @size width,height
191
            @set canvas size in pixels
192
            @mandatory first command
7906 schaersvoo 193
            @if xrange and/or yrange is not given the range will be set to pixels :<br />xrange 0,xsize yrange 0,ysize<br />note: lower left  corner is Origin (0:0) !!! this in contrast to flydraw
7614 schaersvoo 194
            */
7983 schaersvoo 195
            found_size_command = 1;
7614 schaersvoo 196
            xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
197
            ysize = (int)(abs(round(get_real(infile,1))));
198
            /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
199
            xmin = 0;xmax = xsize;
7647 schaersvoo 200
            ymin = 0;ymax = ysize;
7614 schaersvoo 201
 
7956 schaersvoo 202
/*
7614 schaersvoo 203
 The sequence in which stuff is finally printed is important !!
204
 for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc
205
*/
7997 schaersvoo 206
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;margin-left:auto;margin-right:auto;\" ></div><div id=\"tooltip_placeholder_div%d\" style=\"display:block;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id);
7614 schaersvoo 207
fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n");
208
fprintf(stdout,"<!-- include actual object code via include file -->\n<script type=\"text/javascript\" src=\"%s\"></script>\n",getfile_cmd);
7729 schaersvoo 209
fprintf(js_include_file,"var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
210
var xsize = %d;\
211
var ysize = %d;\
7797 schaersvoo 212
var precision = 100;\
7729 schaersvoo 213
var canvas_div = document.getElementById(\"canvas_div%d\");\
214
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;};\
215
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;};\
7990 schaersvoo 216
function x2px(x){if(use_xlogscale == 0 ){return parseFloat(x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin));}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_in = Math.log(x)/Math.log(xlogbase);return x_in*xsize/(x_max - x_min) - xsize*x_min/(x_max - x_min);};};\
217
function px2x(px){if(use_xlogscale == 0 ){return parseFloat(px*(xmax - xmin)/xsize + xmin);}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_out = x_min +px*(x_max - x_min)/(xsize);return Math.pow(xlogbase,x_out);};};\
218
function px2y(py){if(use_ylogscale == 0 ){return parseFloat(ymax - py*(ymax - ymin)/ysize);}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_out = y_max +py*(y_min - y_max)/(ysize);return Math.pow(ylogbase,y_out);};};\
219
function y2px(y){if(use_ylogscale == 0){return parseFloat(-1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin));}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_in = Math.log(y)/Math.log(ylogbase);return (y_max - y_in)*ysize/(y_max - y_min);};};\
8071 schaersvoo 220
function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
221
function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
7729 schaersvoo 222
function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\
223
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) ));};\
224
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;};\
7881 schaersvoo 225
var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
226
function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
227
function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
7735 schaersvoo 228
var xlogbase = 10;\
229
var ylogbase = 10;\
7729 schaersvoo 230
var use_xlogscale = 0;\
231
var use_ylogscale = 0;\
232
var x_strings = null;\
233
var y_strings = null;\
234
var use_pan_and_zoom = 0;\
7858 schaersvoo 235
var use_jsmath = 0;\
7729 schaersvoo 236
var xstart = 0;\
7996 schaersvoo 237
var ystart = 0;\
238
var unit_x=\" \";\
239
var unit_y=\" \";",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 240
/* default add the drag code : nearly always used ...*/
241
add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
242
            break;
243
        case XRANGE:
244
        /*
245
        @ xrange xmin,xmax
7956 schaersvoo 246
        @ if not given: 0,xsize (eg in pixels)
7614 schaersvoo 247
        */
248
            for(i = 0 ; i<2; i++){
249
                switch(i){
250
                    case 0: xmin = get_real(infile,0);break;
251
                    case 1: xmax = get_real(infile,1);break;
252
                    default: break;
253
                }
254
            }
255
            if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
256
            fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
7983 schaersvoo 257
            found_size_command++;
7614 schaersvoo 258
            break;
259
        case YRANGE:
260
        /*
261
        @ yrange ymin,ymax
262
        @ if not given 0,ysize (eg in pixels)
263
        */
264
            for(i = 0 ; i<2; i++){
265
                switch(i){
266
                    case 0: ymin = get_real(infile,0);break;
267
                    case 1: ymax = get_real(infile,1);break;
268
                    default: break;
269
                }
270
            }
271
            if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
272
            fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
7983 schaersvoo 273
            found_size_command++;
7614 schaersvoo 274
            break;
275
        case TRANGE:
276
        /*
277
        @ trange tmin,tmax
278
        @ default -2,2
279
        */
280
            use_parametric = TRUE;
281
            for(i = 0 ; i<2; i++){
282
                switch(i){
283
                    case 0: tmin = get_real(infile,0);break;
284
                    case 1: tmax = get_real(infile,1);break;
285
                    default: break;
286
                }
287
            }
288
            if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
289
            break;
290
        case LINEWIDTH:
291
        /*
292
        @ linewidth int
293
        @ default 1
294
        */
295
            line_width = (int) (get_real(infile,1));
296
            break;
297
        case ARROWHEAD:
298
        /*
299
        @ arrowhead int
300
        @ default 8 (pixels)
301
        */
302
            arrow_head = (int) (get_real(infile,1));
303
            break;
304
        case CROSSHAIRSIZE:
305
        /*
306
        @ crosshairsize int
307
        @ default 10 (px)
308
        */
309
            crosshair_size = (int) (get_real(infile,1));
310
            break;
311
        case CROSSHAIR:
312
        /*
313
        @ crosshair x,y,color
314
        @ draw a single crosshair point at (x;y) in color 'color'
7956 schaersvoo 315
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
7614 schaersvoo 316
        @ may be set draggable / onclick
317
        */
318
            for(i=0;i<3;i++){
319
                switch(i){
320
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
321
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
322
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
323
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 324
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 325
                        click_cnt++;reset();
326
                        break;
327
                    default:break;
328
                }
329
            }
330
            break;
331
        case CROSSHAIRS:
332
        /*
333
        @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
334
        @ draw multiple crosshair points at given coordinates in color 'color'
7956 schaersvoo 335
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
7614 schaersvoo 336
        @ may be set draggable / onclick individually (!)
337
        */
338
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
339
            fill_color = stroke_color;
340
            i=0;
341
            while( ! done ){     /* get next item until EOL*/
342
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
343
                if(i%2 == 0 ){
344
                    double_data[i] = get_real(infile,0); /* x */
345
                }
346
                else
347
                {
348
                    double_data[i] = get_real(infile,1); /* y */
349
                }
350
                i++;
351
            }
352
            decimals = find_number_of_digits(precision);
353
            for(c=0 ; c < i-1 ; c = c+2){
8097 schaersvoo 354
                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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 355
                click_cnt++;
356
            }
357
            reset();
358
            break;
359
        case POINT:
360
        /*
361
        @ point x,y,color
362
        @ draw a single point at (x;y) in color 'color'
7956 schaersvoo 363
        @ use command 'linewidth int'  to adust size
7614 schaersvoo 364
        @ may be set draggable / onclick
7956 schaersvoo 365
        @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
7614 schaersvoo 366
        */
367
            for(i=0;i<3;i++){
368
                switch(i){
369
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
370
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
371
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
372
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 373
                    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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 374
                    click_cnt++;break;
375
                    default: break;
376
                }
377
            }
378
            reset();
379
            break;
380
        case POINTS:
381
        /*
7634 schaersvoo 382
        @ points color,x1,y1,x2,y2,...,x_n,y_n
7614 schaersvoo 383
        @ draw multiple points at given coordinates in color 'color'
7956 schaersvoo 384
        @ use command 'linewidth int'  to adust size
7614 schaersvoo 385
        @ may be set draggable / onclick individually (!)
386
        */
387
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
388
            fill_color = stroke_color;
389
            i=0;
390
            while( ! done ){     /* get next item until EOL*/
391
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
392
                if(i%2 == 0 ){
393
                    double_data[i] = get_real(infile,0); /* x */
394
                }
395
                else
396
                {
397
                    double_data[i] = get_real(infile,1); /* y */
398
                }
399
                i++;
400
            }
7956 schaersvoo 401
            decimals = find_number_of_digits(precision);           
7614 schaersvoo 402
            for(c = 0 ; c < i-1 ; c = c+2){
8097 schaersvoo 403
                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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 404
                click_cnt++;
405
            }
406
            reset();
407
            break;
408
        case SEGMENT:
409
        /*
410
        @ segment x1,y1,x2,y2,color
411
        @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
412
        @ may be set draggable / onclick
413
        */
414
            for(i=0;i<5;i++) {
415
                switch(i){
416
                    case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
417
                    case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
418
                    case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
419
                    case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
420
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
421
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 422
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 423
                        click_cnt++;reset();
424
                        break;
425
                    default: break;
426
                }
427
            }
428
            break;
429
        case LINE:
430
        /*
431
        @ line x1,y1,x2,y2,color
432
        @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
433
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
434
        @ may be set draggable / onclick
435
        */
436
            for(i=0;i<5;i++){
437
                switch(i){
438
                    case 0: double_data[10]= get_real(infile,0);break; /* x-values */
439
                    case 1: double_data[11]= get_real(infile,0);break; /* y-values */
440
                    case 2: double_data[12]= get_real(infile,0);break; /* x-values */
441
                    case 3: double_data[13]= get_real(infile,0);break; /* y-values */
442
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
443
                    if( double_data[10] == double_data[12] ){ /* vertical line*/
444
                        double_data[1] = xmin;
445
                        double_data[3] = ymax;
446
                        double_data[0] = double_data[10];
447
                        double_data[2] = double_data[10];
448
                    }
449
                    else
450
                    {
451
                        if( double_data[11] == double_data[13] ){ /* horizontal line */
452
                            double_data[1] = double_data[11];
453
                            double_data[3] = double_data[11];
454
                            double_data[0] = ymin;
455
                            double_data[2] = xmax;
456
                        }
457
                        else
458
                        {
459
                        /* m */
460
                        double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
461
                        /* q */
462
                        double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
7956 schaersvoo 463
 
7614 schaersvoo 464
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
7956 schaersvoo 465
 
7614 schaersvoo 466
                            double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
467
                            double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
468
                            double_data[0] = xmin;
469
                            double_data[2] = xmax;
470
                        }
471
                    }
472
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 474
                    click_cnt++;reset();
475
                    break;
476
                }
477
            }
478
            break;
7956 schaersvoo 479
        case HLINE:
7614 schaersvoo 480
        /*
481
        @ hline x,y,color
482
        @ draw a horizontal line through point (x:y) in color 'color'
483
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
484
        @ may be set draggable / onclick
485
        */
486
            for(i=0;i<3;i++) {
487
                switch(i){
488
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
489
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
490
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
491
                    double_data[3] = double_data[1];
492
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 493
                    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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 494
                    click_cnt++;reset();
495
                    break;
496
                }
497
            }
498
            break;
499
        case VLINE:
500
        /*
501
        @ vline x,y,color
502
        @ draw a vertical line through point (x:y) in color 'color'
503
        @ may be set draggable / onclick
504
        */
505
            for(i=0;i<3;i++) {
506
                switch(i){
507
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
508
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
509
                    case 2: stroke_color=get_color(infile,1);/* name or hex color */
510
                        double_data[2] = double_data[0];
511
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 512
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 513
                        click_cnt++;reset();
514
                    break;
515
                }
516
            }
517
            break;
518
        case SQUARE:
519
        /*
8071 schaersvoo 520
        @ square x,y,side (px) ,color
7614 schaersvoo 521
        @ draw a square with left top corner (x:y) with side 'side' in color 'color'
522
        @ use command 'fsquare x,y,side,color' for a filled square
523
        @ use command/keyword  'filled' before command 'square x,y,side,color'
524
        @ use command 'fillcolor color' before 'fsquare' to set the fill colour.
525
        @ may be set draggable / onclick
526
        */
527
            for(i=0;i<5;i++){
528
                switch(i){
8071 schaersvoo 529
                    case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
530
                    case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
531
                    case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */
532
                    case 3:
533
                        stroke_color = get_color(infile,1);/* name or hex color */
7614 schaersvoo 534
                        decimals = find_number_of_digits(precision);
8071 schaersvoo 535
                        double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
536
                        double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
8097 schaersvoo 537
                        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\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[3],decimals,double_data[3],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[4],decimals,double_data[4],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 538
                        click_cnt++;reset();
539
                        break;
540
                }
541
            }
542
            break;
543
        case ROUNDRECT:
544
        /*
545
        @ roundrect x1,y1,x2,y2,radius,color
546
        @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
547
        @ use command/keyword  'filled' before command 'roundrect x1,y1,x2,y2,radius,color'
548
        @ use command 'fillcolor color' before 'froundrect' to set the fill colour.
549
        @ may be set draggable / onclick
550
        */
551
            for(i=0;i<6;i++){
552
                switch(i){
553
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
554
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
555
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
556
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
557
                    case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
558
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
8071 schaersvoo 559
                        /* ensure no inverted roundrect is produced... */
560
                        if( double_data[0] > double_data[2] ){double_data[4] = double_data[0];double_data[0] = double_data[2];double_data[2] = double_data[4];}
561
                        if( double_data[3] > double_data[1] ){double_data[4] = double_data[1];double_data[1] = double_data[3];double_data[3] = double_data[4];}
7614 schaersvoo 562
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 563
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 564
                        click_cnt++;reset();
565
                    break;
566
                }
567
            }
568
            break;
569
        case RECT:
570
        /*
571
        @ rect x1,y1,x2,y2,color
572
        @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle
573
        @ use command/keyword  'filled' before command 'rect x1,y1,x2,y2,color'
574
        @ use command 'fillcolor color' before 'frect' to set the fill colour.
575
        @ may be set draggable / onclick
576
        */
577
            for(i=0;i<5;i++){
578
                switch(i){
579
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
580
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
581
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
582
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
583
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
584
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 585
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 586
                        click_cnt++;reset();
587
                        break;
588
                }
589
            }
590
            break;
591
        case POLYLINE:
592
        /*
593
        @ polyline color,x1,y1,x2,y2...x_n,y_n
594
        @ may be set draggable / onclick
595
        */
596
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
597
            i=0;
598
            c=0;
599
            while( ! done ){     /* get next item until EOL*/
600
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
601
                for( c = 0 ; c < 2; c++){
602
                    if(c == 0 ){
603
                        double_data[i] = get_real(infile,0);
604
                        i++;
605
                    }
606
                    else
607
                    {
608
                        double_data[i] = get_real(infile,1);
609
                        i++;
610
                    }
611
                }
612
            }
613
            /* draw path : not closed & not filled */
614
            decimals = find_number_of_digits(precision);
8097 schaersvoo 615
            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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 616
            click_cnt++;reset();
617
            break;
618
        case POLY:
619
        /*
620
        @ poly color,x1,y1,x2,y2...x_n,y_n
621
        @ draw closed polygon
622
        @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color
623
        @ may be set draggable / onclick
624
        */
625
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
626
            i=0;
627
            c=0;
628
            while( ! done ){     /* get next item until EOL*/
629
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
630
                for( c = 0 ; c < 2; c++){
631
                    if(c == 0 ){
632
                        double_data[i] = get_real(infile,0);
633
                        i++;
634
                    }
635
                    else
636
                    {
637
                        double_data[i] = get_real(infile,1);
638
                        i++;
639
                    }
640
                }
641
            }
642
            /* draw path :  closed & optional filled */
643
                decimals = find_number_of_digits(precision);
8097 schaersvoo 644
                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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 645
                click_cnt++;reset();
646
            break;
7956 schaersvoo 647
        case ARC:
7614 schaersvoo 648
        /*
649
         @ arc xc,yc,width,height,start_angle,end_angle,color
650
         @ can not be set "onclick" or "drag xy"
651
         @ attention: width == height == radius in pixels)
652
        */
653
            for(i=0;i<7;i++){
654
                switch(i){
655
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
656
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
657
                    case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */
658
                    case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */
659
                    case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */
660
                    case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */
661
                    case 6:stroke_color = get_color(infile,1);/* name or hex color */
662
                    /* in Shape library:
663
                        x[0] = x[1] = xc
664
                        y[0] = y[1] = yc
7956 schaersvoo 665
                        w[0] = w[1] = radius = width = height  
666
                        h[0] = start_angle ; h[1] = end_engle
7614 schaersvoo 667
                    */
668
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 669
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 670
                        reset();
671
                    break;
672
                }
673
            }
674
            break;
675
        case ELLIPSE:
676
        /*
677
        @ ellipse xc,yc,radius_x,radius_y,color
7956 schaersvoo 678
        @ a ellipse with center xc/yc in x/y-range
7614 schaersvoo 679
        @ radius_x and radius_y are in pixels
680
        @ may be set draggable / onclick
7956 schaersvoo 681
        @ will shrink / expand on zoom out / zoom in
7614 schaersvoo 682
        */
683
            for(i=0;i<5;i++){
684
                switch(i){
685
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
686
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
687
                    case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
7956 schaersvoo 688
                    case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
7614 schaersvoo 689
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
690
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 691
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 692
                        click_cnt++;reset();
693
                    break;
694
                }
695
            }
696
            break;
697
        case DASHTYPE:
698
        /*
699
        @ dashtype int ,int
7956 schaersvoo 700
        @ When dashed is set, the objects will be drawn with this dashtyp
7614 schaersvoo 701
        @ default value "dashtype 2,2"
702
        */
703
            for(i=0;i<2;i++){
704
                switch(i){
705
                    case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
706
                    case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
707
                }
708
            }
709
        break;
710
        case CIRCLE:
711
        /*
712
        @ circle xc,yc,width (2*r in pixels),color
713
        @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk
714
        @ use command 'fillcolor color' to set the fillcolor
715
        @ may be set draggable / onclick
7956 schaersvoo 716
        @ will shrink / expand on zoom out / zoom in
7614 schaersvoo 717
        */
718
            for(i=0;i<4;i++){
719
                switch(i){
720
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
721
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
722
                    case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* radius in 'dx' xrange*/
723
                    case 3: stroke_color = get_color(infile,1);/* name or hex color */
724
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 725
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 726
                        click_cnt++;reset();
727
                    break;
728
                }
729
            }
730
            break;
731
        case RAYS:
732
        /*
733
         @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
734
         @ draw rays in color 'color' and center (xc:yc)
7786 schaersvoo 735
         @ may be set draggable or onclick (every individual ray)
7614 schaersvoo 736
        */
737
            stroke_color=get_color(infile,0);
7786 schaersvoo 738
            fill_color = stroke_color;
739
            double_data[0] = get_real(infile,0);/* xc */
740
            double_data[1] = get_real(infile,0);/* yc */
741
            i=2;
742
            while( ! done ){     /* get next item until EOL*/
743
                if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");}
744
                if(i%2 == 0 ){
745
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 746
                }
7786 schaersvoo 747
                else
748
                {
749
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 750
                }
7786 schaersvoo 751
            fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
752
                i++;
7614 schaersvoo 753
            }
7956 schaersvoo 754
 
755
            if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
756
            decimals = find_number_of_digits(precision);           
7786 schaersvoo 757
            for(c=2; c<i;c = c+2){
7614 schaersvoo 758
                click_cnt++;
8097 schaersvoo 759
                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\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 760
            }
761
            reset();
762
            break;
763
        case ARROW:
764
        /*
765
        @ arrow x1,y1,x2,y2,h,color
766
        @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
767
        @ use command 'linewidth int' to adjust thickness of the arrow
768
        @ may be set draggable / onclick
769
        */
770
            for(i=0;i<6;i++){
771
                switch(i){
772
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
773
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
774
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
775
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
776
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
777
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
778
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 779
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 780
                        click_cnt++;
781
                        reset();
782
                        break;
783
                }
784
            }
785
            break;
786
        case ARROW2:
787
        /*
788
        @ arrow2 x1,y1,x2,y2,h,color
789
        @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
790
        @ use command 'arrowhead int' to adjust the arrow head size
791
        @ use command 'linewidth int' to adjust thickness of the arrow
792
        @ may be set draggable / onclick
793
        */
794
            for(i=0;i<6;i++){
795
                switch(i){
796
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
797
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
798
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
799
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
800
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
801
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
802
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 803
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 804
                        click_cnt++;reset();
805
                        break;
806
                }
807
            }
808
            break;
7956 schaersvoo 809
        case PARALLEL:
7614 schaersvoo 810
        /*
811
         @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
7956 schaersvoo 812
         @ can not be set "onclick" or "drag xy"
7614 schaersvoo 813
        */
814
            for( i = 0;i < 8; i++ ){
815
                switch(i){
816
                    case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
817
                    case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
818
                    case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
819
                    case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
820
                    case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
821
                    case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
822
                    case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
823
                    case 7: stroke_color=get_color(infile,1);/* name or hex color */
824
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 825
                    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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 826
                    click_cnt++;reset();
827
                    break;
828
                    default: break;
829
                }
830
            }
831
            break;
832
        case TRIANGLE:
833
        /*
834
         @triangle x1,y1,x2,y2,x3,y3,color
7956 schaersvoo 835
         @may be set draggable / onclic
7614 schaersvoo 836
        */
837
            for(i=0;i<7;i++){
838
                switch(i){
839
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
840
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
841
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
842
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
843
                    case 4: double_data[4] = get_real(infile,0);break; /* x */
844
                    case 5: double_data[5] = get_real(infile,0);break; /* y */
845
                    case 6: stroke_color = get_color(infile,1);/* name or hex color */
846
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 847
                        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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 848
                        click_cnt++;reset();
849
                        break;
850
                    default: break;
851
                }
852
            }
853
            break;
854
        case LATTICE:
855
        /*
856
         @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
7956 schaersvoo 857
         @can not be set "onclick" or "drag xy"
7614 schaersvoo 858
        */
859
            if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
860
            for( i = 0; i<9; i++){
861
                switch(i){
862
                    case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
863
                    case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
864
                    case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
8071 schaersvoo 865
                    case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
7614 schaersvoo 866
                    case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
8071 schaersvoo 867
                    case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
7614 schaersvoo 868
                    case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
869
                    case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
870
                    case 8: stroke_color=get_color(infile,1);
871
                        decimals = find_number_of_digits(precision);
8071 schaersvoo 872
                        string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 873
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 874
                        snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 875
                        add_to_buffer(tmp_buffer);
876
                    break;
877
                    default:break;
878
                }
879
            }
880
            reset();
881
            break;
882
        case SNAPTOGRID:
883
        /*
884
         @ snaptogrid
885
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
886
         @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
7784 schaersvoo 887
         @ if xminor / yminor is defined, the drawing will snap to xminor and yminor<br />use only even dividers in x/y-minor...for example<br />snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
7614 schaersvoo 888
        */
7881 schaersvoo 889
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
7614 schaersvoo 890
        break;
7784 schaersvoo 891
        case XSNAPTOGRID:
892
        /*
893
         @ xsnaptogrid
894
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
895
         @ in case of userdraw the drawn points will snap to xmajor grid
7856 schaersvoo 896
         @ if xminor is defined, the drawing will snap to xminor <br />use only even dividers in x-minor...for example<br />xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
7784 schaersvoo 897
        */
7881 schaersvoo 898
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
7784 schaersvoo 899
        break;
900
        case YSNAPTOGRID:
901
        /*
902
         @ ysnaptogrid
903
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
904
         @ in case of userdraw the drawn points will snap to ymajor grid
7856 schaersvoo 905
         @ if yminor is defined, the drawing will snap to yminor <br />use only even dividers in y-minor...for example<br />ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
7784 schaersvoo 906
        */
7881 schaersvoo 907
        fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
7784 schaersvoo 908
        break;
7663 schaersvoo 909
        case USERTEXTAREA_XY:
910
        /*
911
        @ usertextarea_xy
7956 schaersvoo 912
        @ keyword
7663 schaersvoo 913
        @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
7956 schaersvoo 914
        @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
7663 schaersvoo 915
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
7956 schaersvoo 916
        @ user drawings will not zoom on zooming (or pan on panning)
7663 schaersvoo 917
        */
7856 schaersvoo 918
            if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
7956 schaersvoo 919
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7749 schaersvoo 920
            use_input_xy = 2;
921
            break;
7652 schaersvoo 922
        case USERINPUT_XY:
923
        /*
924
        @ userinput_xy
7956 schaersvoo 925
        @ keyword
7652 schaersvoo 926
        @ to be used in combination with command "userdraw object_type,color"
7956 schaersvoo 927
        @ if set two (or three) input fields are added to the document<br />(one for x-values , one for y-values and in case of drawing circle one for radius-values)
7652 schaersvoo 928
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
7749 schaersvoo 929
        @ math input is allowed (e.g something like: 1+3,2*6,1/3,sqrt(3), sin(pi/4),10^-2,log(2)...)<br />eval function is 'protected' against code injection.
7652 schaersvoo 930
        @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
7956 schaersvoo 931
        @ user drawings will not zoom on zooming (or pan on panning)
7652 schaersvoo 932
        */
7749 schaersvoo 933
            /* add simple eval check to avoid code injection with unprotected eval(string) */
7856 schaersvoo 934
            if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
7956 schaersvoo 935
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7749 schaersvoo 936
            use_input_xy = 1;
937
            break;
7614 schaersvoo 938
        case USERDRAW:
939
        /*
940
        @ userdraw object_type,color
8083 schaersvoo 941
        @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>vline</li><li>vlines</li><li>hline</li><li>hlines</li><li>segment</li><li>segments</li><li>polyline</li><li>circle</li><li>circles</li><li>arrow</li><li>arrow2 (double arrow)</li><li>arrows</li><li>arrows2 (double 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><li>arc</li><li>arcs</li></ul>
7614 schaersvoo 942
        @ 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)
7956 schaersvoo 943
        @ 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
944
        @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
7614 schaersvoo 945
        @ 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)
946
        @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
7956 schaersvoo 947
        @ use command "dashed" and/or "dashtype int,int" to trigger dashing
7614 schaersvoo 948
        @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
949
        @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
7956 schaersvoo 950
        @ may be combined with keyword 'userinput_xy' or
7653 schaersvoo 951
        @ note: when zooming / panning after a drawing, the drawing will NOT be zoomed / panned...this is a "design" flaw and not a feature <br />To avoid trouble do not use zooming / panning together width userdraw.!
7614 schaersvoo 952
        */
953
            if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
954
                canvas_error("Only one userdraw primitive may be used: read documentation !!");
955
            }
8074 schaersvoo 956
            reply_precision = precision;
7614 schaersvoo 957
            use_userdraw = TRUE;
7856 schaersvoo 958
            fprintf(js_include_file,"\n<!-- 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 -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
7614 schaersvoo 959
            draw_type = get_string_argument(infile,0);
960
            stroke_color = get_color(infile,1);
961
            if( strcmp(draw_type,"point") == 0 ){
962
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 963
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 964
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 965
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7956 schaersvoo 966
                if(use_input_xy == 1){
7652 schaersvoo 967
                    add_input_circle(js_include_file,1,1);
968
                    add_input_xy(js_include_file,canvas_root_id);
969
                }
7614 schaersvoo 970
                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);
971
            }
972
            else
973
            if( strcmp(draw_type,"points") == 0 ){
974
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 975
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 976
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 977
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7956 schaersvoo 978
                if(use_input_xy == 1){
7652 schaersvoo 979
                    add_input_circle(js_include_file,1,2);
980
                    add_input_xy(js_include_file,canvas_root_id);
981
                }
7614 schaersvoo 982
                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);
983
            }
984
            else
985
            if( strcmp(draw_type,"segment") == 0 ){
986
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
987
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 988
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 989
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7956 schaersvoo 990
                if(use_input_xy == 1){
7652 schaersvoo 991
                    add_input_segment(js_include_file,1);
992
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
993
                }
7614 schaersvoo 994
                add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
995
            }
996
            else
7663 schaersvoo 997
            if( strcmp(draw_type,"polyline") == 0 ){
998
                if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
7876 schaersvoo 999
                if(reply_format == 0){reply_format = 23;}
8071 schaersvoo 1000
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7780 schaersvoo 1001
                if( use_input_xy == 1 ){
1002
                    add_input_polyline(js_include_file);
1003
                    add_input_xy(js_include_file,canvas_root_id);
7663 schaersvoo 1004
                }
1005
                add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1006
            }
1007
            else
7614 schaersvoo 1008
            if( strcmp(draw_type,"segments") == 0 ){
1009
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1010
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 1011
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 1012
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7956 schaersvoo 1013
                if(use_input_xy == 1){
7652 schaersvoo 1014
                    add_input_segment(js_include_file,2);
1015
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1016
                }
7614 schaersvoo 1017
                add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1018
            }
1019
            else
1020
            if( strcmp(draw_type,"circle") == 0 ){
1021
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1022
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 1023
                /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
8071 schaersvoo 1024
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7956 schaersvoo 1025
                if(use_input_xy == 1){
7652 schaersvoo 1026
                    add_input_circle(js_include_file,2,1);
1027
                    add_input_xyr(js_include_file,canvas_root_id);
1028
                }
7614 schaersvoo 1029
                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]);
1030
            }
1031
            else
1032
            if( strcmp(draw_type,"circles") == 0 ){
1033
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1034
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 1035
                /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
1036
                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]);
8071 schaersvoo 1037
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7956 schaersvoo 1038
                if(use_input_xy == 1){
7652 schaersvoo 1039
                    add_input_circle(js_include_file,2,2);
1040
                    add_input_xyr(js_include_file,canvas_root_id);
1041
                }
7614 schaersvoo 1042
            }
1043
            else
1044
            if(strcmp(draw_type,"crosshair") == 0 ){
1045
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 1046
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 1047
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
1048
                add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 1049
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7956 schaersvoo 1050
                if(use_input_xy == 1){
7654 schaersvoo 1051
                    add_input_crosshair(js_include_file,1);
1052
                    add_input_xy(js_include_file,canvas_root_id);
1053
                }
7614 schaersvoo 1054
            }
1055
            else
1056
            if(strcmp(draw_type,"crosshairs") == 0 ){
1057
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 1058
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 1059
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
1060
                add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 1061
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7956 schaersvoo 1062
                if(use_input_xy == 1){
7654 schaersvoo 1063
                    add_input_crosshair(js_include_file,2);
1064
                    add_input_xy(js_include_file,canvas_root_id);
1065
                }
7614 schaersvoo 1066
            }
1067
            else
1068
            if(strcmp(draw_type,"freehandline") == 0 ){
1069
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1070
                if(reply_format == 0){reply_format = 6;}
7956 schaersvoo 1071
                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]);  
7652 schaersvoo 1072
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1073
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1074
            }
1075
            else
1076
            if(strcmp(draw_type,"freehandlines") == 0 ){
1077
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1078
                if(reply_format == 0){reply_format = 6;}
7956 schaersvoo 1079
                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]);  
7652 schaersvoo 1080
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1081
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1082
            }
1083
            else
1084
            if(strcmp(draw_type,"path") == 0 ){
1085
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1086
                if(reply_format == 0){reply_format = 6;}
7956 schaersvoo 1087
                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]);  
7652 schaersvoo 1088
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1089
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1090
            }
1091
            else
1092
            if(strcmp(draw_type,"paths") == 0 ){
1093
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1094
                if(reply_format == 0){reply_format = 6;}
7956 schaersvoo 1095
                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]);  
7652 schaersvoo 1096
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1097
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1098
            }
1099
            else
1100
            if(strcmp(draw_type,"arrows") == 0 ){
1101
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1102
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1103
                add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
7956 schaersvoo 1104
                if(use_input_xy == 1){
7654 schaersvoo 1105
                    add_input_arrow(js_include_file,2);
1106
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1107
                }
8071 schaersvoo 1108
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1109
            }
1110
            else
7874 schaersvoo 1111
            if(strcmp(draw_type,"arrows2") == 0 ){
1112
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1113
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1114
                add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
7956 schaersvoo 1115
                if(use_input_xy == 1){
7874 schaersvoo 1116
                    add_input_arrow(js_include_file,1);
1117
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1118
                }
8071 schaersvoo 1119
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 1120
            }
1121
            else
1122
            if(strcmp(draw_type,"arrow2") == 0 ){
1123
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1124
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1125
                add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
7956 schaersvoo 1126
                if(use_input_xy == 1){
7874 schaersvoo 1127
                    add_input_arrow(js_include_file,1);
1128
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1129
                }
8071 schaersvoo 1130
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 1131
            }
1132
            else
7614 schaersvoo 1133
            if(strcmp(draw_type,"arrow") == 0 ){
1134
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1135
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1136
                add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
7956 schaersvoo 1137
                if(use_input_xy == 1){
7654 schaersvoo 1138
                    add_input_arrow(js_include_file,1);
1139
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1140
                }
8071 schaersvoo 1141
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1142
            }
1143
            else
1144
            if(strcmp(draw_type,"polygon") == 0){
1145
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1146
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1147
                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]);
8071 schaersvoo 1148
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1149
                if(use_input_xy == 2){
7780 schaersvoo 1150
                  add_textarea_polygon(js_include_file);
1151
                  add_textarea_xy(js_include_file,canvas_root_id);
7746 schaersvoo 1152
                }
7614 schaersvoo 1153
            }
7956 schaersvoo 1154
            else
7614 schaersvoo 1155
            if(strncmp(draw_type,"poly",4) == 0){
1156
                if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
1157
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1158
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1159
                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]);
7652 schaersvoo 1160
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1161
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1162
            }
7956 schaersvoo 1163
            else
7614 schaersvoo 1164
            if(strcmp(draw_type,"triangle") == 0){
1165
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1166
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1167
                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]);
7652 schaersvoo 1168
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1169
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1170
            }
7956 schaersvoo 1171
            else
7989 schaersvoo 1172
            if( strcmp(draw_type,"hline") == 0 ){
1173
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1174
                if(reply_format == 0){reply_format = 11;}
1175
                add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1176
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1177
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1178
            }
1179
            else
1180
            if( strcmp(draw_type,"hlines") == 0 ){
1181
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1182
                if(reply_format == 0){reply_format = 11;}
1183
                add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1184
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1185
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1186
            }
1187
            else
1188
            if( strcmp(draw_type,"vline") == 0 ){
1189
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1190
                if(reply_format == 0){reply_format = 11;}
1191
                add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1192
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1193
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1194
            }
1195
            else
1196
            if( strcmp(draw_type,"vlines") == 0 ){
1197
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1198
                if(reply_format == 0){reply_format = 11;}
1199
                add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1200
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1201
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1202
            }
1203
            else
7614 schaersvoo 1204
            if( strcmp(draw_type,"line") == 0 ){
1205
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1206
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 1207
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 1208
                add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 1209
                if( use_input_xy == 1 ){
7780 schaersvoo 1210
                    add_input_line(js_include_file,1);
7747 schaersvoo 1211
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1212
                }
8071 schaersvoo 1213
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1214
            }
1215
            else
1216
            if( strcmp(draw_type,"lines") == 0 ){
1217
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1218
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 1219
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 1220
                add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 1221
                if( use_input_xy == 1 ){
7780 schaersvoo 1222
                    add_input_line(js_include_file,2);
7747 schaersvoo 1223
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
7746 schaersvoo 1224
                }
8071 schaersvoo 1225
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1226
            }
1227
            else
1228
            if( strcmp(draw_type,"rects") == 0){
1229
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 1230
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1231
                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]);
7652 schaersvoo 1232
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1233
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1234
            }
7956 schaersvoo 1235
            else
7614 schaersvoo 1236
            if( strcmp(draw_type,"roundrects") == 0){
1237
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 1238
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1239
                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]);
7652 schaersvoo 1240
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1241
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1242
            }
7956 schaersvoo 1243
            else
7614 schaersvoo 1244
            if( strcmp(draw_type,"rect") == 0){
1245
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 1246
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1247
                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]);
7652 schaersvoo 1248
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1249
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1250
            }
7956 schaersvoo 1251
            else
7614 schaersvoo 1252
            if( strcmp(draw_type,"roundrect") == 0){
1253
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 1254
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1255
                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]);
7652 schaersvoo 1256
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1257
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1258
            }
1259
            else
8083 schaersvoo 1260
            if( strcmp(draw_type,"arcs") == 0){
1261
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
1262
                if(reply_format == 0){reply_format = 25;}
1263
                add_js_arc(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
1264
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1265
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1266
            }
1267
            else
8071 schaersvoo 1268
            if( strcmp(draw_type,"arc") == 0){
1269
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
8083 schaersvoo 1270
                if(reply_format == 0){reply_format = 25;}
1271
                add_js_arc(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1272
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1273
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1274
            }
1275
            else
7614 schaersvoo 1276
            if( strcmp(draw_type,"text") == 0){
7956 schaersvoo 1277
                if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}      
7876 schaersvoo 1278
                if(reply_format == 0){reply_format = 17;}
8071 schaersvoo 1279
                add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity);
7652 schaersvoo 1280
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1281
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1282
            }
7956 schaersvoo 1283
            else
7614 schaersvoo 1284
            {
1285
                canvas_error("unknown drawtype or typo? ");
1286
            }
1287
            reset();
1288
        break;
1289
        case PLOTSTEPS:
1290
            /*
1291
             @ plotsteps a_number
1292
             @ default 150
1293
             @ use with care !
1294
            */
1295
            plot_steps = (int) (get_real(infile,1));
1296
            break;
1297
        case FONTSIZE:
1298
        /*
1299
         @fontsize font_size
1300
         @default value 12
1301
        */
1302
            font_size = (int) (get_real(infile,1));
1303
            break;
1304
        case FONTCOLOR:
1305
        /*
1306
         @fontcolor color
1307
         @color: hexcolor or colorname
1308
         @default: black
1309
         @example usage: x/y-axis text
1310
        */
1311
            font_color = get_color(infile,1);
1312
            break;
1313
        case ANIMATE:
1314
        /*
1315
         @animate type
1316
         @type may be "point" (nothing else , yet...)
1317
         @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
1318
         @will animate a point on the next plot/curve command
1319
         @the curve will not be draw
1320
         @moves repeatedly from xmin to xmax
1321
        */
1322
            if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
1323
            break;
7788 schaersvoo 1324
        case LEVELCURVE:
1325
        /*
1326
        @levelcurve color,expression in x/y,l1,l2,...
7792 schaersvoo 1327
        @draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
1328
        @the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
1329
        @every individual level curve may be set 'onclick / drag xy' <br />e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier
1330
        @note : the arrays for holding the javascript data are limited in size
1331
        @note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...)
7788 schaersvoo 1332
        */
7792 schaersvoo 1333
            fill_color = get_color(infile,0);
7788 schaersvoo 1334
            char *fun1 = get_string_argument(infile,0);
1335
            if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
1336
            i = 0;
1337
            done = FALSE;
1338
            while( !done ){
1339
             double_data[i] = get_real(infile,1);
1340
             i++;
1341
            }
1342
            for(c = 0 ; c < i; c++){
8097 schaersvoo 1343
             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7788 schaersvoo 1344
             click_cnt++;
1345
            }
1346
            reset();
1347
            break;
7858 schaersvoo 1348
        case TRACE_JSCURVE:
7823 schaersvoo 1349
        /*
7858 schaersvoo 1350
         @trace_jscurve some_math_function
7823 schaersvoo 1351
         @will use a crosshair to trace the jsmath curve
7856 schaersvoo 1352
         @two inputfields will display the current x/y-values (numerical evaluation by javascript)
7956 schaersvoo 1353
         @default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields  
7823 schaersvoo 1354
         @use linewidth,strokecolor,crosshairsize to adjust the corsshair.
7858 schaersvoo 1355
         @the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x in stead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors...
7823 schaersvoo 1356
        */
1357
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7833 schaersvoo 1358
            if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7858 schaersvoo 1359
            if( use_js_math == FALSE){
1360
                add_to_js_math(js_include_file);
1361
                use_js_math = TRUE;
1362
            }
7823 schaersvoo 1363
            add_trace_js_mouse(js_include_file,TRACE_CANVAS,canvas_root_id,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size);
1364
            break;
1365
        case JSMATH:
1366
        /*
7858 schaersvoo 1367
            @jsmath some_math_function
7856 schaersvoo 1368
            @will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
7956 schaersvoo 1369
            @default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields  
7858 schaersvoo 1370
            @example: jsmath sin(x^2)
1371
            @the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x in stead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors...
7823 schaersvoo 1372
        */
1373
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7858 schaersvoo 1374
            if( use_js_math == FALSE){
1375
                add_to_js_math(js_include_file);
1376
                use_js_math = TRUE;
1377
            }
7823 schaersvoo 1378
            add_calc_y(js_include_file,canvas_root_id,get_string(infile,1));
1379
            break;
7858 schaersvoo 1380
        case JSCURVE:
1381
        /*
1382
         @jscurve color,formula(x)
1383
         @your function will be plotted by the javascript engine of the client browser.
7983 schaersvoo 1384
         @use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
7858 schaersvoo 1385
         @use parenthesis and rawmath : use 2*x in stead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors...
7981 schaersvoo 1386
         @Attention : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
7858 schaersvoo 1387
         @no validity check is done by wims.
1388
         @zooming & panning are implemented :<br />use command 'zoom color' for mouse driven zooming<br />or use keyword 'setlimits' for inputfields setting xmin/xmax, ymin/ymax
1389
         @use command 'trace_jscurve formula(x)` for tracing
1390
         @use commmand 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
1391
         @can not be set draggable / onclick (yet)
7956 schaersvoo 1392
         @commands plotjump / plotstep are not active for 'jscurve'
7858 schaersvoo 1393
        */
1394
            stroke_color = get_color(infile,0);
1395
            if( use_js_math == FALSE){/* add this stuff only once...*/
1396
                add_to_js_math(js_include_file);
1397
                use_js_math = TRUE;
1398
            }
1399
            if( use_js_plot == FALSE){
1400
                use_js_plot = TRUE;
1401
                add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1402
            }
1403
            temp = get_string_argument(infile,1);
1404
            string_length = snprintf(NULL,0,  "jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+use_js_plot,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1405
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1406
            snprintf(tmp_buffer,string_length,"jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+use_js_plot,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1407
            add_to_buffer(tmp_buffer);
1408
            use_js_plot++; /* we need to create multiple canvasses, so we may zoom and pan ?? */
1409
 
1410
        break;
7614 schaersvoo 1411
        case CURVE:
1412
        /*
1413
         @curve color,formula(x)
1414
         @plot color,formula(x)
1415
         @use command trange before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
1416
         @use command "precision" to increase the number of digits of the plotted points
1417
         @use command "plotsteps" to increase / decrease the amount of plotted points (default 150)
1418
         @may be set draggable / onclick
1419
        */
1420
            if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
1421
                use_parametric = FALSE;
1422
                stroke_color = get_color(infile,0);
1423
                char *fun1 = get_string_argument(infile,0);
1424
                char *fun2 = get_string_argument(infile,1);
1425
                if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
8097 schaersvoo 1426
                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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 1427
                click_cnt++;
1428
            }
1429
            else
1430
            {
1431
                stroke_color = get_color(infile,0);
1432
                char *fun1 = get_string_argument(infile,1);
7956 schaersvoo 1433
                if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");} 
8097 schaersvoo 1434
                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\",%d,%s,%d,%d));\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,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 1435
                click_cnt++;
1436
            }
7788 schaersvoo 1437
            animation_type = 9;/* reset to curve plotting without animation */
7614 schaersvoo 1438
            reset();
1439
            break;
1440
        case FLY_TEXT:
1441
        /*
1442
        @ text fontcolor,x,y,font,text_string
1443
        @ font may be described by keywords : giant,huge,normal,small,tiny
7956 schaersvoo 1444
        @ use command 'fontsize' to increase base fontsize for these keywords
7614 schaersvoo 1445
        @ may be set "onclick" or "drag xy"
1446
        @ backwards compatible with flydraw
1447
        @ unicode supported: text red,0,0,huge,\\u2232
7874 schaersvoo 1448
        @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
1449
        @ 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 reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
7614 schaersvoo 1450
        */
1451
            for(i = 0; i < 5 ;i++){
1452
                switch(i){
1453
                    case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
1454
                    case 1: double_data[0] = get_real(infile,0);break; /* x */
1455
                    case 2: double_data[1] = get_real(infile,0);break; /* y */
1456
                    case 3: fly_font = get_string_argument(infile,0);
1457
                            if(strcmp(fly_font,"giant") == 0){
1458
                                font_size = (int)(font_size + 24);
1459
                            }
1460
                            else
1461
                            {
1462
                                if(strcmp(fly_font,"huge") == 0){
1463
                                    font_size = (int)(font_size + 14);
1464
                                }
1465
                                else
1466
                                {
1467
                                    if(strcmp(fly_font,"large") == 0){
1468
                                        font_size = (int)(font_size + 6);
1469
                                        }
1470
                                        else
1471
                                        {
1472
                                            if(strcmp(fly_font,"small") == 0){
1473
                                                font_size = (int)(font_size - 4);
1474
                                                if(font_size<0){font_size = 8;}
1475
                                        }
1476
                                    }
1477
                                }
1478
                            }
1479
                            break; /* font_size ! */
7956 schaersvoo 1480
                    case 4:
7614 schaersvoo 1481
                        temp = get_string_argument(infile,1);
1482
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 1483
                        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,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\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,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 1484
                        click_cnt++;reset();break;
1485
                    default:break;
1486
                }
1487
            }
1488
            break;
1489
        case FLY_TEXTUP:
1490
        /*
1491
         @ textup fontcolor,x,y,font,text_string
1492
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
1493
         @ font may be described by keywords : giant,huge,normal,small,tiny
7956 schaersvoo 1494
         @ use command 'fontsize' to increase base fontsize for the keywords
7614 schaersvoo 1495
         @ backwards compatible with flydraw
1496
         @ unicode supported: textup red,0,0,huge,\\u2232
1497
         @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
7874 schaersvoo 1498
         @ 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 reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
7614 schaersvoo 1499
        */
7956 schaersvoo 1500
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}  
7614 schaersvoo 1501
            for(i = 0; i<5 ;i++){
1502
                switch(i){
1503
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
1504
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
1505
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
1506
                    case 3: fly_font = get_string_argument(infile,0);
1507
                            if(strcmp(fly_font,"giant") == 0){
1508
                                font_size = (int)(font_size + 24);
1509
                            }
1510
                            else
1511
                            {
1512
                                if(strcmp(fly_font,"huge") == 0){
1513
                                    font_size = (int)(font_size + 14);
1514
                                }
1515
                                else
1516
                                {
1517
                                    if(strcmp(fly_font,"large") == 0){
1518
                                        font_size = (int)(font_size + 6);
1519
                                        }
1520
                                        else
1521
                                        {
1522
                                            if(strcmp(fly_font,"small") == 0){
1523
                                                font_size = (int)(font_size - 4);
1524
                                                if(font_size<0){font_size = 8;}
1525
                                        }
1526
                                    }
1527
                                }
1528
                            }
1529
                            break; /* font_size ! */
7956 schaersvoo 1530
                    case 4:
7614 schaersvoo 1531
                    decimals = find_number_of_digits(precision);
1532
                    temp = get_string_argument(infile,1);
8071 schaersvoo 1533
                    string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 1534
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 1535
                    snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 1536
                    add_to_buffer(tmp_buffer);
1537
                    break;
1538
                    default:break;
1539
                }
1540
            }
1541
            reset();
1542
            break;
1543
        case FONTFAMILY:
1544
        /*
1545
         @ fontfamily font_description
1546
         @ set the font family; for browsers that support it
1547
         @ font_description: Ariel ,Courier, Helvetica etc
1548
         @ 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
1549
         @ use correct syntax : 'font style' 'font size'px 'fontfamily'
1550
        */
1551
            font_family = get_string(infile,1);
1552
            break;
1553
        case STRINGUP:
7956 schaersvoo 1554
        /*
1555
         @ stringup color,x,y,rotation_degrees,the text string
7614 schaersvoo 1556
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
1557
         @ unicode supported: stringup red,0,0,45,\\u2232
1558
         @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
1559
 
1560
        */
1561
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
1562
            for(i=0;i<6;i++){
1563
                switch(i){
1564
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
1565
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
1566
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
1567
                    case 3: double_data[0] = get_real(infile,0);break;/* rotation */
1568
                    case 4: decimals = find_number_of_digits(precision);
1569
                            temp = get_string_argument(infile,1);
8071 schaersvoo 1570
                            string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 1571
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 1572
                            snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 1573
                            add_to_buffer(tmp_buffer);
1574
                            break;
1575
                    default:break;
1576
                }
1577
            }
1578
            reset();
1579
            break;
1580
        case STRING:
7956 schaersvoo 1581
        /*
7614 schaersvoo 1582
         @ string color,x,y,the text string
1583
         @ may be set "onclick" or "drag xy"
1584
         @ unicode supported: string red,0,0,\\u2232
7956 schaersvoo 1585
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
7614 schaersvoo 1586
        */
1587
            for(i=0;i<5;i++){
1588
                switch(i){
1589
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
1590
                    case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
1591
                    case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
1592
                    case 3: decimals = find_number_of_digits(precision);
1593
                        temp = get_string_argument(infile,1);
1594
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 1595
                        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,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\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,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 1596
                        click_cnt++;reset();break;
1597
                    default:break;
1598
                }
1599
            }
1600
            break;
7983 schaersvoo 1601
        case CENTERSTRING:
1602
        /*
1603
         @ centerstring color,y-value,the text string
7984 schaersvoo 1604
         @ title color,y-value,the text string
7983 schaersvoo 1605
         @ draw a string centered on the canvas at y = y-value
1606
         @ can not set "onclick" or "drag xy" (...)
1607
         @ unicode supported: centerstring red,5,\\u2232
1608
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
1609
        */
1610
            if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
1611
            for(i=0;i<3;i++){
1612
                switch(i){
1613
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
1614
                    case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
1615
                    case 2: temp = get_string_argument(infile,1);
1616
                            /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
1617
                            decimals = find_number_of_digits(precision);
1618
                            string_length = snprintf(NULL,0,
1619
                            "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
1620
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1621
                            snprintf(tmp_buffer,string_length,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
1622
                            add_to_buffer(tmp_buffer);
1623
                            break;
1624
                    default:break;
1625
                }
1626
            }
1627
            break;
7614 schaersvoo 1628
        case MATHML:
1629
        /*
1630
        @ mathml x1,y1,x2,y2,mathml_string
7956 schaersvoo 1631
        @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2)
7614 schaersvoo 1632
        @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
7956 schaersvoo 1633
        @ 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();"
7614 schaersvoo 1634
        @ 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....
7956 schaersvoo 1635
 
7614 schaersvoo 1636
        */
1637
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
1638
            for(i=0;i<5;i++){
1639
                switch(i){
1640
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1641
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1642
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
1643
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
1644
                    case 4: decimals = find_number_of_digits(precision);
7956 schaersvoo 1645
                            if(onclick == 1 ){ onclick = click_cnt;click_cnt++;}
7614 schaersvoo 1646
                            temp = get_string(infile,1);
1647
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
1648
                            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);
1649
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1650
                            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);
1651
                            add_to_buffer(tmp_buffer);
7956 schaersvoo 1652
                            /*
1653
                             in case inputs are present , trigger adding the read_mathml()
7614 schaersvoo 1654
                             if no other reply_format is defined
1655
                             note: all other reply types will include a reading of elements with id='mathml'+p)
1656
                             */
1657
                            if(strstr(temp,"mathml0") != NULL){
7876 schaersvoo 1658
                             if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
7614 schaersvoo 1659
                            }
1660
                            break;
1661
                    default:break;
1662
                }
1663
            }
1664
            reset();
1665
            break;
1666
        case HTTP:
1667
        /*
1668
         @http x1,y1,x2,y2,http://some_adress.com
7956 schaersvoo 1669
         @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
7614 schaersvoo 1670
         @do not use interactivity (or mouse) if the mouse needs to be active in the iframe
1671
         @can not be 'set onclick' or 'drag xy'
1672
        */
7956 schaersvoo 1673
            if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}    
7614 schaersvoo 1674
            for(i=0;i<5;i++){
1675
                switch(i){
1676
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1677
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1678
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
1679
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
1680
                    case 4: decimals = find_number_of_digits(precision);
1681
                            temp = get_string(infile,1);
1682
                            if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
1683
                            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);
1684
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1685
                            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);
1686
                            add_to_buffer(tmp_buffer);
1687
                    break;
1688
                }
1689
            }
1690
            reset();
1691
            break;
1692
        case HTML:
1693
        /*
1694
         @ html x1,y1,x2,y2,html_string
1695
         @ all tags are allowed
1696
         @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
1697
         @ 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.
7956 schaersvoo 1698
 
7614 schaersvoo 1699
         note: uses the same code as 'mathml'
1700
        */
1701
            break;
1702
        case X_AXIS_STRINGS:
1703
        /*
1704
         @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1705
         @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1706
         @ use these x-axis values in stead of default xmin...xmax
1707
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
1708
         @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied
1709
         @ 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
1710
         @ 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
1711
        */
1712
            temp = get_string(infile,1);
1713
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
1714
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
1715
            fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
1716
            use_axis_numbering = 1;
1717
            break;
1718
        case Y_AXIS_STRINGS:
1719
        /*
1720
         @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1721
         @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1722
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
1723
         @ use these y-axis values in stead of default ymin...ymax
1724
         @ 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
1725
        */
1726
            temp = get_string(infile,1);
1727
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
1728
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
1729
            fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
1730
            use_axis_numbering = 1;
1731
            break;
7956 schaersvoo 1732
 
7614 schaersvoo 1733
        case AXIS_NUMBERING:
1734
        /*
7956 schaersvoo 1735
            @ axisnumbering
8101 schaersvoo 1736
            @ keyword, no arguments required
7614 schaersvoo 1737
        */
1738
            use_axis_numbering = 1;
1739
            break;
1740
        case AXIS:
1741
        /*
1742
            @ axis
8101 schaersvoo 1743
            @ keyword, no arguments required
7614 schaersvoo 1744
 
1745
        */
1746
            use_axis = TRUE;
1747
            break;
8101 schaersvoo 1748
        case KILLSLIDER:
1749
        /*
1750
         @ killslider
1751
         @ keyword, no arguments required
1752
         @ ends grouping of object under a preciously defined slider
1753
        */
1754
            slider = 0;
1755
            break;
8071 schaersvoo 1756
        case SLIDER:
1757
        /*
8097 schaersvoo 1758
        @ slider start_value,end_value,width px,height px,type,label
1759
        @ type: xy,x,y,angle
8101 schaersvoo 1760
        @ use commmand 'slider' before draggable/clickable objects.
1761
        @ a slider will affect all draggable objects after the 'slider' command...<br />and can be used to group translate / rotate several objects...<br />until a next 'slider' or keyword 'killslider'
8097 schaersvoo 1762
        @ amount of sliders is not limited.
8101 schaersvoo 1763
        @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
8097 schaersvoo 1764
        @ type=angle: for all objects in radians<br />except command 'arc', which should be in degrees !
1765
        @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
1766
        @ every draggable object may have it's own slider (no limit in amount of sliders)
8071 schaersvoo 1767
        @ label: some slider text
1768
        @ use fillcolor for slider ball
1769
        @ use strokecolor for slider bar
8097 schaersvoo 1770
        @ use fontfamily / fontcolor to set used fonts
8071 schaersvoo 1771
        @ use opacity (only fill opacity will be used) to set transparency
1772
        @ the slider will be draw in the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
1773
        */
1774
            for(i=0; i<6 ; i++){
1775
                switch(i){
1776
                    case 0: double_data[0] = get_real(infile,0);break; /* start value */
1777
                    case 1: double_data[1] = get_real(infile,0);break; /* end value */
1778
                    case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
1779
                    case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
8097 schaersvoo 1780
                    case 4: temp = get_string_argument(infile,0); /* type : x,y,angle */
1781
                    if(strstr(temp,"xy")!= NULL){
1782
                     slider = 4;
1783
                    }
1784
                    else
1785
                    {
1786
                     if(strstr(temp,"x") != NULL){
1787
                      slider = 1;
1788
                     }
1789
                     else
1790
                     {
1791
                      if(strstr(temp,"y") != NULL){
1792
                       slider = 2;
1793
                      }
1794
                      else
1795
                      {
1796
                       if(strstr(temp,"angle") != NULL){
1797
                        slider = 3;
1798
                       }
1799
                       else
1800
                       {
1801
                        canvas_error("slider types may be : x , y , xy , angle");
1802
                       }                     
1803
                      }
1804
                     }
1805
                    }
1806
                    break;
1807
                    case 5: /* some string used for slider description  */
8071 schaersvoo 1808
                    slider_cnt++;
8097 schaersvoo 1809
                    if(slider == 4){
1810
                     add_xyslider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color);
1811
                    }else{
1812
                     add_slider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color);
1813
                    }
8071 schaersvoo 1814
                    break;
1815
                }
8097 schaersvoo 1816
             }
8071 schaersvoo 1817
            break;
7654 schaersvoo 1818
        case SGRAPH:
1819
        /*
1820
         @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
1821
         @ primitive implementation of a 'broken scale' graph...
7976 schaersvoo 1822
         @ not very versatile: only usable in combination with userdraw <br />eg no other objects will obey this "coordinate system"<br />if you want to place an object into this coordinate system, be aware that 10% or 20% of xsize and/or ysize is 'lost'.<br />Use these "formulas" to recalculate the virtual coordinates:<br />factor=0.8 in case xstart != xmin (or ystart != ymin)<br />factor=0.9 in case xstart = xmin (or ystart = ymin)<br />px_x_point = ((factor*xsize)/(xmax - xstart))*(x_point - xmax)+xsize<br />x_recalculated = px*(xmax - xmin)/xsize + $xmin<br />px_y_point = -1*factor*y_point*ysize/(ymax - ystart) + ymax*factor*ysize/(ymax - ystart)<br />y_recalculated = ymax - py*(ymax - ymin)/ysize<br />
1823
         @ example:<br />size 400,400<br />xrange 0,10000<br />yrange 0,100<br />sgraph 9000,50,100,10,4,4,grey,blue<br />userinput_xy<br />linewidth 2<br />userdraw segments,red
7654 schaersvoo 1824
        */
7956 schaersvoo 1825
            if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
7654 schaersvoo 1826
            for(i = 0 ; i < 8 ;i++){
1827
                switch(i){
1828
                    case 0:double_data[0] = get_real(infile,0);break;
1829
                    case 1:double_data[1] = get_real(infile,0);break;
1830
                    case 2:double_data[2] = get_real(infile,0);break;
1831
                    case 3:double_data[3] = get_real(infile,0);break;
1832
                    case 4:int_data[0] = (int)(get_real(infile,0));break;
1833
                    case 5:int_data[1] = (int)(get_real(infile,0));break;
1834
                    case 6:stroke_color = get_color(infile,0);break;
1835
                    case 7:font_color = get_color(infile,1);
7658 schaersvoo 1836
                    string_length = snprintf(NULL,0,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size);
7654 schaersvoo 1837
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7658 schaersvoo 1838
                    snprintf(tmp_buffer,string_length,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size);
7654 schaersvoo 1839
                    add_to_buffer(tmp_buffer);
1840
                    break;
1841
                    default:break;
1842
                }
1843
            }
1844
            /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
1845
            break;
7614 schaersvoo 1846
        case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/
1847
        /*
1848
         @ grid step_x,step_y,gridcolor
1849
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
1850
         @ 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
7654 schaersvoo 1851
         @ if xmin > 0 and/or ymin > 0 and zooming / panning is not activ: <br /> be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual <br /> as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV)
7614 schaersvoo 1852
         @ can not be set "onclick" or "drag xy"
1853
         @ 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')
1854
         @ 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')
1855
         @ 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')
1856
        */
7729 schaersvoo 1857
            if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
7614 schaersvoo 1858
            if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
1859
            for(i=0;i<4;i++){
1860
                switch(i){
1861
                    case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
1862
                    case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
1863
                    case 2:
1864
                    if( use_axis == TRUE ){
1865
                        stroke_color = get_color(infile,0);
1866
                        done = FALSE;
1867
                        int_data[0] = (int) (get_real(infile,0));/* xminor */
1868
                        int_data[1] = (int) (get_real(infile,0));/* yminor */
1869
                        int_data[2] = (int) (get_real(infile,0));/* tic_length */
1870
                        fill_color = get_color(infile,1); /* used as axis_color*/
1871
                    }
1872
                    else
1873
                    {
1874
                        int_data[0] = 1;
1875
                        int_data[1] = 1;
1876
                        stroke_color = get_color(infile,1);
1877
                        fill_color = stroke_color;
1878
                    }
1879
                    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 !");}
7634 schaersvoo 1880
                    /* set snap_x snap_y values in pixels */
7988 schaersvoo 1881
                    fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
8071 schaersvoo 1882
                    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,%s,%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
7614 schaersvoo 1883
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 1884
                    snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
7614 schaersvoo 1885
                    add_to_buffer(tmp_buffer);
1886
                    break;
1887
                }
1888
            }
1889
            reset();
1890
            break;
1891
        case OPACITY:
1892
        /*
1893
        @ opacity 0-255,0-255
1894
        @
1895
        */
1896
            for(i = 0 ; i<2;i++){
1897
                switch(i){
1898
                    case 0: double_data[0]=(int)(get_real(infile,0));break;
1899
                    case 1: double_data[1]=(int)(get_real(infile,1));break;
1900
                    default: break;
1901
                }
1902
            }
1903
            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 ? */
1904
            stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */
1905
            fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */
1906
            break;
1907
        case ROTATE:
1908
        /*
1909
         @rotate rotation_angle
8097 schaersvoo 1910
         @angle in degrees
7614 schaersvoo 1911
        */
1912
            use_rotate = TRUE;
8097 schaersvoo 1913
            angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
7614 schaersvoo 1914
            break;
7785 schaersvoo 1915
        case KILLAFFINE:
1916
        /*
1917
        @ killaffine
1918
        @ keyword : resets the transformation matrix to 1,0,0,1,0,0
1919
        */
1920
            use_affine = FALSE;
7956 schaersvoo 1921
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");    
7785 schaersvoo 1922
            break;
1923
        case AFFINE:
1924
        /*
1925
         @affine a,b,c,d,tx,ty
7956 schaersvoo 1926
         @ defines a transformation matrix for subsequent objects
7785 schaersvoo 1927
         @ use keyword 'killaffine' to end the transformation
1928
         @ note 1: only 'draggable' / 'noclick' objects can be transformed.
1929
         @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
1930
         @ note 3: no matrix operations on the transformation matrix implemented (yet)
1931
         @ a : Scales the drawings horizontally
1932
         @ b : Skews the drawings horizontally
1933
         @ c : Skews the drawings vertically
1934
         @ d : Scales the drawings vertically
8071 schaersvoo 1935
         @ tx: Moves the drawings horizontally in xrange coordinate system
1936
         @ ty: Moves the drawings vertically in yrange coordinate system
1937
         @ the data precision is 2 decimals (printf : %2.f)
7785 schaersvoo 1938
        */
1939
            for(i = 0 ; i<6;i++){
1940
                switch(i){
1941
                    case 0: double_data[0] = get_real(infile,0);break;
1942
                    case 1: double_data[1] = get_real(infile,0);break;
1943
                    case 2: double_data[2] = get_real(infile,0);break;
1944
                    case 3: double_data[3] = get_real(infile,0);break;
8071 schaersvoo 1945
                    case 4: double_data[4] = get_real(infile,0);break;
1946
                    case 5: double_data[5] = get_real(infile,1);
7785 schaersvoo 1947
                        use_affine = TRUE;
8071 schaersvoo 1948
                        string_length = snprintf(NULL,0,     "[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f] ",double_data[0],double_data[1],double_data[2],double_data[3],double_data[4]*xsize/(xmax - xmin),-1*double_data[5]*ysize/(ymax - ymin));
7785 schaersvoo 1949
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
8071 schaersvoo 1950
                        snprintf(affine_matrix,string_length,"[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f] ",double_data[0],double_data[1],double_data[2],double_data[3],double_data[4]*xsize/(xmax - xmin),-1*double_data[5]*ysize/(ymax - ymin));    
1951
                        break;
7785 schaersvoo 1952
                    default: break;
1953
                }
1954
            }
1955
        break;
7614 schaersvoo 1956
        case KILLTRANSLATION:
1957
        /*
1958
         killtranslation
1959
        */
8071 schaersvoo 1960
            use_affine = FALSE;
1961
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");    
7614 schaersvoo 1962
            break;
1963
        case TRANSLATION:
1964
        /*
1965
         @translation tx,ty
8071 schaersvoo 1966
         @will translate the next object tx in xrange and ty in yrange
1967
         @uase command 'killtranstation' to end the command
7614 schaersvoo 1968
        */
8071 schaersvoo 1969
            for(i = 0 ; i<2;i++){
1970
                switch(i){
1971
                    case 0: double_data[0] = get_real(infile,0);break;
1972
                    case 1: double_data[1] = get_real(infile,1);
1973
                        use_affine = TRUE;
1974
                        string_length = snprintf(NULL,0, "[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
1975
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
1976
                        snprintf(affine_matrix,string_length,"[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
1977
                        break;
1978
                    default: break;
1979
                }
1980
            }
1981
        break;
1982
 
7614 schaersvoo 1983
        case DASHED:
1984
        /*
1985
        @ keyword "dashed"
1986
        @ next object will be drawn with a dashed line
1987
        @ change dashing scheme by using command "dashtype int,int)
1988
        */
1989
            use_dashed = TRUE;
1990
            break;
1991
        case FILLED:
1992
        /*
7956 schaersvoo 1993
        @ keyword "filled"
1994
        @ the next 'fillable' object (only) will be filled
7614 schaersvoo 1995
        @ use command "fillcolor color" to set fillcolor
1996
        @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
1997
        @ 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 !
1998
        */
1999
            use_filled = TRUE;
2000
            break;
2001
        case STYLE:
2002
        /*
2003
         @highlight color,opacity,linewidth
2004
         @ NOT IMPLEMENTED
2005
         @ use command "onclick" : when the object receives a userclick it will increase it's linewidth
2006
        */
2007
            break;
2008
        case FILLCOLOR:
2009
        /*
2010
        @ fillcolor colorname or #hex
2011
        @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
2012
        @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...)
2013
        */
2014
            fill_color = get_color(infile,1);
2015
            break;
2016
        case STROKECOLOR:
2017
        /*
2018
        @ strokecolor colorname or #hex
2019
        @ to be used for commands that do not supply a color argument (like command 'linegraph')
2020
        */
2021
            stroke_color = get_color(infile,1);
2022
            break;
7956 schaersvoo 2023
        case BGIMAGE:
7614 schaersvoo 2024
        /*
2025
         @bgimage image_location
2026
         @use an image as background .<br />(we use the background of 'canvas_div' )
2027
         @the background image will be resized to match "width = xsize" and "height = ysize"
2028
        */
2029
        URL = get_string(infile,1);
2030
        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);
2031
            break;
7956 schaersvoo 2032
        case BGCOLOR:
7614 schaersvoo 2033
        /*
2034
         @bgcolor colorname or #hex
2035
         @use this color as background of the "div" containing the canvas(es)
2036
        */
2037
        /* [255,255,255]*/
2038
            bgcolor = get_string(infile,1);
2039
            if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
2040
                int found = 0;
2041
                for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
2042
                    if( strcmp( colors[i].name , bgcolor ) == 0 ){
2043
                        bgcolor = colors[i].hex;
2044
                        found = 1;
2045
                        break;
2046
                    }
2047
                }
2048
                if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
2049
            }
2050
            fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
2051
            break;
2052
        case COPY:
2053
        /*
2054
        @ copy x,y,x1,y1,x2,y2,[filename URL]
2055
        @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
2056
        @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
7956 schaersvoo 2057
        @ [filename] is the URL of the image   
7614 schaersvoo 2058
        @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
2059
        @ 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
7956 schaersvoo 2060
        @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
7614 schaersvoo 2061
 
2062
        context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
2063
        draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){
2064
        */
2065
            for(i = 0 ; i<7;i++){
2066
                switch(i){
2067
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
2068
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
2069
                    case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
2070
                    case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
2071
                    case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
2072
                    case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
2073
                    case 6: URL = get_string(infile,1);
2074
                            int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
2075
                            int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
2076
                            if( drag_type > -1 ){
2077
                                if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
7876 schaersvoo 2078
                                if(reply_format == 0 ){reply_format = 20;}
7614 schaersvoo 2079
                                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);
2080
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7956 schaersvoo 2081
                                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);                       
7614 schaersvoo 2082
                                drag_type = -1;
2083
                                ext_img_cnt++;
2084
                            }
2085
                            else
2086
                            {
2087
                                if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
2088
                                /*
2089
                                draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\
2090
                                */
2091
                                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]);
2092
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2093
                                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]);
2094
                            }
2095
                            add_to_buffer(tmp_buffer);
2096
                            break;
2097
                    default: break;
2098
                }
2099
            }
2100
            reset();
2101
            break;
2102
/*
2103
context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
2104
img     Specifies the image, canvas, or video element to use
2105
sx      The x coordinate where to start clipping : x1 = int_data[0]
2106
sy      The y coordinate where to start clipping : x2 = int_data[1]
7956 schaersvoo 2107
swidth  The width of the clipped image : int_data[2] - int_data[0]
7614 schaersvoo 2108
sheight The height of the clipped image : int_data[3] - int_data[1]
2109
x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
2110
y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
2111
width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
2112
height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
2113
*/
2114
        case COPYRESIZED:
2115
        /*
2116
        @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
7956 schaersvoo 2117
        @ 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
7614 schaersvoo 2118
        @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
2119
        @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
2120
        @ 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
7956 schaersvoo 2121
        @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
7614 schaersvoo 2122
        */
2123
            for(i = 0 ; i<9;i++){
2124
                switch(i){
2125
                    case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
2126
                    case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
2127
                    case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
2128
                    case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
2129
                    case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
2130
                    case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
2131
                    case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
2132
                    case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
2133
                    case 8: URL = get_string(infile,1);
2134
                            if( drag_type > -1 ){
2135
                                if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
7876 schaersvoo 2136
                                if(reply_format == 0 ){reply_format = 20;}
7614 schaersvoo 2137
                                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);
2138
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2139
                                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);
2140
                                drag_type = -1;
2141
                                ext_img_cnt++;
2142
                            }
2143
                            else
2144
                            {
2145
                                if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
2146
                                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]);
2147
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2148
                                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]);
2149
                            }
2150
                            add_to_buffer(tmp_buffer);
2151
                    default: break;
2152
                }
2153
            }
2154
            reset();
2155
            break;
2156
        case BUTTON:
2157
        /*
2158
         button x,y,value
2159
        */
2160
        break;
2161
        case INPUTSTYLE:
2162
        /*
2163
        @ inputstyle style_description
2164
        @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
2165
        */
2166
            input_style = get_string(infile,1);
2167
            break;
2168
        case INPUT:
7956 schaersvoo 2169
        /*
7614 schaersvoo 2170
         @ input x,y,size,editable,value
7956 schaersvoo 2171
         @ to set inputfield "readonly", use editable = 0
7614 schaersvoo 2172
         @ only active inputfields (editable = 1) will be read with read_canvas();
7956 schaersvoo 2173
         @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
7614 schaersvoo 2174
         @ may be further controlled by "inputstyle" (inputcss is not yet implemented...)
2175
         @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
2176
        */
7956 schaersvoo 2177
        if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}    
7614 schaersvoo 2178
            for(i = 0 ; i<5;i++){
2179
                switch(i){
2180
                    case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
2181
                    case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
2182
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
2183
                    case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
7956 schaersvoo 2184
                    case 4:
7614 schaersvoo 2185
                            temp = get_string_argument(infile,1);
2186
                            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);
2187
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2188
                            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);
2189
                            add_to_buffer(tmp_buffer);
2190
                            input_cnt++;break;
2191
                    default: break;
2192
                }
2193
            }
7876 schaersvoo 2194
            if(reply_format == 0 ){reply_format = 15;}
7614 schaersvoo 2195
            reset();
2196
            break;
2197
        case TEXTAREA:
7956 schaersvoo 2198
        /*
7614 schaersvoo 2199
         @ textarea x,y,cols,rows,readonly,value
2200
         @ may be further controlled by "inputstyle"
7956 schaersvoo 2201
         @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
7614 schaersvoo 2202
         @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
2203
        */
7956 schaersvoo 2204
            if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}  
7614 schaersvoo 2205
            for(i = 0 ; i<6;i++){
2206
                switch(i){
2207
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
2208
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
2209
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
2210
                    case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
2211
                    case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
2212
                    case 5: temp = get_string_argument(infile,1);
2213
                            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);
2214
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2215
                            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);
2216
                            add_to_buffer(tmp_buffer);
2217
                            input_cnt++;break;
2218
                    default: break;
2219
                }
2220
            }
7876 schaersvoo 2221
            if(reply_format == 0 ){reply_format = 15;}
7614 schaersvoo 2222
            reset();
2223
            break;
2224
        case MOUSE_PRECISION:
2225
        /*
2226
            @ precision int
8074 schaersvoo 2227
            @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
7614 schaersvoo 2228
            @ may be used / changed before every object
8074 schaersvoo 2229
            @ In case of user interaction (like 'userdraw') this value will be used to determine the amount of decimals in the reply / answer
7614 schaersvoo 2230
        */
2231
            precision = (int) (get_real(infile,1));
8074 schaersvoo 2232
            if(precision < 1 ){precision = 1;};
7614 schaersvoo 2233
            break;
7838 schaersvoo 2234
        case SETLIMITS:
2235
        /*
7956 schaersvoo 2236
            @setlimits
7838 schaersvoo 2237
            @keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
2238
            @may be used for inputfield based zooming / panning
7858 schaersvoo 2239
            @use command xlabel / ylabel to change text from xmin to 'xlabel'min etc
7956 schaersvoo 2240
            @note:the input value will not be checked on validity
7838 schaersvoo 2241
        */
7956 schaersvoo 2242
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7838 schaersvoo 2243
            add_setlimits(js_include_file,canvas_root_id);
2244
            /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
2245
            use_pan_and_zoom = TRUE;
2246
            done = TRUE;
2247
            break;
7614 schaersvoo 2248
        case ZOOM:
2249
        /*
2250
         @ zoom button_color
2251
         @ introduce a controlpanel at the lower right corner
2252
         @ 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
2253
         @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
2254
         @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
7956 schaersvoo 2255
         @ command 'opacity' may be used to set stroke_opacity of 'buttons
7988 schaersvoo 2256
         @ NOTE: use command 'zoom' at the end of your script code (the same is true for commanmd 'mouse')
7614 schaersvoo 2257
         @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned
2258
         @ 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 !!
2259
        */
7653 schaersvoo 2260
            fprintf(js_include_file,"use_pan_and_zoom = 1;");
7797 schaersvoo 2261
            use_pan_and_zoom = TRUE;
7988 schaersvoo 2262
            stroke_color = get_color(infile,1);
7614 schaersvoo 2263
            /* we use BG_CANVAS (0) */
7988 schaersvoo 2264
            add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
7614 schaersvoo 2265
            done = TRUE;
2266
            break;
2267
        case ONCLICK:
2268
        /*
2269
         @ onclick
2270
         @ keyword, no arguments
2271
         @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas();
7956 schaersvoo 2272
         @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked.
7906 schaersvoo 2273
         @ NOTE: not all objects may be set clickable
7614 schaersvoo 2274
        */
7956 schaersvoo 2275
 
7614 schaersvoo 2276
            onclick = 1;
2277
            break;
2278
        case DRAG:
2279
        /*
2280
         @ drag [x][y][xy]
2281
         @ the next object will be draggable in x / y / xy direction
2282
         @ the displacement can be read by 'javascript:read_dragdrop();'
8074 schaersvoo 2283
         @ the precision (default 2 decimals) in the student reply may be set with command 'precision'.<br />Use this 'precision' command before this command 'drag x|y|xy' !
7906 schaersvoo 2284
         @ the answer is  : object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the place of the draggable object in your script.<br />Only draggable object will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc)
7881 schaersvoo 2285
         @ use keywordd 'snaptogrid' , 'xsnaptogrid' or 'ysnaptogrid' to switch from free to discrete movement
7956 schaersvoo 2286
         @ 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.
7614 schaersvoo 2287
         @ 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 !!
2288
        */
2289
            temp = get_string(infile,1);
7956 schaersvoo 2290
            if(strstr(temp,"xy") != NULL ){
7614 schaersvoo 2291
                drag_type = 0;
2292
            }
2293
            else
2294
            {
7956 schaersvoo 2295
                if(strstr(temp,"x") != NULL ){
7614 schaersvoo 2296
                    drag_type = 1;
2297
                }
2298
                else
2299
                {
2300
                    drag_type = 2;
2301
                }
2302
            }
8074 schaersvoo 2303
            fprintf(js_include_file,"var dragdrop_precision = %d;",precision);
7614 schaersvoo 2304
            onclick = 2;
2305
            /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
2306
            break;
2307
        case BLINK:
2308
        /*
2309
         @ blink time(seconds)
2310
         @ NOT IMPLEMETED -YET
2311
        */
2312
            break;
7996 schaersvoo 2313
        case XUNIT:
2314
        /*
2315
         @ xunit some_unit_for_x-values
2316
         @ unicode allowed (no html code)
2317
         @ use together with command mousex
2318
         @ will display the cursor x-coordinate 'unit'
2319
        */
2320
            fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
2321
            break;
2322
        case YUNIT:
2323
        /*
2324
         @ yunit some_unit_for_y-values
2325
         @ unicode allowed (no html code)
2326
         @ use together with command mousex
2327
         @ will display the cursor y-coordinate 'unit'
2328
        */
2329
            fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
2330
            break;
8071 schaersvoo 2331
        case MOUSE_DISPLAY:
2332
        /*
2333
         @display x|y|xy|degree,color,fontsize
8099 schaersvoo 2334
         @will display the mouse cursor coordinates as x-only,y-only,(x:y) or the angle in degrees<br />(angle between x-axis;(0:0);(x:y)
8071 schaersvoo 2335
         @just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
2336
        */
2337
        temp = get_string_argument(infile,0);
2338
        if(strstr(temp,"degree") != NULL){
2339
            int_data[0] = 3;
2340
        }else{
2341
            if( strstr(temp,"xy") != NULL ){
2342
                int_data[0] = 2;
2343
            }else{
2344
                if( strstr(temp,"y") != NULL ){
2345
                    int_data[0] = 1;
2346
                }else{
2347
                    if( strstr(temp,"x") != NULL ){
2348
                        int_data[0] = 0;
2349
                    }else{
2350
                        int_data[0] = 2;
2351
                    }  
2352
                }
2353
            }
2354
        }      
2355
        stroke_color = get_color(infile,0);
2356
        font_size = (int) (get_real(infile,1));
2357
        tmp_buffer = my_newmem(26);
2358
        snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2359
        add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
2360
        break;
2361
        case MOUSE_DEGREE:
2362
        /*
2363
         @ mouse_degree color,fontsize
8099 schaersvoo 2364
         @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using default fontfamily Ariel
8071 schaersvoo 2365
         @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
2366
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2367
 
2368
        */
2369
            stroke_color = get_color(infile,0);
2370
            font_size = (int) (get_real(infile,1));
2371
            tmp_buffer = my_newmem(26);
2372
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2373
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
2374
            break;
7991 schaersvoo 2375
        case MOUSEX:
2376
        /*
2377
         @ mousex color,fontsize
2378
         @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
8071 schaersvoo 2379
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
7991 schaersvoo 2380
 
2381
        */
2382
            stroke_color = get_color(infile,0);
2383
            font_size = (int) (get_real(infile,1));
2384
            tmp_buffer = my_newmem(26);
2385
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2386
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
2387
            break;
2388
        case MOUSEY:
2389
        /*
2390
         @ mousey color,fontsize
2391
         @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
8071 schaersvoo 2392
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
7991 schaersvoo 2393
 
2394
        */
2395
            stroke_color = get_color(infile,0);
2396
            font_size = (int) (get_real(infile,1));
2397
            tmp_buffer = my_newmem(26);
2398
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2399
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
2400
            break;
7614 schaersvoo 2401
        case MOUSE:
2402
        /*
2403
         @ mouse color,fontsize
7991 schaersvoo 2404
         @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
7988 schaersvoo 2405
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for commanmd 'zoom')
2406
 
7614 schaersvoo 2407
        */
2408
            stroke_color = get_color(infile,0);
2409
            font_size = (int) (get_real(infile,1));
7839 schaersvoo 2410
            tmp_buffer = my_newmem(26);
2411
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
7991 schaersvoo 2412
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
7614 schaersvoo 2413
            break;
2414
        case INTOOLTIP:
2415
            /*
2416
            @ intooltip link_text
2417
            @ link_text is a single line (span-element)
2418
            @ link_text may also be an image URL http://some_server/images/my_image.png
2419
            @ link_text may contain HTML markup
2420
            @ the canvas will be displayed in a tooltip on 'link_text'
2421
            @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor.
2422
            */
7823 schaersvoo 2423
            if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy command");}
7614 schaersvoo 2424
            use_tooltip = TRUE;
2425
            tooltip_text = get_string(infile,1);
2426
            if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
2427
            break;
2428
        case AUDIO:
2429
        /*
2430
        @ audio x,y,w,h,loop,visible,audiofile location
2431
        @ x,y : left top corner of audio element (in xrange / yrange)
2432
        @ w,y : width and height in pixels
2433
        @ loop : 0 or 1 ( 1 = loop audio fragment)
2434
        @ visible : 0 or 1 (1 = show controls)
2435
        @ audio format may be in *.mp3 or *.ogg
2436
        @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
2437
        @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
2438
        @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
2439
        @ 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 />
2440
        */
2441
            if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
2442
            for(i=0;i<7;i++){
2443
                switch(i){
2444
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
2445
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
2446
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
2447
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
2448
                    case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
2449
                    case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
7956 schaersvoo 2450
                    case 6:
7614 schaersvoo 2451
                    temp = get_string(infile,1);
2452
                    if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
2453
                    if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
2454
                    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);
2455
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2456
                    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);
2457
                    add_to_buffer(tmp_buffer);
2458
                    break;
2459
                    default:break;
2460
                }
2461
            }
2462
            reset();
2463
            break;
2464
        case VIDEO:
2465
        /*
2466
        @ video x,y,w,h,videofile location
2467
        @ x,y : left top corner of audio element (in xrange / yrange)
2468
        @ w,y : width and height in pixels
2469
        @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
2470
        @ video format may be in *.mp4 (todo:other formats)
2471
        */
2472
            if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
2473
            for(i=0;i<5;i++){
2474
                switch(i){
2475
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
2476
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
2477
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
2478
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
2479
                    case 4: temp = get_string(infile,1);
2480
                            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);
2481
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2482
                            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);
2483
                            add_to_buffer(tmp_buffer);
2484
                            break;
2485
                    default:break;
2486
                }
2487
            }
2488
            reset();
2489
            break;
2490
        case HATCHFILL:
2491
        /*
2492
        @ hatchfill x0,y0,dx,dy,color
2493
        @ x0,y0 in xrange / yrange
2494
        @ distances dx,dy in pixels
2495
        */
2496
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
2497
            for(i=0;i<5;i++){
2498
                switch(i){
2499
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2500
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2501
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2502
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2503
                    case 4: stroke_color = get_color(infile,1);
2504
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
2505
                    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);
2506
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2507
                    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);
2508
                    add_to_buffer(tmp_buffer);
2509
                    break;
2510
                    default:break;
2511
                }
2512
            }
2513
            reset();
2514
        break;
7647 schaersvoo 2515
        case DIAMONDFILL:
2516
        /*
2517
        @ diamondfill x0,y0,dx,dy,color
2518
        @ x0,y0 in xrange / yrange
2519
        @ distances dx,dy in pixels
2520
        */
2521
            if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
2522
            for(i=0;i<5;i++){
2523
                switch(i){
2524
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2525
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2526
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2527
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2528
                    case 4: stroke_color = get_color(infile,1);
2529
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
2530
                    string_length = snprintf(NULL,0,  "draw_diamondfill(%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);
2531
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2532
                    snprintf(tmp_buffer,string_length,"draw_diamondfill(%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);
2533
                    add_to_buffer(tmp_buffer);
2534
                    break;
2535
                    default:break;
2536
                }
2537
            }
2538
            reset();
2539
        break;
7614 schaersvoo 2540
        case GRIDFILL:
2541
        /*
2542
        @ gridfill x0,y0,dx,dy,color
2543
        @ x0,y0 in xrange / yrange
2544
        @ distances dx,dy in pixels
7883 schaersvoo 2545
        @ a draggable object may snap_to_grid (using keywords xysnaptogrid,xsnaprogrid, ysnaptogrid)
2546
        @ userdraw object may snap_to_grid
7614 schaersvoo 2547
        */
2548
            if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
2549
            for(i=0;i<5;i++){
2550
                switch(i){
2551
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2552
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2553
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2554
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2555
                    case 4: stroke_color = get_color(infile,1);
2556
                    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);
2557
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2558
                    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);
2559
                    add_to_buffer(tmp_buffer);
2560
                    break;
2561
                    default:break;
2562
                }
2563
            }
2564
            reset();
2565
        break;
2566
        case DOTFILL:
2567
        /*
2568
        @ dotfill x0,y0,dx,dy,color
2569
        @ x0,y0 in xrange / yrange
2570
        @ distances dx,dy in pixels
2571
        @ radius of dots is linewidth
2572
        */
2573
            if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
2574
            for(i=0;i<5;i++){
2575
                switch(i){
2576
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2577
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2578
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2579
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2580
                    case 4: stroke_color = get_color(infile,1);
2581
                    /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
2582
                    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);
2583
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2584
                    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);
2585
                    add_to_buffer(tmp_buffer);
2586
                    break;
2587
                    default:break;
2588
                }
2589
            }
2590
            reset();
2591
        break;
2592
        case IMAGEFILL:
2593
        /*
2594
        @ imagefill dx,dy,image_url
2595
        @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
2596
        @ After pattern filling ,the fill-color should be reset !
2597
        @ wims getins / image from class directory : imagefill 80,80,my_image.gif
2598
        @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
2599
        @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
2600
        @ if dx,dy is larger than the image, the whole image will be background to the next object.
2601
        */
2602
            if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
2603
            for(i=0 ;i < 3 ; i++){
2604
                switch(i){
2605
                    case 0:int_data[0] = (int) (get_real(infile,0));break;
2606
                    case 1:int_data[1] = (int) (get_real(infile,0));break;
2607
                    case 2: URL = get_string_argument(infile,1);
2608
                            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);
2609
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2610
                            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);
2611
                            add_to_buffer(tmp_buffer);
2612
                    break;
2613
                }
2614
            }
8083 schaersvoo 2615
            reset();
7614 schaersvoo 2616
        break;
2617
        case FILLTOBORDER:
2618
        /*
2619
        @ filltoborder x,y,bordercolor,color
7956 schaersvoo 2620
        @ fill the region  of point (x:y) bounded by 'bordercolor' with color 'color'
7614 schaersvoo 2621
        @ any other color will not act as border to the bucket fill
2622
        @ use this command  after all boundary objects are declared.
2623
        @ 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..
2624
        */
2625
            for(i=0 ;i < 4 ; i++){
2626
                switch(i){
2627
                    case 0:double_data[0] = get_real(infile,0);break;
2628
                    case 1:double_data[1] = get_real(infile,0);break;
2629
                    case 2:bgcolor = get_color(infile,0);break;
2630
                    case 3:fill_color = get_color(infile,1);
2631
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
2632
                                js_function[DRAW_FILLTOBORDER] = 1;
2633
                                add_js_filltoborder(js_include_file,canvas_root_id);
2634
                           }
2635
                           decimals = find_number_of_digits(precision);
7895 schaersvoo 2636
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
8071 schaersvoo 2637
                           string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
7614 schaersvoo 2638
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 2639
                           snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
7614 schaersvoo 2640
                           add_to_buffer(tmp_buffer);
2641
                           break;
2642
                    default:break;
8083 schaersvoo 2643
                }
2644
            }
2645
            reset();
7614 schaersvoo 2646
        break;
2647
        case FLOODFILL:
2648
        /*
2649
        @ floodfill x,y,color
2650
        @ alternative syntax: fill x,y,color
2651
        @ fill the region of point (x:y) with color 'color'
2652
        @ any other color or size of picture (borders of picture) will act as border to the bucket fill
2653
        @ use this command  after all boundary objects are declared.
2654
        @ Use command 'clickfill,color' for user click driven flood fill.
2655
        @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
2656
        @ 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..
2657
        */
2658
            for(i=0 ;i < 4 ; i++){
2659
                switch(i){
2660
                    case 0:double_data[0] = get_real(infile,0);break;
2661
                    case 1:double_data[1] = get_real(infile,0);break;
2662
                    case 2:fill_color = get_color(infile,1);
2663
                           if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
2664
                                js_function[DRAW_FLOODFILL] = 1;
2665
                                add_js_floodfill(js_include_file,canvas_root_id);
2666
                           }
2667
                           decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */
7895 schaersvoo 2668
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
2669
                           string_length = snprintf(NULL,0,  "setTimeout(function(){floodfill(0,%.*f,%.*f,[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
7614 schaersvoo 2670
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7895 schaersvoo 2671
                           snprintf(tmp_buffer,string_length,"setTimeout(function(){floodfill(0,%.*f,%.*f,[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
7614 schaersvoo 2672
                           add_to_buffer(tmp_buffer);
2673
                           break;
2674
                    default:break;
8083 schaersvoo 2675
                }
2676
            }
2677
            reset();
7614 schaersvoo 2678
        break;
2679
        case CLICKFILLMARGE:
2680
            clickfillmarge = (int) (get_real(infile,1));
2681
            break;
2682
        /*
2683
        @ clickfillmarge int
2684
        @ default 20 (pixels)
2685
        @ 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[])
2686
        */
2687
        case CLICKFILL:
2688
        /*
2689
        @ clickfill fillcolor
2690
        @ user left mouse click will floodfill the area with fillcolor
2691
        @ multiple areas may be coloured
2692
        @ 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)
2693
        @ the answer will be read as the (x:y) click coordinates per coloured area
2694
        @ background color of main div may be set by using command "bgcolor color"
2695
        @ may not be combined with command "userdraw"
2696
        @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
2697
        */
2698
         fill_color = get_color(infile,1);
2699
         if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
2700
            js_function[DRAW_FLOODFILL] = 1;
2701
            add_js_floodfill(js_include_file,canvas_root_id);
2702
         }
7895 schaersvoo 2703
         fprintf(js_include_file,"\n<!-- 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 || [255,255,255,0]);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]);};",clickfillmarge,fill_color,(int) (fill_opacity/0.0039215));
8074 schaersvoo 2704
         add_read_canvas(1,reply_precision);
8083 schaersvoo 2705
         reset();
7614 schaersvoo 2706
        break;
2707
        case SETPIXEL:
2708
        /*
2709
        @ setpixel x,y,color
2710
        @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange
2711
        @ pixels can not be dragged or clicked
2712
        @ "pixelsize = 1" may be changed by command "pixelsize int"
2713
        */
2714
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
2715
            for(i=0;i<3;i++){
2716
                switch(i){
2717
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
2718
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
2719
                    case 2: stroke_color = get_color(infile,1);
2720
                           string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
2721
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2722
                           snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
2723
                           add_to_buffer(tmp_buffer);
2724
                           break;
2725
                    default:break;
2726
                }
2727
            }
2728
            reset();
2729
        break;
2730
        case PIXELSIZE:
2731
        /*
2732
        @ pixelsize int
2733
        @ in case you want to deviate from default pixelsize = 1...
2734
        */
2735
            pixelsize = (int) get_real(infile,1);
2736
        break;
2737
        case PIXELS:
2738
        /*
2739
        @ pixels color,x1,y1,x2,y2,x3,y3...
2740
        @ Draw  "points" with diameter 1 pixel
2741
        @ pixels can not be dragged or clicked
2742
        @ "pixelsize = 1" may be changed by command "pixelsize int"
2743
        */
2744
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
2745
            stroke_color=get_color(infile,0);
2746
            i=0;
2747
            c=0;
2748
            while( ! done ){     /* get next item until EOL*/
2749
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2750
                for( c = 0 ; c < 2; c++){
2751
                    if(c == 0 ){
2752
                        double_data[i] = get_real(infile,0);
2753
                        i++;
2754
                    }
2755
                    else
2756
                    {
2757
                        double_data[i] = get_real(infile,1);
2758
                        i++;
2759
                    }
2760
                }
2761
            }
2762
            decimals = find_number_of_digits(precision);
2763
            /*  *double_xy2js_array(double xy[],int len,int decimals) */
2764
            string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
2765
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2766
            snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
2767
            add_to_buffer(tmp_buffer);
8083 schaersvoo 2768
            reset();
7614 schaersvoo 2769
            break;
2770
        case REPLYFORMAT:
2771
        /*
2772
        @ replyformat number
7876 schaersvoo 2773
        @ use number=-1 to deactivate the js-function read_canvas()
7614 schaersvoo 2774
        @ default values should be fine !
8074 schaersvoo 2775
        @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
7963 schaersvoo 2776
        @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
8083 schaersvoo 2777
        @ 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 = returns 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</li><li>replyformat 23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline isx1,y1,x2,y2,x2,y2,x3,y3,x3,y3.....,x(n-1),y(n-1),x(n-1),y(n-1),xn,yn --replyformat 23--> x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn multiple occurences will be filtered out.The reply will be in x-y-range (xreply \\n yreply)</li><li>replyformat 24 = read all inputfield values: even those set 'readonly'</li><li>format 25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>format 26 = rad1,rad2...rad_n : will return the radius (one or many) of the user drawn circle segment in radians </li></ul>
7614 schaersvoo 2778
        @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...)
2779
        */
2780
         reply_format = (int) get_real(infile,1);
8074 schaersvoo 2781
         reply_precision = precision;
7614 schaersvoo 2782
        break;
2783
        case LEGENDCOLORS:
2784
        /*
2785
        @ legendcolors color1:color2:color3:...:color_n
7956 schaersvoo 2786
        @ will be used to colour a legend: use this command after the legend command ! e.g.<br />legend test1:test2:test3<br />legendcolors blue:red:orange<br />
7614 schaersvoo 2787
        @ make sure the number of colours match the number of legend items
7956 schaersvoo 2788
        @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
7614 schaersvoo 2789
        */
7956 schaersvoo 2790
            if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
7614 schaersvoo 2791
            temp = get_string(infile,1);
2792
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7956 schaersvoo 2793
            fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
7614 schaersvoo 2794
            break;
2795
        case LEGEND:
2796
        /*
2797
        @ legend string1:string2:string3....string_n
2798
        @ will be used to create a legend for a graph
7956 schaersvoo 2799
        @ also see command 'piechart'  
2800
        @ will use the same colors per default as used in the graphs : use command 'legendcolors' to override the default
7614 schaersvoo 2801
        */
2802
            temp = get_string(infile,1);
2803
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7956 schaersvoo 2804
            legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
2805
            fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
7614 schaersvoo 2806
            break;
2807
        case XLABEL:
2808
        /*
2809
        @ xlabel some_string
2810
        @ will be used to create a label for the x-axis (label is in quadrant I)
2811
        @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
7956 schaersvoo 2812
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
7614 schaersvoo 2813
        */
2814
            temp = get_string(infile,1);
7653 schaersvoo 2815
            fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
7614 schaersvoo 2816
            break;
2817
        case YLABEL:
2818
        /*
2819
        @ ylabel some_string
7956 schaersvoo 2820
        @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
7614 schaersvoo 2821
        @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
7956 schaersvoo 2822
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
7614 schaersvoo 2823
        */
2824
            temp = get_string(infile,1);
7653 schaersvoo 2825
            fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
7614 schaersvoo 2826
            break;
2827
        case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
2828
        /*
7996 schaersvoo 2829
        @ linegraph x1:y1;x2:y2...x_n:y_n
7614 schaersvoo 2830
        @ will plot your data in a graph
2831
        @ may only to be used together with command 'grid'
2832
        @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
2833
        @ use command 'legend' to provide an optional legend in right-top-corner
2834
        @ also see command 'piechart'
2835
        @ multiple linegraphs may be used in a single plot
7989 schaersvoo 2836
        @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
7614 schaersvoo 2837
        @ <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>
7956 schaersvoo 2838
        */    
7614 schaersvoo 2839
            temp = get_string(infile,1);
2840
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7653 schaersvoo 2841
            fprintf(js_include_file,"var linegraph_%d = [\"%s\",\"%d\",\"%d\",\"%d\",\"%d\",\"%s\"];",linegraph_cnt,stroke_color,line_width,use_dashed,dashtype[0],dashtype[1],temp);
7614 schaersvoo 2842
            linegraph_cnt++;
2843
            reset();
2844
            break;
7989 schaersvoo 2845
        case BARCHART:
2846
        /*
2847
        @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
2848
        @ will be used to create a legend for bar graph
2849
        @ may only to be used together with command 'grid'
2850
        @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
2851
        @ use command 'legend' to provide an optional legend in right-top-corner
2852
        @ also see command 'piechart'
2853
        @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
2854
        */
2855
            temp = get_string(infile,1);
2856
            if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
2857
            fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
2858
            barchart_cnt++;
2859
            reset();
2860
            break;
7614 schaersvoo 2861
        case CLOCK:
2862
        /*
2863
        @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
7997 schaersvoo 2864
        @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
7614 schaersvoo 2865
        @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
2866
        @ 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
7862 schaersvoo 2867
        @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
7614 schaersvoo 2868
        @ 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>
2869
        @ canvasdraw will not check validity of colornames...the javascript console is your best friend
2870
        @ no combinations with other reply_types allowed, for now
7783 schaersvoo 2871
        @ if interactive, 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
7614 schaersvoo 2872
        */
2873
            if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
2874
 
2875
        /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
2876
            for(i=0;i<9;i++){
2877
             switch(i){
2878
              case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
2879
              case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
2880
              case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
2881
              case 3: int_data[3] = get_real(infile,0);break;/* hours */
2882
              case 4: int_data[4] = get_real(infile,0);break;/* minutes */
2883
              case 5: int_data[5] = get_real(infile,0);break;/* seconds */
7783 schaersvoo 2884
              case 6: int_data[6] = get_real(infile,0);if(int_data[6] < 0 || int_data[6] > 2){canvas_error("hourglass can be 0,1 or 2");}break;/* type hourglass */
7614 schaersvoo 2885
              case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/
7783 schaersvoo 2886
                switch(int_data[7]){
2887
                    case 0:break;
2888
                    case 1:if(clock_cnt == 0){
2889
                                if( reply_format == 0 ){
7614 schaersvoo 2890
                                     reply_format = 18; /* user sets clock */
7783 schaersvoo 2891
                                    /* 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");
7614 schaersvoo 2892
                                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2893
                                     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");
2894
                                     add_to_buffer(tmp_buffer);
7783 schaersvoo 2895
                                    */
8000 schaersvoo 2896
                                     fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = 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");
7783 schaersvoo 2897
                                }
2898
                                else
2899
                                {
2900
                                    canvas_error("interactive clock may not be used together with other reply_types...");
2901
                                }
8001 schaersvoo 2902
                                fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H&minus;\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M&minus;\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S&minus;\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt);
7783 schaersvoo 2903
                             }
2904
                    break;
2905
                    case 2:if( reply_format == 0 ){
2906
                                reply_format = 19; /* "onclick */
2907
                                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 ");
2908
                            }
2909
                            else
2910
                            {
2911
                                if( reply_format != 19){
7614 schaersvoo 2912
                                   canvas_error("clickable clock(s) may not be used together with other reply_types...");
2913
                                 }
7783 schaersvoo 2914
                            }
2915
                     break;
2916
                     default: canvas_error("interactive must be set 0,1 or 2");break;
2917
                }
2918
                break;
7956 schaersvoo 2919
                case 8:
8000 schaersvoo 2920
                        fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
7614 schaersvoo 2921
                        temp = get_string(infile,1);
2922
                        if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
2923
                        if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";}
2924
                        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);
2925
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2926
                        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);
2927
                        add_to_buffer(tmp_buffer);
2928
                        clock_cnt++;
2929
                        break;
2930
                default:break;
2931
             }
2932
            }
2933
            break;
2934
        case PIECHART:
2935
        /*
2936
        @ piechart xc,yc,radius,'data+colorlist'
2937
        @ (xc : yc) center of circle diagram in xrange/yrange
2938
        @ radius in pixels
2939
        @ 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
2940
        @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
2941
        @ the number of colors must match the number of data.
2942
        @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours
7956 schaersvoo 2943
        @ 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...<br />use command 'fontfamily' to set the font of the legend.
7614 schaersvoo 2944
        */
7956 schaersvoo 2945
            if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}    
7614 schaersvoo 2946
            for(i=0;i<5;i++){
2947
                switch(i){
2948
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2949
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2950
                    case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
2951
                    case 3: temp = get_string(infile,1);
2952
                            if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
7956 schaersvoo 2953
                            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,legend_cnt,font_family);
7614 schaersvoo 2954
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7956 schaersvoo 2955
                            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,legend_cnt,font_family);
7614 schaersvoo 2956
                            add_to_buffer(tmp_buffer);
2957
                           break;
2958
                    default:break;
2959
                }
2960
            }
2961
            reset();
2962
        break;
2963
        case STATUS:
7877 schaersvoo 2964
        /*
2965
        @status
2966
        @keyword
2967
        @alernative keyword: nostatus
2968
        @used to override the effects of "status=done" in wims (answer.phtml)
2969
        @affects inputfields / textarea's in canvasimage and all userdraw based commands
2970
        @e.g.: if keyword 'status' is set, the pupil will be able to modify the canvas when the 'wims status variable' is set to 'done'
2971
        */
7956 schaersvoo 2972
 
7877 schaersvoo 2973
            fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
7614 schaersvoo 2974
            break;
7735 schaersvoo 2975
        case XLOGBASE:
7729 schaersvoo 2976
        /*
7735 schaersvoo 2977
        @ xlogbase number
2978
        @ sets the logbase number for the x-axis
7729 schaersvoo 2979
        @ default value 10
7735 schaersvoo 2980
        @ use together with commands xlogscale / xylogscale
7729 schaersvoo 2981
        */
7735 schaersvoo 2982
            fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
7729 schaersvoo 2983
            break;
7735 schaersvoo 2984
        case YLOGBASE:
2985
        /*
2986
        @ ylogbase number
2987
        @ sets the logbase number for the y-axis
2988
        @ default value 10
2989
        @ use together with commands ylogscale / xylogscale
2990
        */
2991
            fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
2992
            break;
7614 schaersvoo 2993
        case XLOGSCALE:
2994
        /*
7735 schaersvoo 2995
         @ xlogscale ymajor,yminor,majorcolor,minorcolor
2996
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
2997
         @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
2998
         @ the linewidth is set using command 'linewidth int'
2999
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
3000
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
7956 schaersvoo 3001
         @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'xlogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
7735 schaersvoo 3002
         @ note: the complete canvas will be used for the 'log paper'
3003
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3004
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
7956 schaersvoo 3005
         @ note: when using something like 'xrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')  
7735 schaersvoo 3006
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3007
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
7614 schaersvoo 3008
        */
7735 schaersvoo 3009
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3010
            if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
3011
            for(i=0;i<4;i++){
3012
                switch(i){
3013
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
3014
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
3015
                    case 2: stroke_color = get_color(infile,0); break;
7956 schaersvoo 3016
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 3017
                        string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
7735 schaersvoo 3018
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3019
                        snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
7735 schaersvoo 3020
                        fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
3021
                        add_to_buffer(tmp_buffer);
3022
                        break;
3023
                    default:break;
3024
                }
3025
            }
7614 schaersvoo 3026
            break;
3027
        case YLOGSCALE:
7729 schaersvoo 3028
        /*
3029
         @ ylogscale xmajor,xminor,majorcolor,minorcolor
3030
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
3031
         @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
3032
         @ the linewidth is set using command 'linewidth int'
3033
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
7735 schaersvoo 3034
         @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
7956 schaersvoo 3035
         @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'ylogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
7729 schaersvoo 3036
         @ note: the complete canvas will be used for the 'log paper'
3037
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3038
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
7956 schaersvoo 3039
         @ note: when using something like 'yrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')  
7735 schaersvoo 3040
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3041
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
7729 schaersvoo 3042
        */
3043
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3044
            if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
3045
            for(i=0;i<4;i++){
3046
                switch(i){
3047
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
3048
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
3049
                    case 2: stroke_color = get_color(infile,0); break;
7956 schaersvoo 3050
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 3051
                        string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
7729 schaersvoo 3052
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3053
                        snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
7735 schaersvoo 3054
                        fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
7729 schaersvoo 3055
                        add_to_buffer(tmp_buffer);
3056
                        break;
3057
                    default:break;
3058
                }
3059
            }
7614 schaersvoo 3060
            break;
3061
        case XYLOGSCALE:
7735 schaersvoo 3062
        /*
3063
         @ xylogscale majorcolor,minorcolor
3064
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
3065
         @ the linewidth is set using command 'linewidth int'
3066
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
3067
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
7956 schaersvoo 3068
         @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
7735 schaersvoo 3069
         @ note: the complete canvas will be used for the 'log paper'
3070
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3071
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
7956 schaersvoo 3072
         @ note: when using something like 'yrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')  
7735 schaersvoo 3073
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3074
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
3075
        */
3076
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3077
            if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
3078
            for(i=0;i<2;i++){
3079
                switch(i){
3080
                    case 0: stroke_color = get_color(infile,0); break;
7956 schaersvoo 3081
                    case 1: fill_color = get_color(infile,1);
7779 schaersvoo 3082
                        string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision);
7735 schaersvoo 3083
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3084
                        snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision);
7735 schaersvoo 3085
                        fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
3086
                        add_to_buffer(tmp_buffer);
3087
                        break;
3088
                    default:break;
3089
                }
3090
            }
3091
        break;
7614 schaersvoo 3092
        default:sync_input(infile);
3093
        break;
3094
    }
7956 schaersvoo 3095
  }
7614 schaersvoo 3096
  /* we are done parsing script file */
7983 schaersvoo 3097
  /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
3098
  if( found_size_command == 1 ){
3099
    fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
3100
  }
3101
  else
3102
  {
3103
    if( found_size_command != 3 ){
3104
     canvas_error("Please specify bothe xrange and yrange ...");
3105
    }
3106
  }
7614 schaersvoo 3107
  /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable shapes / objects  ! */
3108
  add_javascript_functions(js_function,canvas_root_id);
3109
   /* add read_canvas() etc functions if needed */
8074 schaersvoo 3110
  if( reply_format > 0 ){ add_read_canvas(reply_format,reply_precision);}
7797 schaersvoo 3111
  if( use_pan_and_zoom == TRUE ){
3112
  /* in case of zooming ... */
7729 schaersvoo 3113
  fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
7797 schaersvoo 3114
  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
7729 schaersvoo 3115
  var ymin_start=ymin;var ymax_start=xmax;\
3116
  var zoom_x_increment=0;var zoom_y_increment=0;\
3117
  var pan_x_increment=0;var pan_y_increment=0;\
3118
  if(use_ylogscale == 0 ){\
7956 schaersvoo 3119
   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
7729 schaersvoo 3120
  }else{\
3121
   zoom_x_increment = (xmax - xmin)/20;\
3122
   pan_x_increment = (xmax - xmin)/20;\
3123
  };\
7653 schaersvoo 3124
  function start_canvas%d(type){\
3125
   switch(type){\
7729 schaersvoo 3126
    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
3127
    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
7653 schaersvoo 3128
    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
3129
    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
3130
    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
3131
    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
3132
    case 6:location.reload();break;\
3133
    default:break;\
3134
   };\
3135
   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
3136
   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
3137
   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\
3138
   %s\
3139
  };\
7797 schaersvoo 3140
  start_canvas%d(333);\
7614 schaersvoo 3141
 };\n\
3142
<!-- end wims_canvas_function -->\n\
7797 schaersvoo 3143
wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
3144
  }
3145
  else
3146
  {
3147
  /* no zoom, just add buffer */
3148
  fprintf(js_include_file,"\n<!-- add buffer -->\n\
3149
  %s\
3150
 };\n\
3151
<!-- end wims_canvas_function -->\n\
3152
wims_canvas_function%d();\n",buffer,canvas_root_id);
3153
  }
7614 schaersvoo 3154
/* done writing the javascript include file */
3155
fclose(js_include_file);
3156
 
3157
}
3158
 
3159
/* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
3160
if(use_tooltip == TRUE){
3161
  add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
3162
}
3163
exit(EXIT_SUCCESS);
3164
}
3165
/* end main() */
3166
 
3167
/******************************************************************************
3168
**
3169
**  sync_input
3170
**
3171
**  synchronises input line - reads to end of line, leaving file pointer
3172
**  at first character of next line.
3173
**
3174
**  Used by:
3175
**  main program - error handling.
3176
**
3177
******************************************************************************/
3178
void sync_input(FILE *infile)
3179
{
3180
        int c = 0;
3181
 
7658 schaersvoo 3182
        if( c == '\n' || c == ';' ) return;
3183
        while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
7614 schaersvoo 3184
        if( c == EOF ) finished = 1;
7658 schaersvoo 3185
        if( c == '\n' || c == '\r' || c == ';') line_number++;
7614 schaersvoo 3186
        return;
3187
}
3188
 
3189
/******************************************************************************/
3190
 
3191
char *str_replace(const char *str, const char *old, const char *new){
3192
/* http://creativeandcritical.net/str-replace-c/ */
3193
    if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
3194
    char *ret, *r;
3195
    const char *p, *q;
3196
    size_t oldlen = strlen(old);
3197
    size_t count = 0;
3198
    size_t retlen = 0;
3199
    size_t newlen = strlen(new);
3200
    if (oldlen != newlen){
3201
        for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
3202
            count++;
3203
            retlen = p - str + strlen(p) + count * (newlen - oldlen);
3204
        }
7956 schaersvoo 3205
    }
7614 schaersvoo 3206
    else
3207
    {
3208
        retlen = strlen(str);
3209
    }
7956 schaersvoo 3210
 
7614 schaersvoo 3211
    if ((ret = malloc(retlen + 1)) == NULL){
3212
        ret = NULL;
3213
        canvas_error("string argument is NULL");
3214
    }
3215
    else
3216
    {
3217
        for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
3218
            size_t l = q - p;
3219
            memcpy(r, p, l);
3220
            r += l;
3221
            memcpy(r, new, newlen);
3222
            r += newlen;
3223
        }
3224
        strcpy(r, p);
3225
    }
3226
    return ret;
3227
}
3228
 
3229
/******************************************************************************/
7848 bpr 3230
 
7614 schaersvoo 3231
char *get_color(FILE *infile , int last){
3232
    int c,i = 0,is_hex = 0;
3233
    char temp[MAX_COLOR_STRING], *string;
7748 schaersvoo 3234
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
7614 schaersvoo 3235
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
3236
        if( c == '#' ){
3237
            is_hex = 1;
3238
        }
3239
        if( c != ' '){
3240
            temp[i]=tolower(c);
3241
            i++;
3242
        }
3243
    }
7956 schaersvoo 3244
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3245
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
7614 schaersvoo 3246
    if( c == EOF ){finished = 1;}
3247
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
3248
    temp[i]='\0';
3249
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
3250
    if( is_hex == 1 ){
3251
        char red[3], green[3], blue[3];
3252
        red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
3253
        green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
3254
        blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
3255
        int r = (int) strtol(red,   NULL, 16);
3256
        int g = (int) strtol(green, NULL, 16);
3257
        int b = (int) strtol(blue,  NULL, 16);
3258
        string = (char *)my_newmem(12);
3259
        snprintf(string,11,"%d,%d,%d",r,g,b);
3260
        return string;
3261
    }
3262
    else
3263
    {
3264
        string = (char *)my_newmem(sizeof(temp));
3265
        snprintf(string,sizeof(temp),"%s",temp);
3266
        for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){
3267
            if( strcmp( colors[i].name , string ) == 0 ){
3268
                return colors[i].rgb;
3269
            }
3270
        }
3271
    }
3272
    /* not found...return error */
3273
    free(string);string = NULL;
3274
    canvas_error("I was expecting a color name or hexnumber...but found nothing.");
3275
    return NULL;
3276
}
3277
 
3278
char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
3279
    int c,i=0;
3280
    char  temp[MAX_BUFFER], *string;
7748 schaersvoo 3281
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
7614 schaersvoo 3282
        temp[i]=c;
3283
        i++;
3284
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
3285
    }
7956 schaersvoo 3286
    if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3287
    if( c == '\n') { done = TRUE; line_number++; }
7614 schaersvoo 3288
    if( c == EOF ) {
3289
        finished = 1;
3290
        if( last != 1 ){ canvas_error("expected more arguments");}
3291
    }
3292
    temp[i]='\0';
3293
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
3294
    string=(char *)my_newmem(strlen(temp));
3295
    snprintf(string,sizeof(temp),"%s",temp);
3296
    return string;
3297
}
3298
 
3299
char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
3300
    int c,i=0;
3301
    char temp[MAX_BUFFER], *string;
7748 schaersvoo 3302
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
7614 schaersvoo 3303
        temp[i]=c;
3304
        i++;
3305
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
3306
    }
7956 schaersvoo 3307
    if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3308
    if( c == '\n') { line_number++; }
7614 schaersvoo 3309
    if( c == EOF ) {finished = 1;}
3310
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
3311
    temp[i]='\0';
3312
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
3313
    string=(char *)my_newmem(sizeof(temp));
3314
    snprintf(string,sizeof(temp),"%s",temp);
3315
    done = TRUE;
3316
    return string;
3317
}
3318
 
3319
double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
3320
    int c,i=0,found_calc = 0;
3321
    double y;
3322
    char tmp[MAX_INT];
7658 schaersvoo 3323
    while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
7614 schaersvoo 3324
     if( c != ' ' ){
7956 schaersvoo 3325
     /*
3326
     libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used
7614 schaersvoo 3327
     We will check after assert() if it's a NULL pointer...and exit program via :
3328
     canvas_error("I'm having trouble parsing your \"expression\" ");
3329
     */
7956 schaersvoo 3330
      if( i == 0 &&  c == '+' ){
7614 schaersvoo 3331
       continue;
7956 schaersvoo 3332
      }
7614 schaersvoo 3333
      else
3334
      {
3335
       if(canvas_iscalculation(c) != 0){
3336
        found_calc = 1;
3337
        c = tolower(c);
3338
       }
3339
       tmp[i] = c;
3340
       i++;
3341
      }
3342
     }
3343
     if( i > MAX_INT - 1){canvas_error("number too large");}
3344
    }
7956 schaersvoo 3345
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
7658 schaersvoo 3346
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
7614 schaersvoo 3347
    if( c == EOF ){done = TRUE ; finished = 1;}
3348
    tmp[i]='\0';
3349
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
3350
    if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
7848 bpr 3351
     void *f = eval_create(tmp);
7614 schaersvoo 3352
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
7848 bpr 3353
     y = eval_x(f, 1);
7614 schaersvoo 3354
     /* if function is bogus; y = 1 : so no core dumps */
7848 bpr 3355
     eval_destroy(f);
7614 schaersvoo 3356
    }
3357
    else
3358
    {
3359
     y = atof(tmp);
3360
    }
3361
    return y;
3362
}
3363
void canvas_error(char *msg){
7748 schaersvoo 3364
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
7614 schaersvoo 3365
    finished = 1;
3366
    exit(EXIT_SUCCESS);
3367
}
3368
 
3369
 
3370
/* convert x/y coordinates to pixel */
3371
int x2px(double x){
3372
 return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
3373
}
3374
 
3375
int y2px(double y){
3376
 return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
3377
}
3378
 
3379
double px2x(int x){
3380
 return (x*(xmax - xmin)/xsize + xmin);
3381
}
3382
double px2y(int y){
3383
 return (y*(ymax - ymin)/ysize + ymin);
3384
}
3385
 
3386
void add_to_buffer(char *tmp){
3387
 if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
3388
 /*  do we have enough space left in buffer[MAX_BUFFER] ? */
3389
 int space_left = (int) (sizeof(buffer) - strlen(buffer));
3390
 if( space_left > strlen(tmp)){
3391
  strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
3392
 }
3393
 else
3394
 {
3395
  canvas_error("buffer is too big\n");
3396
 }
3397
 tmp = NULL;free(tmp);
3398
 return;
3399
}
3400
 
3401
void reset(){
3402
 if(use_filled == TRUE){use_filled = FALSE;}
3403
 if(use_dashed == TRUE){use_dashed = FALSE;}
3404
 if(use_rotate == TRUE){use_rotate = FALSE;}
8101 schaersvoo 3405
   onclick = 0;
7614 schaersvoo 3406
}
3407
 
3408
 
3409
 
3410
/* What reply format in read_canvas();
3411
 
3412
note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
3413
1 = x1,x2,x3,x4....x_n
3414
    y1,y2,y3,y4....y_n
3415
 
3416
    x/y in pixels
3417
 
3418
2 = x1,x2,x3,x4....x_n
3419
    y1,y2,y3,y4....y_n
3420
    x/y in  xrange / yrange coordinate system
3421
 
3422
3 = x1,x2,x3,x4....x_n
3423
    y1,y2,y3,y4....y_n
3424
    r1,r2,r3,r4....r_n
3425
 
7956 schaersvoo 3426
    x/y in pixels
7614 schaersvoo 3427
    r in pixels
3428
 
3429
4 = x1,x2,x3,x4....x_n
3430
    y1,y2,y3,y4....y_n
3431
    r1,r2,r3,r4....r_n
3432
 
3433
    x/y in  xrange / yrange coordinate system
3434
    r in pixels
3435
 
3436
5 = Ax1,Ax2,Ax3,Ax4....Ax_n
3437
    Ay1,Ay2,Ay3,Ay4....Ay_n
3438
    Bx1,Bx2,Bx3,Bx4....Bx_n
3439
    By1,By2,By3,By4....By_n
3440
    Cx1,Cx2,Cx3,Cx4....Cx_n
3441
    Cy1,Cy2,Cy3,Cy4....Cy_n
3442
    ....
3443
    Zx1,Zx2,Zx3,Zx4....Zx_n
3444
    Zy1,Zy2,Zy3,Zy4....Zy_n
7956 schaersvoo 3445
 
7614 schaersvoo 3446
    x/y in pixels
3447
 
3448
6 = Ax1,Ax2,Ax3,Ax4....Ax_n
3449
    Ay1,Ay2,Ay3,Ay4....Ay_n
3450
    Bx1,Bx2,Bx3,Bx4....Bx_n
3451
    By1,By2,By3,By4....By_n
3452
    Cx1,Cx2,Cx3,Cx4....Cx_n
3453
    Cy1,Cy2,Cy3,Cy4....Cy_n
3454
    ....
3455
    Zx1,Zx2,Zx3,Zx4....Zx_n
3456
    Zy1,Zy2,Zy3,Zy4....Zy_n
3457
 
3458
    x/y in  xrange / yrange coordinate system
7956 schaersvoo 3459
 
7614 schaersvoo 3460
7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
7956 schaersvoo 3461
 
7614 schaersvoo 3462
    x/y in pixels
3463
 
3464
8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
7956 schaersvoo 3465
 
7614 schaersvoo 3466
    x/y in  xrange / yrange coordinate system
3467
 
7956 schaersvoo 3468
9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
7614 schaersvoo 3469
 
3470
    x/y in pixels
3471
 
7956 schaersvoo 3472
10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n    
7614 schaersvoo 3473
 
3474
    x/y in  xrange / yrange coordinate system
3475
 
3476
11 = Ax1,Ay1,Ax2,Ay2
3477
     Bx1,By1,Bx2,By2
3478
     Cx1,Cy1,Cx2,Cy2
3479
     Dx1,Dy1,Dx2,Dy2
3480
     ......
3481
     Zx1,Zy1,Zx2,Zy2
7956 schaersvoo 3482
 
7614 schaersvoo 3483
    x/y in  xrange / yrange coordinate system
3484
 
3485
12 = Ax1,Ay1,Ax2,Ay2
3486
     Bx1,By1,Bx2,By2
3487
     Cx1,Cy1,Cx2,Cy2
3488
     Dx1,Dy1,Dx2,Dy2
3489
     ......
3490
     Zx1,Zy1,Zx2,Zy2
7956 schaersvoo 3491
 
7614 schaersvoo 3492
    x/y in pixels
3493
 
3494
13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
3495
 
3496
    x/y in  xrange / yrange coordinate system
3497
14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
3498
    x/y in pixels
3499
15 = reply from inputfields,textareas
3500
    reply1,reply2,reply3,...,reply_n
7984 schaersvoo 3501
    only fields set write (a.g. will not read 'readonly' inputfield values'
7614 schaersvoo 3502
 
3503
16 = read mathml inputfields only
3504
 
3505
17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
3506
 when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
3507
 
3508
18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
3509
19 = return clicked object number (analogue to shape-library onclick)
3510
20 = return x/y-data in x-range/y-range of all 'draggable' images
3511
21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
3512
22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
3513
    x/y in  xrange / yrange coordinate system
7956 schaersvoo 3514
23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
7984 schaersvoo 3515
24 = read all inputfield values: even those set 'readonly'
8083 schaersvoo 3516
25 = return all userdrawn arcs in degrees:
3517
26 = return all userdrawn arcs in radians:
7614 schaersvoo 3518
*/
3519
 
3520
 
8074 schaersvoo 3521
void add_read_canvas(int type_reply,int reply_precision){
7614 schaersvoo 3522
/* just 1 reply type allowed */
8074 schaersvoo 3523
fprintf(js_include_file,"\
3524
\n<!-- begin set_reply_precision() -->\n\
3525
function set_reply_precision(){\
3526
 var len = userdraw_x.length;\
3527
 var prec = %d;\
3528
 for(var p = 0 ; p < len ; p++ ){\
3529
  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
3530
  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
3531
 };\
3532
 len = userdraw_radius.length;\
3533
 if( len > 0 ){\
3534
  for(var p = 0 ; p < len ; p++ ){\
3535
   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
3536
  };\
3537
 };\
3538
};",reply_precision);
7963 schaersvoo 3539
 
7614 schaersvoo 3540
switch(type_reply){
8074 schaersvoo 3541
/*  
7614 schaersvoo 3542
answers may have:
3543
x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
3544
*/
3545
    case 1: fprintf(js_include_file,"\
7653 schaersvoo 3546
\n<!-- begin function 1 read_canvas() -->\n\
7614 schaersvoo 3547
function read_canvas(){\
3548
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3549
 set_reply_precision();\
7614 schaersvoo 3550
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3551
  var p = 0;var input_reply = new Array();\
3552
  if( document.getElementById(\"canvas_input0\")){\
3553
   var t = 0;\
3554
   while(document.getElementById(\"canvas_input\"+t)){\
3555
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3556
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3557
     p++;\
3558
    };\
3559
    t++;\
3560
   };\
3561
  };\
3562
  if( typeof userdraw_text != 'undefined' ){\
3563
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
3564
  }\
3565
  else\
3566
  {\
3567
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
3568
  }\
3569
 }\
3570
 else\
3571
 {\
3572
  if( typeof userdraw_text != 'undefined' ){\
3573
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
3574
  }\
3575
  else\
3576
  {\
3577
   return userdraw_x+\"\\n\"+userdraw_y;\
3578
  }\
3579
 };\
3580
};\
3581
this.read_canvas = read_canvas;\n\
7653 schaersvoo 3582
<!-- end function 1 read_canvas() -->");
7614 schaersvoo 3583
    break;
3584
    case 2: fprintf(js_include_file,"\
7653 schaersvoo 3585
\n<!-- begin function 2 read_canvas() -->\n\
7614 schaersvoo 3586
function read_canvas(){\
3587
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3588
 set_reply_precision();\
7614 schaersvoo 3589
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
8074 schaersvoo 3590
 var prec = %d;\
7614 schaersvoo 3591
 while(userdraw_x[p]){\
8074 schaersvoo 3592
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
3593
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 3594
  p++;\
3595
 };\
3596
 if(p == 0){alert(\"nothing drawn...\");return;};\
3597
 if( document.getElementById(\"canvas_input0\")){\
3598
  var p = 0;var input_reply = new Array();\
3599
  if( document.getElementById(\"canvas_input0\")){\
3600
   var t = 0;\
3601
   while(document.getElementById(\"canvas_input\"+t)){\
3602
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3603
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3604
     p++;\
3605
    };\
3606
    t++;\
3607
   };\
3608
  };\
3609
  if( typeof userdraw_text != 'undefined' ){\
3610
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3611
  }\
3612
  else\
3613
  {\
3614
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
3615
  }\
3616
 }\
3617
 else\
3618
 {\
3619
  if( typeof userdraw_text != 'undefined' ){\
3620
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
3621
  }\
3622
  else\
3623
  {\
3624
   return reply_x+\"\\n\"+reply_y;\
3625
  };\
3626
 };\
3627
};\
3628
this.read_canvas = read_canvas;\n\
8074 schaersvoo 3629
<!-- end function 2 read_canvas() -->",reply_precision);
7614 schaersvoo 3630
    break;
3631
    case 3: fprintf(js_include_file,"\
7653 schaersvoo 3632
\n<!-- begin function 3 read_canvas() -->\n\
7614 schaersvoo 3633
function read_canvas(){\
3634
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3635
 set_reply_precision();\
7614 schaersvoo 3636
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3637
  var p = 0;var input_reply = new Array();\
3638
  if( document.getElementById(\"canvas_input0\")){\
3639
   var t = 0;\
3640
   while(document.getElementById(\"canvas_input\"+t)){\
3641
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3642
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3643
     p++;\
3644
    };\
3645
    t++;\
3646
   };\
3647
  };\
3648
  if( typeof userdraw_text != 'undefined' ){\
3649
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3650
  }\
3651
  else\
3652
  {\
3653
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
3654
  }\
3655
 }\
3656
 else\
3657
 {\
3658
  if( typeof userdraw_text != 'undefined' ){\
3659
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
3660
  }\
3661
  else\
3662
  {\
3663
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
3664
  }\
3665
 }\
3666
};\
3667
this.read_canvas = read_canvas;\n\
7653 schaersvoo 3668
<!-- end function 3 read_canvas() -->");
7614 schaersvoo 3669
    break;
3670
    case 4: fprintf(js_include_file,"\
7653 schaersvoo 3671
\n<!-- begin function 4 read_canvas() -->\n\
7614 schaersvoo 3672
function read_canvas(){\
8074 schaersvoo 3673
 var prec = %d;\
7614 schaersvoo 3674
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
3675
 while(userdraw_x[p]){\
8074 schaersvoo 3676
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
3677
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
7614 schaersvoo 3678
  p++;\
3679
 };\
3680
 if(p == 0){alert(\"nothing drawn...\");return;};\
3681
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3682
  var p = 0;var input_reply = new Array();\
3683
  if( document.getElementById(\"canvas_input0\")){\
3684
   var t = 0;\
3685
   while(document.getElementById(\"canvas_input\"+t)){\
3686
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3687
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3688
     p++;\
3689
    };\
3690
    t++;\
3691
   };\
3692
  };\
3693
  if( typeof userdraw_text != 'undefined' ){\
3694
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3695
  }\
3696
  else\
3697
  {\
3698
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
3699
  }\
3700
 }\
3701
 else\
3702
 {\
3703
  if( typeof userdraw_text != 'undefined' ){\
3704
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
3705
  }\
3706
  else\
3707
  {\
3708
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
3709
  }\
3710
 };\
3711
};\
3712
this.read_canvas = read_canvas;\n\
8074 schaersvoo 3713
<!-- end function 4 read_canvas() -->",reply_precision);
7614 schaersvoo 3714
    break;
7956 schaersvoo 3715
    /*
3716
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
3717
        used for userdraw multiple paths
7614 schaersvoo 3718
    */
3719
    case 5: fprintf(js_include_file,"\
7653 schaersvoo 3720
\n<!-- begin function 5 read_canvas() -->\n\
7614 schaersvoo 3721
function read_canvas(){\
8074 schaersvoo 3722
 set_reply_precision();\
7614 schaersvoo 3723
 var p = 0;\
3724
 var reply = \"\";\
3725
 for(p = 0; p < userdraw_x.length;p++){\
3726
  if(userdraw_x[p] != null ){\
3727
   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
3728
  };\
3729
 };\
3730
 if(p == 0){alert(\"nothing drawn...\");return;};\
3731
 userdraw_x = [];userdraw_y = [];\
3732
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3733
  var p = 0;var input_reply = new Array();\
3734
  if( document.getElementById(\"canvas_input0\")){\
3735
   var t = 0;\
3736
   while(document.getElementById(\"canvas_input\"+t)){\
3737
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3738
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3739
     p++;\
3740
    };\
3741
    t++;\
3742
   };\
3743
  };\
3744
  if( typeof userdraw_text != 'undefined' ){\
3745
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3746
  }\
3747
  else\
3748
  {\
3749
   return reply +\"\\n\"+input_reply;\
3750
  }\
3751
 }\
3752
 else\
3753
 {\
3754
  if( typeof userdraw_text != 'undefined' ){\
3755
   return reply+\"\\n\"+userdraw_text;\
3756
  }\
3757
  else\
3758
  {\
3759
   return reply;\
3760
  }\
3761
 };\
3762
};\
7905 bpr 3763
this.read_canvas = read_canvas;\n\
7653 schaersvoo 3764
<!-- end function 5 read_canvas() -->");
7614 schaersvoo 3765
    break;
7956 schaersvoo 3766
    /*
3767
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
3768
        used for userdraw multiple paths
7614 schaersvoo 3769
    */
3770
    case 6: fprintf(js_include_file,"\
7653 schaersvoo 3771
\n<!-- begin function 6 read_canvas() -->\n\
7614 schaersvoo 3772
function read_canvas(){\
3773
 var p = 0;\
3774
 var reply = \"\";\
3775
 var tmp_x = new Array();\
3776
 var tmp_y = new Array();\
8074 schaersvoo 3777
 var prec = %d;\
7614 schaersvoo 3778
 for(p = 0 ; p < userdraw_x.length; p++){\
3779
  tmp_x = userdraw_x[p];\
3780
  tmp_y = userdraw_y[p];\
3781
  if(tmp_x != null){\
3782
   for(var i = 0 ; i < tmp_x.length ; i++){\
8074 schaersvoo 3783
    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
3784
    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
7614 schaersvoo 3785
   };\
3786
   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
3787
  };\
3788
 };\
3789
 if(p == 0){alert(\"nothing drawn...\");return;};\
3790
 userdraw_x = [];userdraw_y = [];\
3791
 if( document.getElementById(\"canvas_input0\") ){\
3792
  var p = 0;var input_reply = new Array();\
3793
  if( document.getElementById(\"canvas_input0\")){\
3794
   var t = 0;\
3795
   while(document.getElementById(\"canvas_input\"+t)){\
3796
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3797
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3798
     p++;\
3799
    };\
3800
    t++;\
3801
   };\
3802
  };\
3803
  if( typeof userdraw_text != 'undefined' ){\
3804
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3805
  }\
3806
  else\
3807
  {\
3808
   return reply +\"\\n\"+input_reply;\
3809
  }\
3810
 }\
3811
 else\
3812
 {\
3813
  if( typeof userdraw_text != 'undefined' ){\
3814
   return reply +\"\\n\"+userdraw_text;\
3815
  }\
3816
  else\
3817
  {\
3818
   return reply;\
3819
  }\
3820
 };\
3821
};\
3822
this.read_canvas = read_canvas;\n\
8074 schaersvoo 3823
<!-- end function 6 read_canvas() -->",reply_precision);
7614 schaersvoo 3824
    break;
3825
    case 7: fprintf(js_include_file,"\
7653 schaersvoo 3826
\n<!-- begin function 7 read_canvas() -->\n\
7614 schaersvoo 3827
function read_canvas(){\
8074 schaersvoo 3828
 set_reply_precision();\
7614 schaersvoo 3829
 var reply = new Array();\
3830
 var p = 0;\
3831
 while(userdraw_x[p]){\
3832
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
3833
  p++;\
3834
 };\
3835
 if(p == 0){alert(\"nothing drawn...\");return;};\
3836
 if( document.getElementById(\"canvas_input0\") ){\
3837
  var p = 0;var input_reply = new Array();\
3838
  if( document.getElementById(\"canvas_input0\")){\
3839
   var t = 0;\
3840
   while(document.getElementById(\"canvas_input\"+t)){\
3841
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3842
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3843
     p++;\
3844
    };\
3845
    t++;\
3846
   };\
3847
  };\
3848
  if( typeof userdraw_text != 'undefined' ){\
3849
   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3850
  }\
3851
  else\
3852
  {\
3853
   return reply+\"\\n\"+input_reply;\
3854
  }\
7862 schaersvoo 3855
 }\
7614 schaersvoo 3856
 else\
3857
 {\
3858
  if( typeof userdraw_text != 'undefined' ){\
3859
   return reply+\"\\n\"+userdraw_text;\
3860
  }\
3861
  else\
3862
  {\
3863
   return reply;\
3864
  }\
3865
 };\
3866
};\
3867
this.read_canvas = read_canvas;\n\
7653 schaersvoo 3868
<!-- end function 7 read_canvas() -->");
7614 schaersvoo 3869
    break;
3870
    case 8: fprintf(js_include_file,"\
7653 schaersvoo 3871
\n<!-- begin function 8 read_canvas() -->\n\
7614 schaersvoo 3872
function read_canvas(){\
3873
 var reply = new Array();\
3874
 var p = 0;\
8074 schaersvoo 3875
 var prec = %d;\
7614 schaersvoo 3876
 while(userdraw_x[p]){\
8074 schaersvoo 3877
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 3878
  p++;\
3879
 };\
3880
 if(p == 0){alert(\"nothing drawn...\");return;};\
3881
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3882
  var p = 0;var input_reply = new Array();\
3883
  if( document.getElementById(\"canvas_input0\")){\
3884
   var t = 0;\
3885
   while(document.getElementById(\"canvas_input\"+t)){\
3886
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3887
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3888
     p++;\
3889
    };\
3890
    t++;\
3891
   };\
3892
  };\
3893
  if( typeof userdraw_text != 'undefined' ){\
3894
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3895
  }\
3896
  else\
3897
  {\
3898
   return reply +\"\\n\"+input_reply;\
3899
  }\
3900
 }\
3901
 else\
3902
 {\
3903
  if( typeof userdraw_text != 'undefined' ){\
3904
   return reply +\"\\n\"+userdraw_text;\
3905
  }\
3906
  else\
3907
  {\
3908
   return reply;\
3909
  }\
3910
 };\
3911
};\
3912
this.read_canvas = read_canvas;\n\
8074 schaersvoo 3913
<!-- end function 8 read_canvas() -->",reply_precision);
7614 schaersvoo 3914
    break;
3915
    case 9: fprintf(js_include_file,"\
7653 schaersvoo 3916
\n<!-- begin function 9 read_canvas() -->\n\
7614 schaersvoo 3917
function read_canvas(){\
8074 schaersvoo 3918
 set_reply_precision();\
7614 schaersvoo 3919
 var reply = new Array();\
3920
 var p = 0;\
3921
 while(userdraw_x[p]){\
3922
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
3923
  p++;\
3924
 };\
3925
 if(p == 0){alert(\"nothing drawn...\");return;};\
3926
 if( document.getElementById(\"canvas_input0\") ){\
3927
  var p = 0;var input_reply = new Array();\
3928
  if( document.getElementById(\"canvas_input0\")){\
3929
   var t = 0;\
3930
   while(document.getElementById(\"canvas_input\"+t)){\
3931
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3932
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3933
     p++;\
3934
    };\
3935
    t++;\
3936
   };\
3937
  };\
3938
  if( typeof userdraw_text != 'undefined' ){\
3939
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3940
  }\
3941
  else\
3942
  {\
3943
   return reply +\"\\n\"+input_reply;\
3944
  }\
3945
 }\
3946
 else\
3947
 {\
3948
  if( typeof userdraw_text != 'undefined' ){\
3949
   return reply +\"\\n\"+userdraw_text;\
3950
  }\
3951
  else\
3952
  {\
3953
   return reply;\
3954
  }\
3955
 };\
3956
};\
3957
this.read_canvas = read_canvas;\n\
7653 schaersvoo 3958
<!-- end function 9 read_canvas() -->");
7614 schaersvoo 3959
    break;
3960
    case 10: fprintf(js_include_file,"\
7653 schaersvoo 3961
\n<!-- begin function 10 read_canvas() -->\n\
7614 schaersvoo 3962
function read_canvas(){\
3963
 var reply = new Array();\
3964
 var p = 0;\
8074 schaersvoo 3965
 var prec = %d;\
7614 schaersvoo 3966
 while(userdraw_x[p]){\
8074 schaersvoo 3967
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*userdraw_radius[p]))/prec;\
7614 schaersvoo 3968
  p++;\
3969
 };\
3970
 if(p == 0){alert(\"nothing drawn...\");return;};\
3971
 if( document.getElementById(\"canvas_input0\") ){\
3972
  var p = 0;var input_reply = new Array();\
3973
  if( document.getElementById(\"canvas_input0\")){\
3974
   var t = 0;\
3975
   while(document.getElementById(\"canvas_input\"+t)){\
3976
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3977
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3978
     p++;\
3979
    };\
3980
    t++;\
3981
   };\
3982
  };\
3983
  if( typeof userdraw_text != 'undefined' ){\
3984
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3985
  }\
3986
  else\
3987
  {\
3988
   return reply +\"\\n\"+input_reply;\
3989
  }\
3990
 }\
3991
 else\
3992
 {\
3993
  if( typeof userdraw_text != 'undefined' ){\
3994
   return reply +\"\\n\"+userdraw_text;\
3995
  }\
3996
  else\
3997
  {\
3998
   return reply;\
3999
  }\
4000
 };\
4001
};\
4002
this.read_canvas = read_canvas;\n\
8074 schaersvoo 4003
<!-- end function 10 read_canvas() -->",reply_precision);
7614 schaersvoo 4004
    break;
4005
    case 11: fprintf(js_include_file,"\
7653 schaersvoo 4006
\n<!-- begin function 11 read_canvas() -->\n\
7614 schaersvoo 4007
function read_canvas(){\
4008
 var reply = \"\";\
4009
 var p = 0;\
8074 schaersvoo 4010
 var prec = %d;\
7614 schaersvoo 4011
 while(userdraw_x[p]){\
8074 schaersvoo 4012
  reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\",\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec +\"\\n\" ;\
7614 schaersvoo 4013
  p = p+2;\
4014
 };\
4015
 if(p == 0){alert(\"nothing drawn...\");return;};\
4016
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
4017
  var p = 0;var input_reply = new Array();\
4018
  if( document.getElementById(\"canvas_input0\")){\
4019
   var t = 0;\
4020
   while(document.getElementById(\"canvas_input\"+t)){\
4021
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4022
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4023
     p++;\
4024
    };\
4025
    t++;\
4026
   };\
4027
  };\
4028
  if( typeof userdraw_text != 'undefined' ){\
4029
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4030
  }\
4031
  else\
4032
  {\
4033
   return reply +\"\\n\"+input_reply;\
4034
  }\
4035
 }\
4036
 else\
4037
 {\
4038
  if( typeof userdraw_text != 'undefined' ){\
4039
   return reply +\"\\n\"+userdraw_text;\
4040
  }\
4041
  else\
4042
  {\
4043
   return reply;\
4044
  }\
4045
 };\
4046
};\
4047
this.read_canvas = read_canvas;\n\
8074 schaersvoo 4048
<!-- end function 11 read_canvas() -->",reply_precision);
7614 schaersvoo 4049
    break;
4050
    case 12: fprintf(js_include_file,"\
7653 schaersvoo 4051
\n<!-- begin function 12 read_canvas() -->\n\
7614 schaersvoo 4052
function read_canvas(){\
8074 schaersvoo 4053
 set_reply_precision();\
7614 schaersvoo 4054
 var reply = \"\";\
4055
 var p = 0;\
4056
 for(p = 0; p< userdraw_x.lenght;p = p+2){\
4057
  if(userdraw_x[p] != null){\
4058
    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
4059
  };\
4060
 };\
4061
 if(p == 0){alert(\"nothing drawn...\");return;};\
4062
 if( document.getElementById(\"canvas_input0\") ){\
4063
  var p = 0;var input_reply = new Array();\
4064
  if( document.getElementById(\"canvas_input0\")){\
4065
   var t = 0;\
4066
   while(document.getElementById(\"canvas_input\"+t)){\
4067
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4068
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4069
     p++;\
4070
    };\
4071
    t++;\
4072
   };\
4073
  };\
4074
  if( typeof userdraw_text != 'undefined' ){\
4075
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4076
  }\
4077
  else\
4078
  {\
4079
   return reply +\"\\n\"+input_reply;\
4080
  }\
4081
 }\
4082
 else\
4083
 {\
4084
  if( typeof userdraw_text != 'undefined' ){\
4085
   return reply +\"\\n\"+userdraw_text\
4086
  }\
4087
  else\
4088
  {\
4089
   return reply;\
4090
  }\
4091
 };\
4092
};\
4093
this.read_canvas = read_canvas;\n\
7653 schaersvoo 4094
<!-- end function 12 read_canvas() -->");
7614 schaersvoo 4095
    break;
4096
    case 13: fprintf(js_include_file,"\
7653 schaersvoo 4097
\n<!-- begin function 13 read_canvas() -->\n\
7614 schaersvoo 4098
function read_canvas(){\
4099
 var reply = new Array();\
4100
 var p = 0;var i = 0;\
8074 schaersvoo 4101
 var prec = %d;\
7614 schaersvoo 4102
 while(userdraw_x[p]){\
8074 schaersvoo 4103
  reply[i] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec;\
7614 schaersvoo 4104
  p = p+2;i++;\
4105
 };\
4106
 if(p == 0){alert(\"nothing drawn...\");return;};\
4107
 if( document.getElementById(\"canvas_input0\") ){\
4108
  var p = 0;var input_reply = new Array();\
4109
  if( document.getElementById(\"canvas_input0\")){\
4110
   var t = 0;\
4111
   while(document.getElementById(\"canvas_input\"+t)){\
4112
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4113
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4114
     p++;\
4115
    };\
4116
    t++;\
4117
   };\
4118
  };\
4119
  if( typeof userdraw_text != 'undefined' ){\
4120
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4121
  }\
4122
  else\
4123
  {\
4124
   return reply +\"\\n\"+input_reply;\
4125
  }\
4126
 }\
4127
 else\
4128
 {\
4129
  if( typeof userdraw_text != 'undefined' ){\
4130
   return reply +\"\\n\"+userdraw_text\
4131
  }\
4132
  else\
4133
  {\
4134
   return reply;\
4135
  }\
4136
 };\
4137
};\
4138
this.read_canvas = read_canvas;\n\
8074 schaersvoo 4139
<!-- end function 13 read_canvas() -->",reply_precision);
7614 schaersvoo 4140
    break;
4141
    case 14: fprintf(js_include_file,"\
7653 schaersvoo 4142
\n<!-- begin function 14 read_canvas() -->\n\
7614 schaersvoo 4143
function read_canvas(){\
8074 schaersvoo 4144
 set_reply_precision();\
7614 schaersvoo 4145
 var reply = new Array();\
4146
 var p = 0;var i = 0;\
4147
 while(userdraw_x[p]){\
4148
  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
4149
  p = p+2;i++;\
4150
 };\
4151
 if(p == 0){alert(\"nothing drawn...\");return;};\
4152
 if( document.getElementById(\"canvas_input0\") ){\
4153
  var p = 0;var input_reply = new Array();\
4154
  if( document.getElementById(\"canvas_input0\")){\
4155
   var t = 0;\
4156
   while(document.getElementById(\"canvas_input\"+t)){\
4157
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4158
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4159
     p++;\
4160
    };\
4161
    t++;\
4162
   };\
4163
  };\
4164
  if( typeof userdraw_text != 'undefined' ){\
4165
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4166
  }\
4167
  else\
4168
  {\
4169
   return reply +\"\\n\"+input_reply;\
4170
  }\
4171
 }\
4172
 else\
4173
 {\
4174
  if( typeof userdraw_text != 'undefined' ){\
4175
   return reply +\"\\n\"+userdraw_text;\
4176
  }\
4177
  else\
4178
  {\
4179
   return reply;\
4180
  }\
4181
 };\
4182
};\
4183
 this.read_canvas = read_canvas;\n\
7653 schaersvoo 4184
<!-- end function 14 read_canvas() -->");
7614 schaersvoo 4185
    break;
4186
    case 15: fprintf(js_include_file,"\
7653 schaersvoo 4187
\n<!-- begin function 15  read_canvas() -->\n\
7614 schaersvoo 4188
function read_canvas(){\
4189
 var input_reply = new Array();\
4190
 var p = 0;\
4191
 if( document.getElementById(\"canvas_input0\")){\
4192
  var t = 0;\
4193
  while(document.getElementById(\"canvas_input\"+t)){\
4194
   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4195
    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4196
    p++;\
4197
   };\
4198
   t++;\
4199
  };\
4200
 };\
4201
 if( typeof userdraw_text != 'undefined' ){\
4202
   return input_reply +\"\\n\"+userdraw_text;\
4203
 }\
4204
 else\
4205
 {\
4206
  return input_reply;\
4207
 };\
4208
};\
4209
 this.read_canvas = read_canvas;\n\
7653 schaersvoo 4210
<!-- end function 15 read_canvas() -->");
7614 schaersvoo 4211
    break;
4212
    case 16: fprintf(js_include_file,"\
7653 schaersvoo 4213
\n<!-- begin function 16 read_mathml() -->\n\
7614 schaersvoo 4214
function read_mathml(){\
4215
 var reply = new Array();\
4216
 var p = 0;\
4217
 if( document.getElementById(\"mathml0\")){\
4218
  while(document.getElementById(\"mathml\"+p)){\
4219
   reply[p] = document.getElementById(\"mathml\"+p).value;\
4220
   p++;\
4221
  };\
4222
 };\
4223
return reply;\
4224
};\
4225
this.read_mathml = read_mathml;\n\
7653 schaersvoo 4226
<!-- end function 16 read_mathml() -->");
7614 schaersvoo 4227
    break;
4228
    case 17:  fprintf(js_include_file,"\
7653 schaersvoo 4229
\n<!-- begin function 17 read_canvas() -->\n\
7614 schaersvoo 4230
function read_canvas(){\
4231
 if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
4232
 return userdraw_text;\
4233
};\
4234
this.read_canvas = read_canvas;\n\
7653 schaersvoo 4235
<!-- end function 17 read_canvas() -->");
7614 schaersvoo 4236
    break;
4237
    case 18: fprintf(js_include_file,"\
7653 schaersvoo 4238
\n<!-- begin function 18 read_canvas() -->\n\
7614 schaersvoo 4239
function read_canvas(){\
4240
 var p = 0;\
4241
 var reply = new Array();\
4242
 var name;\
4243
 var t = true;\
8000 schaersvoo 4244
 var h;var m;var s;\
7614 schaersvoo 4245
 while(t){\
8000 schaersvoo 4246
  try{\
4247
   name = eval('clocks'+p);\
4248
   h = name.H;m = name.M;s = name.S;\
4249
   if(s < 0){s = 60 + s;m = m - 1;};\
4250
   if(m < 0){m = 60 + m;h = h - 1;};\
4251
   if(h < 0){h = 12 + h;};\
4252
   h = parseInt((h+m/60+s/3600)%%12);m = parseInt((m + s/60)%%60);s = parseInt(s%%60);\
4253
   reply[p] = h+\":\"+m+\":\"+s;\
4254
   p++;\
4255
  }catch(e){t=false;};\
7614 schaersvoo 4256
 };\
8000 schaersvoo 4257
 if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
7614 schaersvoo 4258
 return reply;\
4259
};\
4260
this.read_canvas = read_canvas;\n\
7653 schaersvoo 4261
<!-- end function 18 read_canvas() -->");
7614 schaersvoo 4262
    break;
4263
    case 19: fprintf(js_include_file,"\
7653 schaersvoo 4264
\n<!-- begin function 19 read_canvas() -->\n\
7614 schaersvoo 4265
function read_canvas(){\
4266
 return reply[0];\
4267
};\
4268
this.read_canvas = read_canvas;\n\
7653 schaersvoo 4269
<!-- end function 19 read_canvas() -->");
7614 schaersvoo 4270
    case 20: fprintf(js_include_file,"\
7653 schaersvoo 4271
\n<!-- begin function 20 read_canvas() -->\n\
7614 schaersvoo 4272
function read_canvas(){\
8074 schaersvoo 4273
 var prec = %d;\
7614 schaersvoo 4274
 var len  = ext_drag_images.length;\
4275
 var reply = new Array(len);\
4276
 for(var p = 0 ; p < len ; p++){\
4277
    var img = ext_drag_images[p];\
8074 schaersvoo 4278
    reply[p] = (Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7614 schaersvoo 4279
 };\
4280
 return reply;\
4281
};\
4282
this.read_canvas = read_canvas;\n\
8074 schaersvoo 4283
<!-- end function 20 read_canvas() -->",reply_precision);
7614 schaersvoo 4284
    break;
4285
    case 21: fprintf(js_include_file,"\
7653 schaersvoo 4286
\n<!-- begin function 21 read_canvas() -->\n\
7614 schaersvoo 4287
function read_canvas(){\
4288
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
4289
 var reply_coord = new Array();var p = 0;\
8074 schaersvoo 4290
 var prec = %d;\
7614 schaersvoo 4291
 while(userdraw_x[p]){\
8074 schaersvoo 4292
  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
7614 schaersvoo 4293
  p++;\
4294
 };\
4295
 if(p == 0){alert(\"nothing drawn...\");return;};\
4296
 if( document.getElementById(\"canvas_input0\") ){\
4297
  var p = 0;var input_reply = new Array();\
4298
  if( document.getElementById(\"canvas_input0\")){\
4299
   var t = 0;\
4300
   while(document.getElementById(\"canvas_input\"+t)){\
4301
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4302
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4303
     p++;\
4304
    };\
4305
    t++;\
4306
   };\
4307
  };\
4308
  if( typeof userdraw_text != 'undefined' ){\
4309
   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4310
  }\
4311
  else\
4312
  {\
4313
   return reply_coord+\"\\n\"+input_reply;\
4314
  }\
4315
 }\
4316
 else\
4317
 {\
4318
  if( typeof userdraw_text != 'undefined' ){\
4319
   return reply_coord+\"\\n\"+userdraw_text;\
4320
  }\
4321
  else\
4322
  {\
4323
   return reply_coord;\
4324
  };\
4325
 };\
4326
};\
4327
this.read_canvas = read_canvas;\n\
8074 schaersvoo 4328
<!-- end function 21 read_canvas() -->",reply_precision);
7614 schaersvoo 4329
    break;
4330
    case 22: fprintf(js_include_file,"\
7653 schaersvoo 4331
\n<!-- begin function 22 read_canvas() -->\n\
7614 schaersvoo 4332
function read_canvas(){\
4333
 var reply = new Array();\
7963 schaersvoo 4334
 var lu = userdraw_x.length;\
4335
 if(lu == 0){alert(\"nothing drawn...\");return;};\
7614 schaersvoo 4336
 var idx = 0;\
8074 schaersvoo 4337
 var prec = %d;\
7963 schaersvoo 4338
 for(var p = 0 ; p < lu ; p++){\
8074 schaersvoo 4339
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
4340
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
7614 schaersvoo 4341
 };\
4342
 if( document.getElementById(\"canvas_input0\") ){\
4343
  var p = 0;var input_reply = new Array();\
4344
  if( document.getElementById(\"canvas_input0\")){\
4345
   var t = 0;\
4346
   while(document.getElementById(\"canvas_input\"+t)){\
4347
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4348
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4349
     p++;\
4350
    };\
4351
    t++;\
4352
   };\
4353
  };\
4354
  if( typeof userdraw_text != 'undefined' ){\
4355
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4356
  }\
4357
  else\
4358
  {\
4359
   return reply +\"\\n\"+input_reply;\
4360
  }\
4361
 }\
4362
 else\
4363
 {\
4364
  if( typeof userdraw_text != 'undefined' ){\
4365
   return reply +\"\\n\"+userdraw_text;\
4366
  }\
4367
  else\
4368
  {\
4369
   return reply;\
4370
  }\
4371
 };\
4372
};\
4373
this.read_canvas = read_canvas;\n\
8074 schaersvoo 4374
<!-- end function 22 read_canvas() -->",reply_precision);
7614 schaersvoo 4375
    break;
7782 schaersvoo 4376
    case 23: fprintf(js_include_file,"\
4377
\n<!-- begin function 23 read_canvas() default 5 px marge -->\n\
4378
function read_canvas(){\
4379
 if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
4380
 var lu = userdraw_x.length;\
4381
 if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
7962 schaersvoo 4382
 var reply_x = new Array();var reply_y = new Array();\
4383
 var marge = 5;var p = 0;\
8074 schaersvoo 4384
 var prec = %d;\
7782 schaersvoo 4385
 for(var i = 0; i < lu - 1 ; i++ ){\
7962 schaersvoo 4386
  if( Math.abs(userdraw_x[i] - userdraw_x[i+1])){\
8074 schaersvoo 4387
   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
7962 schaersvoo 4388
   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
4389
   p++;\
7782 schaersvoo 4390
  };\
8074 schaersvoo 4391
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
7782 schaersvoo 4392
 };\
4393
 if( document.getElementById(\"canvas_input0\")){\
4394
  var p = 0;var input_reply = new Array();\
4395
  if( document.getElementById(\"canvas_input0\")){\
4396
   var t = 0;\
4397
   while(document.getElementById(\"canvas_input\"+t)){\
4398
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4399
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4400
     p++;\
4401
    };\
4402
    t++;\
4403
   };\
4404
  };\
4405
  if( typeof userdraw_text != 'undefined' ){\
4406
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4407
  }\
4408
  else\
4409
  {\
4410
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
4411
  }\
4412
 }\
4413
 else\
4414
 {\
4415
  if( typeof userdraw_text != 'undefined' ){\
4416
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
4417
  }\
4418
  else\
4419
  {\
4420
   return reply_x+\"\\n\"+reply_y;\
4421
  };\
4422
 };\
4423
};\
4424
this.read_canvas = read_canvas;\n\
8074 schaersvoo 4425
<!-- end function 23 read_canvas() -->",reply_precision);
7782 schaersvoo 4426
    break;
7984 schaersvoo 4427
    case 24: fprintf(js_include_file,"\n\
4428
<!-- begin function 24  read_canvas() -->\n\
4429
function read_canvas(){\
4430
 var input_reply = new Array();\
4431
 var p = 0;\
4432
 if( document.getElementById(\"canvas_input0\")){\
4433
  while(document.getElementById(\"canvas_input\"+p)){\
4434
    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
4435
    p++;\
4436
  };\
4437
  return input_reply;\
4438
 };\
4439
};\
4440
this.read_canvas = read_canvas;\n\
4441
<!-- end function 24 read_canvas() -->");
4442
    break;
8083 schaersvoo 4443
    case 25:
4444
    fprintf(js_include_file,"\n<!-- begin function 25 read_canvas() : angle(s) in degrees-->\n\
4445
function read_canvas(){\
4446
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
4447
 var lu = userdraw_radius.length;\
4448
 var prec = %d;\
4449
 var angle_reply = new Array(lu);\
4450
 for(var p = 0 ; p < lu ; p++){\
4451
  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
4452
 };\
4453
 return angle_reply;\
4454
};\
4455
this.read_canvas = read_canvas;\n\
4456
<!-- end function 25 read_canvas() -->",reply_precision);
4457
    break;
4458
    case 26:
4459
    fprintf(js_include_file,"\n<!-- begin function 25 read_canvas() : angle(s) in radians-->\n\
4460
function read_canvas(){\
4461
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
4462
 var lu = userdraw_radius.length;\
4463
 var prec = %d;\
4464
 var angle_reply = new Array(lu);\
4465
 for(var p = 0 ; p < lu ; p++){\
4466
  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
4467
 };\
4468
 return angle_reply;\
4469
};\
4470
this.read_canvas = read_canvas;\n\
4471
<!-- end function 25 read_canvas() -->",reply_precision);
4472
    break;
7614 schaersvoo 4473
    default: canvas_error("hmmm unknown replyformat...");break;
4474
}
4475
 return;
4476
}
4477
 
4478
 
7956 schaersvoo 4479
/*
4480
 add drawfunction :
7614 schaersvoo 4481
 - functions used by userdraw_primitives (circle,rect,path,triangle...)
4482
 - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
4483
 - grid / mathml
4484
 - will not scale or zoom in
4485
 - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
7956 schaersvoo 4486
 - is printed directly into 'js_include_file'
7614 schaersvoo 4487
*/
4488
 
4489
void add_javascript_functions(int js_functions[],int canvas_root_id){
4490
int i;
4491
for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
4492
 if( js_functions[i] == 1){
4493
    switch(i){
4494
    case DRAG_EXTERNAL_IMAGE:
4495
fprintf(js_include_file,"\n<!-- drag external images --->\n\
7653 schaersvoo 4496
var external_canvas = create_canvas%d(7,xsize,ysize);\
4497
var external_ctx = external_canvas.getContext(\"2d\");\
4498
var external_canvas_rect = external_canvas.getBoundingClientRect();\
4499
canvas_div.addEventListener(\"mousedown\",setxy,false);\
4500
canvas_div.addEventListener(\"mouseup\",dragstop,false);\
4501
canvas_div.addEventListener(\"mousemove\",dragxy,false);\
4502
var selected_image = null;\
4503
var ext_image_cnt = 0;\
4504
var ext_drag_images = new Array();\
4505
function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\
4506
 ext_image_cnt = idx;\
4507
 var image = new Image();\
4508
 image.src = URL;\
4509
 image.onload = function(){\
4510
  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\
4511
  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\
4512
  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\
4513
  img = new Array(10);\
4514
  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
4515
  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\
4516
  ext_drag_images[idx] = img;\
4517
  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
4518
 };\
4519
};\
4520
function dragstop(evt){\
4521
 selected_image = null;return;\
4522
};\
4523
function dragxy(evt){\
4524
 if( selected_image != null ){\
4525
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
4526
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
4527
  var s_img = ext_drag_images[selected_image];\
4528
  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
4529
  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
4530
  ext_drag_images[selected_image] = s_img;\
4531
  external_ctx.clearRect(0,0,xsize,ysize);\
4532
  for(var i = 0; i <= ext_image_cnt ; i++){\
4533
   var img = ext_drag_images[i];\
4534
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
4535
  };\
4536
 };\
4537
};\
4538
function setxy(evt){\
4539
 if( ! selected_image && evt.which == 1 ){\
4540
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
4541
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
4542
  var xm = evt.clientX - external_canvas_rect.left + xoff;\
4543
  var ym = evt.clientY - external_canvas_rect.top + yoff;\
4544
  for(var p = 0 ; p <= ext_image_cnt ; p++){\
4545
   var img = ext_drag_images[p];\
4546
   if( img[0] == 1 ){\
4547
    var w = img.width;\
4548
    var h = img.height;\
4549
    if( xm > img[6] && xm < img[6] + img[4]){\
4550
     if( ym > img[7] && ym < img[7] + img[5]){\
4551
      img[6] = xm;\
4552
      img[7] = ym;\
4553
      ext_drag_images[p] = img;\
4554
      selected_image = p;\
4555
      dragxy(evt);\
4556
     };\
4557
    };\
4558
   };\
4559
  };\
4560
 }\
4561
 else\
4562
 {\
4563
  selected_image = null;\
4564
 };\
7614 schaersvoo 4565
};",canvas_root_id);
4566
    break;
4567
 
4568
    case DRAW_EXTERNAL_IMAGE:
4569
fprintf(js_include_file,"\n<!-- draw external images -->\n\
4570
draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
4571
 var image = new Image();\
4572
 image.src = URL;\
4573
 var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
4574
 image.onload = function(){\
4575
  if( x0 < 1 ){ x0 = 0; };\
4576
  if( y0 < 1 ){ y0 = 0; };\
4577
  if( sx < 1 ){ sx = 0; };\
4578
  if( sy < 1 ){ sy = 0; };\
4579
  if( width < 1 ){ width = image.width;};\
4580
  if( height < 1 ){ height = image.height;};\
4581
  if( swidth < 1 ){ swidth = image.width;};\
4582
  if( sheight < 1 ){ sheight = image.height;};\
4583
  var ml = x0 - sx;\
4584
  var mh = y0 - sy;\
4585
  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
4586
  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
4587
  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
4588
  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
4589
  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
4590
 };\
7956 schaersvoo 4591
};",canvas_root_id);    
7614 schaersvoo 4592
    break;
4593
    case DRAW_GRIDFILL:/* not used for userdraw */
4594
fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
4595
draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
4596
 var obj;\
4597
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4598
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4599
 }\
4600
 else\
4601
 {\
4602
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4603
 };\
4604
 var ctx = obj.getContext(\"2d\");\
4605
 var x,y;\
7883 schaersvoo 4606
 snap_x = dx;snap_y = dy;\
7614 schaersvoo 4607
 ctx.save();\
4608
 ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
4609
 for( x = x0 ; x < xsize+dx ; x = x + dx ){\
4610
    ctx.moveTo(x,y0);\
4611
    ctx.lineTo(x,ysize);\
4612
 };\
7645 schaersvoo 4613
 for( y = y0 ; y < ysize+dy; y = y + dy ){\
7614 schaersvoo 4614
    ctx.moveTo(x0,y);\
4615
    ctx.lineTo(xsize,y);\
4616
 };\
4617
 ctx.stroke();\
4618
 ctx.restore();\
7653 schaersvoo 4619
 return;};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4620
    break;
7956 schaersvoo 4621
 
7614 schaersvoo 4622
    case DRAW_IMAGEFILL:/* not  used for userdraw */
4623
fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
4624
draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
4625
 var obj;\
4626
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4627
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4628
 }\
4629
 else\
4630
 {\
4631
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4632
 };\
4633
 var ctx = obj.getContext(\"2d\");\
4634
 ctx.save();\
4635
 var img = new Image();\
4636
 img.src = URL;\
4637
 img.onload = function(){\
4638
  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
4639
    ctx.drawImage(img,x0,y0,xsize,ysize);\
4640
  }\
4641
  else\
4642
  {\
4643
    var repeat = \"repeat\";\
4644
    if(img.width > xsize - x0){\
4645
        repeat = \"repeat-y\";\
4646
    }\
4647
    else\
4648
    {\
4649
     if( img.height > ysize -x0 ){\
4650
      repeat = \"repeat-x\";\
4651
     }\
4652
    }\
4653
    var pattern = ctx.createPattern(img,repeat);\
4654
    ctx.rect(x0,y0,xsize,ysize);\
4655
    ctx.fillStyle = pattern;\
4656
  }\
4657
  ctx.fill();\
4658
 };\
4659
 ctx.restore();\
4660
 return;\
7653 schaersvoo 4661
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4662
    break;
7956 schaersvoo 4663
 
7614 schaersvoo 4664
    case DRAW_DOTFILL:/* not  used for userdraw */
4665
fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
4666
draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
4667
 var obj;\
4668
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4669
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4670
 }\
4671
 else\
4672
 {\
4673
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4674
 };\
4675
 var ctx = obj.getContext(\"2d\");\
4676
 var x,y;\
4677
 ctx.closePath();\
4678
 ctx.save();\
7645 schaersvoo 4679
 snap_x = dx;snap_y = dy;\
7614 schaersvoo 4680
 ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
4681
 for( x = x0 ; x < xsize+dx ; x = x + dx ){\
4682
  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
4683
   ctx.arc(x,y,radius,0,2*Math.PI,false);\
4684
   ctx.closePath();\
4685
  }\
4686
 }\
4687
 ctx.fill();\
4688
 ctx.restore();\
7653 schaersvoo 4689
 return;};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4690
    break;
7645 schaersvoo 4691
 
7647 schaersvoo 4692
    case DRAW_DIAMONDFILL:/* not used for userdraw */
7614 schaersvoo 4693
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
7647 schaersvoo 4694
draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
7614 schaersvoo 4695
  var obj;\
4696
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4697
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4698
 }\
4699
 else\
4700
 {\
4701
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4702
 };\
4703
 var ctx = obj.getContext(\"2d\");\
4704
 var x;\
4705
 var y;\
4706
 ctx.save();\
4707
 ctx.lineWidth = linewidth;\
4708
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4709
 y = ysize;\
4710
 for( x = x0 ; x < xsize ; x = x + dx ){\
4711
  ctx.moveTo(x,y0);\
4712
  ctx.lineTo(xsize,y);\
4713
  y = y - dy;\
4714
 };\
4715
 y = y0;\
4716
 for( x = xsize ; x > 0 ; x = x - dx){\
4717
  ctx.moveTo(x,ysize);\
4718
  ctx.lineTo(x0,y);\
4719
  y = y + dy;\
4720
 };\
4721
 x = x0;\
4722
 for( y = y0 ; y < ysize ; y = y + dy ){\
4723
  ctx.moveTo(xsize,y);\
4724
  ctx.lineTo(x,ysize);\
4725
  x = x + dx;\
4726
 };\
4727
 x = xsize;\
4728
 for( y = ysize ; y > y0 ; y = y - dy ){\
4729
  ctx.moveTo(x,y0);\
4730
  ctx.lineTo(x0,y);\
4731
  x = x - dx;\
4732
 };\
4733
 ctx.stroke();\
4734
 ctx.restore();\
4735
 return;\
7653 schaersvoo 4736
 }",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4737
    break;
7956 schaersvoo 4738
 
7647 schaersvoo 4739
    case DRAW_HATCHFILL:/* not used for userdraw */
4740
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
4741
draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
4742
  var obj;\
4743
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4744
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4745
 }\
4746
 else\
4747
 {\
4748
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4749
 };\
4750
 var ctx = obj.getContext(\"2d\");\
4751
 var x;\
4752
 var y;\
4753
 ctx.save();\
4754
 ctx.lineWidth = linewidth;\
4755
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4756
 y = ysize;\
4757
 for( x = x0 ; x < xsize ; x = x + dx ){\
4758
  ctx.moveTo(x,y0);\
4759
  ctx.lineTo(xsize,y);\
4760
  y = y - dy;\
4761
 };\
4762
 y = y0;\
4763
 for( x = xsize ; x >= dx ; x = x - dx){\
4764
  ctx.moveTo(x,ysize);\
4765
  ctx.lineTo(x0,y);\
4766
  y = y + dy;\
4767
 };\
4768
 ctx.stroke();\
4769
 ctx.restore();\
4770
 return;\
7653 schaersvoo 4771
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7647 schaersvoo 4772
    break;
7614 schaersvoo 4773
    case DRAW_CIRCLES:/*  used for userdraw */
4774
fprintf(js_include_file,"\n<!-- draw circles -->\n\
8071 schaersvoo 4775
draw_circles = function(ctx,x_points,y_points,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 4776
 ctx.save();\
8071 schaersvoo 4777
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 4778
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4779
 ctx.lineWidth = line_width;\
4780
 for(var p = 0 ; p < x_points.length ; p++ ){\
4781
  ctx.beginPath();\
4782
  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
4783
  ctx.closePath();\
4784
  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
4785
  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
4786
  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4787
  ctx.stroke();\
4788
 }\
4789
 ctx.restore();\
4790
 return;\
7653 schaersvoo 4791
};");
7614 schaersvoo 4792
    break;
7663 schaersvoo 4793
    case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
4794
fprintf(js_include_file,"\n<!-- draw polyline -->\n\
8071 schaersvoo 4795
draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7663 schaersvoo 4796
 ctx.save();\
8071 schaersvoo 4797
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7663 schaersvoo 4798
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4799
 ctx.lineWidth = line_width;\
4800
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4801
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
4802
 ctx.clearRect(0,0,xsize,ysize);\
4803
 ctx.beginPath();\
4804
 for(var p = 0 ; p < x_points.length-1 ; p++ ){\
4805
  ctx.moveTo(x_points[p],y_points[p]);\
4806
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
4807
 }\
4808
 ctx.closePath();\
4809
 ctx.stroke();\
4810
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4811
 for(var p = 0 ; p < x_points.length ; p++ ){\
4812
  ctx.beginPath();\
4813
  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
4814
  ctx.closePath();ctx.fill();ctx.stroke();\
4815
 };\
4816
 ctx.restore();\
4817
 return;\
4818
};");
4819
    break;
7956 schaersvoo 4820
 
7614 schaersvoo 4821
    case DRAW_SEGMENTS:/*  used for userdraw */
4822
fprintf(js_include_file,"\n<!-- draw segments -->\n\
8071 schaersvoo 4823
draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 4824
 ctx.save();\
8071 schaersvoo 4825
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 4826
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4827
 ctx.lineWidth = line_width;\
4828
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4829
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
4830
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
4831
  ctx.beginPath();\
4832
  ctx.moveTo(x_points[p],y_points[p]);\
4833
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
4834
  ctx.closePath();\
4835
  ctx.stroke();\
4836
  }\
4837
  ctx.restore();\
4838
  return;\
4839
 };");
4840
    break;
7956 schaersvoo 4841
 
7614 schaersvoo 4842
    case DRAW_LINES:/*  used for userdraw */
4843
fprintf(js_include_file,"\n<!-- draw lines -->\n\
4844
function calc_line(x1,x2,y1,y2){\
4845
 var marge = 2;\
4846
 if(x1 < x2+marge && x1>x2-marge){\
4847
  return [x1,0,x1,ysize];\
4848
 };\
4849
 if(y1 < y2+marge && y1>y2-marge){\
4850
  return [0,y1,xsize,y1];\
4851
 };\
4852
 var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
4853
 var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
4854
 return [0,Y1,xsize,Y2];\
4855
};\
8071 schaersvoo 4856
draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 4857
 ctx.save();\
4858
 var line = new Array(4);\
8071 schaersvoo 4859
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 4860
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4861
 ctx.lineWidth = line_width;\
4862
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4863
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
4864
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
4865
  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
4866
  ctx.beginPath();\
4867
  ctx.moveTo(line[0],line[1]);\
4868
  ctx.lineTo(line[2],line[3]);\
4869
  ctx.closePath();\
4870
  ctx.stroke();\
4871
  }\
4872
  ctx.restore();\
4873
  return;\
4874
 };");
4875
    break;
4876
 
4877
    case DRAW_CROSSHAIRS:/*  used for userdraw */
4878
fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
8071 schaersvoo 4879
draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
4880
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 4881
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4882
 ctx.lineWidth = line_width;\
4883
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4884
 var x1,x2,y1,y2;\
4885
 for(var p = 0 ; p < x_points.length ; p++ ){\
4886
  x1 = x_points[p] - crosshair_size;\
4887
  x2 = x_points[p] + crosshair_size;\
4888
  y1 = y_points[p] - crosshair_size;\
4889
  y2 = y_points[p] + crosshair_size;\
4890
  ctx.beginPath();\
4891
  ctx.moveTo(x1,y1);\
4892
  ctx.lineTo(x2,y2);\
4893
  ctx.closePath();\
4894
  ctx.stroke();\
4895
  ctx.beginPath();\
4896
  ctx.moveTo(x2,y1);\
4897
  ctx.lineTo(x1,y2);\
4898
  ctx.closePath();\
4899
  ctx.stroke();\
4900
 }\
4901
 ctx.restore();\
4902
  return;\
7653 schaersvoo 4903
};");
7614 schaersvoo 4904
    break;
4905
 
4906
    case DRAW_RECTS:/*  used for userdraw */
4907
fprintf(js_include_file,"\n<!-- draw rects -->\n\
8071 schaersvoo 4908
draw_rects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 4909
 ctx.save();\
8071 schaersvoo 4910
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 4911
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4912
 ctx.lineWidth = line_width;\
4913
 ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
4914
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
4915
 for(var p = 0 ; p < x_points.length ; p = p + 2){\
4916
  ctx.beginPath();\
4917
  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
4918
  ctx.closePath();\
4919
  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
4920
  ctx.stroke();\
4921
 };\
4922
 ctx.restore();\
4923
 return;\
7653 schaersvoo 4924
};");
7614 schaersvoo 4925
    break;
4926
 
4927
    case DRAW_ROUNDRECTS:/*  used for userdraw */
4928
fprintf(js_include_file,"\n<!-- draw round rects -->\n\
8071 schaersvoo 4929
draw_roundrects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 4930
 ctx.save();\
8071 schaersvoo 4931
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 4932
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
4933
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4934
 var x,y,w,h,r;\
4935
 for(var p = 0; p < x_points.length; p = p+2){\
4936
  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);\
4937
  ctx.beginPath();ctx.moveTo(x + r, y);\
4938
  ctx.lineTo(x + w - r, y);\
4939
  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
4940
  ctx.lineTo(x + w, y + h - r);\
4941
  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
4942
  ctx.lineTo(x + r, y + h);\
4943
  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
4944
  ctx.lineTo(x, y + r);\
4945
  ctx.quadraticCurveTo(x, y, x + r, y);\
4946
  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
4947
  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4948
  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
4949
  ctx.stroke();\
4950
 }\
4951
 ctx.restore();\
7653 schaersvoo 4952
};");
7956 schaersvoo 4953
    break;
7614 schaersvoo 4954
 
4955
    case DRAW_ELLIPSES:/* not  used for userdraw */
4956
fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
8071 schaersvoo 4957
draw_ellipses = function(canvas_type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 4958
 var obj;\
4959
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4960
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4961
 }\
4962
 else\
4963
 {\
4964
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4965
 };\
4966
 var ctx = obj.getContext(\"2d\");\
4967
 ctx.save();\
8071 schaersvoo 4968
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 4969
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4970
 var cx,cy,ry,rx;\
4971
 ctx.lineWidth = line_width;\
4972
 if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
4973
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
4974
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4975
 for(var p=0;p< x_points.length;p = p+2){\
4976
  ctx.beginPath();\
4977
  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
4978
  ctx.translate(cx - rx, cy - ry);\
4979
  ctx.scale(rx, ry);\
4980
  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
4981
  if( use_filled == 1 ){ctx.fill();}\
4982
  ctx.stroke();\
4983
 };\
4984
 ctx.restore();\
7653 schaersvoo 4985
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4986
    break;
4987
 
4988
    case DRAW_PATHS: /*  used for userdraw */
4989
fprintf(js_include_file,"\n<!-- draw paths -->\n\
8071 schaersvoo 4990
draw_paths = function(ctx,x_points,y_points,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 4991
 ctx.save();\
8071 schaersvoo 4992
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 4993
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
4994
 ctx.lineWidth = line_width;\
4995
 ctx.lineJoin = \"round\";\
4996
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4997
 ctx.beginPath();\
4998
 ctx.moveTo(x_points[0],y_points[0]);\
4999
 for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
5000
 if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
5001
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5002
 if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
5003
 ctx.stroke();\
5004
 ctx.restore();\
5005
 return;\
5006
};");
7956 schaersvoo 5007
 
7614 schaersvoo 5008
    break;
5009
    case DRAW_ARROWS:/*  used for userdraw */
5010
fprintf(js_include_file,"\n<!-- draw arrows -->\n\
8071 schaersvoo 5011
draw_arrows = function(ctx,x_points,y_points,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5012
 ctx.save();\
8071 schaersvoo 5013
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5014
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5015
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5016
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5017
 ctx.lineWidth = line_width;\
5018
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5019
 ctx.lineCap = \"round\";\
5020
 var x1,y1,x2,y2,dx,dy,len;\
5021
 for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
7874 schaersvoo 5022
   ctx.save();\
7614 schaersvoo 5023
   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
5024
   len = Math.sqrt(dx*dx+dy*dy);\
5025
   ctx.translate(x2,y2);\
5026
   ctx.rotate(Math.atan2(dy,dx));\
5027
   ctx.lineCap = \"round\";\
5028
   ctx.beginPath();\
5029
   ctx.moveTo(0,0);\
5030
   ctx.lineTo(-len,0);\
5031
   ctx.closePath();\
5032
   ctx.stroke();\
5033
   ctx.beginPath();\
5034
   ctx.moveTo(0,0);\
5035
   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
5036
   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
5037
   ctx.closePath();\
5038
   ctx.fill();\
7874 schaersvoo 5039
   ctx.restore();\
7614 schaersvoo 5040
   if( type == 2 ){\
5041
     ctx.save();\
5042
     ctx.translate(x1,y1);\
5043
     ctx.rotate(Math.atan2(-dy,-dx));\
5044
     ctx.beginPath();\
5045
     ctx.moveTo(0,0);\
5046
     ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
5047
     ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
5048
     ctx.closePath();\
5049
     ctx.stroke();\
5050
     ctx.fill();\
7874 schaersvoo 5051
     ctx.restore();\
7614 schaersvoo 5052
   }\
5053
  }\
5054
  ctx.restore();\
5055
  return;\
7653 schaersvoo 5056
};");
7614 schaersvoo 5057
    break;
5058
 
5059
    case DRAW_VIDEO:/* not  used for userdraw */
5060
fprintf(js_include_file,"\n<!-- draw video -->\n\
5061
draw_video = function(canvas_root_id,x,y,w,h,URL){\
5062
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5063
 var video_div = document.createElement(\"div\");\
5064
 canvas_div.appendChild(video_div);\
5065
 video_div.style.position = \"absolute\";\
5066
 video_div.style.left = x+\"px\";\
5067
 video_div.style.top = y+\"px\";\
5068
 video_div.style.width = w+\"px\";\
5069
 video_div.style.height = h+\"px\";\
5070
 var video = document.createElement(\"video\");\
5071
 video_div.appendChild(video);\
5072
 video.style.width = w+\"px\";\
5073
 video.style.height = h+\"px\";\
5074
 video.autobuffer = true;\
5075
 video.controls = true;video.autoplay = false;\
5076
 var src = document.createElement(\"source\");\
5077
 src.type = \"video/mp4\";\
5078
 src.src = URL;\
5079
 video.appendChild(src);\
5080
 video.load();\
5081
 return;\
7956 schaersvoo 5082
};");    
7614 schaersvoo 5083
    break;
7956 schaersvoo 5084
 
7614 schaersvoo 5085
    case DRAW_AUDIO:/* not used for userdraw */
5086
fprintf(js_include_file,"\n<!-- draw audio -->\n\
5087
draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
5088
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5089
 var audio_div = document.createElement(\"div\");\
5090
 canvas_div.appendChild(audio_div);\
5091
 audio_div.style.position = \"absolute\";\
5092
 audio_div.style.left = x+\"px\";\
5093
 audio_div.style.top = y+\"px\";\
5094
 audio_div.style.width = w+\"px\";\
5095
 audio_div.style.height = h+\"px\";\
5096
 var audio = document.createElement(\"audio\");\
5097
 audio_div.appendChild(audio);\
5098
 audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
5099
 audio.autobuffer = true;\
5100
 if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
5101
 if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
5102
 var src1 = document.createElement(\"source\");\
5103
 src1.type = \"audio/ogg\";\
5104
 src1.src = URL1;\
5105
 audio.appendChild(src1);\
5106
 var src2 = document.createElement(\"source\");\
5107
 src2.type = \"audio/mpeg\";\
5108
 src2.src = URL2;\
5109
 audio.appendChild(src2);\
5110
 audio.load();\
5111
 return;\
7653 schaersvoo 5112
};");
7614 schaersvoo 5113
    break;
7956 schaersvoo 5114
 
7614 schaersvoo 5115
    case DRAW_HTTP:/* not  used for userdraw */
5116
fprintf(js_include_file,"\n<!-- draw http -->\n\
5117
draw_http = function(canvas_root_id,x,y,w,h,URL){\
5118
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5119
 var http_div = document.createElement(\"div\");\
5120
 var iframe = document.createElement(\"iframe\");\
5121
 canvas_div.appendChild(http_div);\
5122
 http_div.appendChild(iframe);\
5123
 iframe.src = URL;\
5124
 iframe.setAttribute(\"width\",w);\
5125
 iframe.setAttribute(\"height\",h);\
5126
 return;\
7653 schaersvoo 5127
};");
7614 schaersvoo 5128
    break;
7956 schaersvoo 5129
 
7614 schaersvoo 5130
    case DRAW_XML:
5131
fprintf(js_include_file,"\n<!-- draw xml -->\n\
5132
draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
5133
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5134
 var xml_div = document.createElement(\"div\");\
5135
 canvas_div.appendChild(xml_div);\
5136
 xml_div.innerHTML = mathml;\
5137
 if(onclick != 0){\
5138
  xml_div.onclick = function(){\
5139
   reply[0] = onclick;\
5140
   alert(\"send \"+onclick+\" ?\");\
5141
  };\
5142
 };\
5143
 xml_div.style.position = \"absolute\";\
5144
 xml_div.style.left = x+\"px\";\
5145
 xml_div.style.top = y+\"px\";\
5146
 xml_div.style.width = w+\"px\";\
5147
 xml_div.style.height = h+\"px\";\
5148
 return;\
7653 schaersvoo 5149
};"
7614 schaersvoo 5150
);
5151
    break;
7654 schaersvoo 5152
    case DRAW_SGRAPH:
7956 schaersvoo 5153
/*
7654 schaersvoo 5154
 xstart = given
5155
 ystart = given
5156
 sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
5157
*/
5158
fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
7658 schaersvoo 5159
draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
5160
 var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{ obj = create_canvas%d(canvas_type,xsize,ysize);};\
5161
 var ctx = obj.getContext(\"2d\");\
5162
 ctx.font = fontfamily;\
5163
 var minor_opacity = 0.8*opacity;\
5164
 ctx.clearRect(0,0,xsize,ysize);\
7976 schaersvoo 5165
 var zero_x = 0.1*xsize;\
5166
 var zero_y = 0.9*ysize;\
7659 schaersvoo 5167
 var snor_x;\
7654 schaersvoo 5168
 if( xstart != xmin){\
7658 schaersvoo 5169
  snor_x = 0.1*xsize;\
5170
 }\
5171
 else\
5172
 {\
5173
  snor_x = 0;\
5174
  xstart = xmin;\
5175
 };\
5176
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5177
 ctx.lineWidth = 2;\
5178
 ctx.beginPath();\
5179
 ctx.moveTo(xsize,zero_y);\
5180
 ctx.lineTo(zero_x,zero_y);\
5181
 ctx.lineTo(zero_x,0);\
5182
 ctx.stroke();\
5183
 ctx.closePath();\
5184
 ctx.beginPath();\
5185
 ctx.moveTo(zero_x,zero_y);\
5186
 ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
5187
 ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
5188
 ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
5189
 ctx.lineTo(zero_x + snor_x,zero_y);\
5190
 ctx.stroke();\
5191
 ctx.closePath();\
5192
 ctx.beginPath();\
5193
 var num = xstart;\
7660 schaersvoo 5194
 var flipflop = 1;\
7658 schaersvoo 5195
 var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
7976 schaersvoo 5196
 var txtsize;var txt_marge=step_x - 5;\
7658 schaersvoo 5197
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7976 schaersvoo 5198
  txtsize = ctx.measureText(num).width;\
5199
  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
5200
  if( flipflop == 1){\
5201
   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
5202
  }\
5203
  else\
5204
  {\
5205
   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
5206
  }\
5207
  num = num + xmajor;\
7658 schaersvoo 5208
 };\
5209
 ctx.stroke();\
5210
 ctx.closePath();\
5211
 ctx.lineWidth = 1;\
5212
 ctx.beginPath();\
5213
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
5214
   ctx.moveTo(x,zero_y);\
5215
   ctx.lineTo(x,0);\
5216
 };\
5217
 ctx.stroke();\
5218
 ctx.closePath();\
5219
 if( xminor > 1){\
5220
  ctx.lineWidth = 0.5;\
5221
  ctx.beginPath();\
5222
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
5223
  var minor_step_x = step_x / xminor;\
5224
  var nx;\
5225
  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
5226
    num = 1;\
5227
    for(var p = 1 ; p < xminor ; p++){\
5228
     nx = x + num*minor_step_x;\
5229
     ctx.moveTo(nx,zero_y);\
5230
     ctx.lineTo(nx,0);\
5231
     num++;\
5232
    };\
5233
  };\
5234
  ctx.stroke();\
5235
  ctx.closePath();\
5236
  ctx.beginPath();\
5237
  ctx.lineWidth = 2;\
5238
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5239
  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
5240
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
5241
  };\
5242
  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
5243
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
5244
  };\
5245
  ctx.stroke();\
5246
  ctx.closePath();\
5247
  ctx.lineWidth = 0.5;\
5248
 };\
5249
 xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
5250
 if( ystart != ymin){\
5251
  snor_y = 0.1*ysize;\
5252
 }\
5253
 else\
5254
 {\
5255
  snor_y = 0;\
5256
  ystart = ymin;\
5257
 };\
5258
 ctx.lineWidth = 2;\
5259
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5260
 ctx.beginPath();\
5261
 ctx.moveTo(zero_x,zero_y);\
5262
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
5263
 ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
5264
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
5265
 ctx.lineTo(zero_x,zero_y - snor_y);\
5266
 ctx.stroke();\
5267
 ctx.closePath();\
5268
 ctx.beginPath();\
5269
 ctx.lineWidth = 1;\
5270
 num = ystart;\
5271
 var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
5272
 for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
5273
  ctx.moveTo(zero_x,y);\
5274
  ctx.lineTo(xsize,y);\
5275
  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
5276
  num = num + ymajor;\
5277
 };\
5278
 ctx.stroke();\
5279
 ctx.closePath();\
5280
 if( yminor > 1){\
5281
  ctx.lineWidth = 0.5;\
5282
  ctx.beginPath();\
5283
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
5284
  var minor_step_y = step_y / yminor;\
5285
  var ny;\
5286
  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
5287
   num = 1;\
5288
   for(var p = 1 ;p < yminor;p++){\
5289
     ny = y + num*minor_step_y;\
5290
     ctx.moveTo(zero_x,ny);\
5291
     ctx.lineTo(xsize,ny);\
5292
     num++;\
5293
    };\
5294
  };\
5295
  ctx.stroke();\
5296
  ctx.closePath();\
5297
  ctx.lineWidth = 2;\
5298
  ctx.beginPath();\
5299
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5300
  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
5301
   ctx.moveTo(zero_x,y);\
5302
   ctx.lineTo(zero_x+12,y);\
5303
  };\
5304
  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
5305
   ctx.moveTo(zero_x,y);\
5306
   ctx.lineTo(zero_x+6,y);\
5307
  };\
5308
  ctx.stroke();\
5309
  ctx.closePath();\
5310
 };\
5311
 ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
7654 schaersvoo 5312
 if( typeof legend%d  !== 'undefined' ){\
5313
  ctx.globalAlpha = 1.0;\
5314
  var y_offset = 2*font_size;\
5315
  var txt;var txt_size;\
5316
  var x_offset = xsize - 2*font_size;\
5317
  var l_length = legend%d.length;var barcolor = new Array();\
5318
  if( typeof legendcolors%d !== 'undefined' ){\
5319
   for(var p = 0 ; p < l_length ; p++){\
5320
    barcolor[p] = legendcolors%d[p];\
5321
   };\
5322
  }else{\
5323
   if( barcolor.length == 0 ){\
5324
    for(var p = 0 ; p < l_length ; p++){\
5325
     barcolor[p] = stroke_color;\
5326
    };\
5327
   };\
5328
  };\
5329
  for(var p = 0; p < l_length; p++){\
5330
   ctx.fillStyle = barcolor[p];\
5331
   txt = legend%d[p];\
5332
   txt_size = ctx.measureText(txt).width;\
5333
   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
5334
   y_offset = parseInt(y_offset + 1.5*font_size);\
5335
  };\
5336
 };\
7660 schaersvoo 5337
 if( typeof xaxislabel !== 'undefined' ){\
7658 schaersvoo 5338
   ctx.fillStyle = \'#000000\';\
5339
   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
5340
   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
5341
 };\
7660 schaersvoo 5342
 if( typeof yaxislabel !== 'undefined'){\
7658 schaersvoo 5343
   ctx.save();\
5344
   ctx.fillStyle = \'#000000\';\
5345
   var txt_size = ctx.measureText(yaxislabel).width;\
5346
   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
5347
   ctx.rotate(-0.5*Math.PI);\
5348
   ctx.fillText(yaxislabel,0,0);\
7874 schaersvoo 5349
   ctx.restore();\
7658 schaersvoo 5350
 };\
7654 schaersvoo 5351
};\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);
5352
    break;
7614 schaersvoo 5353
 
5354
    case DRAW_GRID:/* not used for userdraw */
5355
fprintf(js_include_file,"\n<!-- draw grid -->\n\
8071 schaersvoo 5356
draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\
7988 schaersvoo 5357
var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{obj = create_canvas%d(canvas_type,xsize,ysize);};\
5358
var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
7614 schaersvoo 5359
if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5360
ctx.save();\
8071 schaersvoo 5361
if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 5362
if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
5363
var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5364
ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
5365
var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
5366
ctx.font = font_family;\
7988 schaersvoo 5367
var barcolor = new Array();\
7614 schaersvoo 5368
var xstep = xsize*xmajor/(xmax - xmin);\
5369
var ystep = ysize*ymajor/(ymax - ymin);\
5370
var x2step = xstep / xminor;\
5371
var y2step = ystep / yminor;\
7996 schaersvoo 5372
var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
5373
if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
5374
if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
7614 schaersvoo 5375
ctx.beginPath();\
5376
ctx.lineWidth = line_width;\
5377
ctx.strokeStyle = stroke_color;\
5378
for(var p = zero_x ; p < xsize; p = p + xstep){\
5379
 ctx.moveTo(p,0);\
5380
 ctx.lineTo(p,ysize);\
5381
};\
5382
for(var p = zero_x ; p > 0; p = p - xstep){\
5383
 ctx.moveTo(p,0);\
5384
 ctx.lineTo(p,ysize);\
5385
};\
5386
for(var p = zero_y ; p < ysize; p = p + ystep){\
5387
 ctx.moveTo(0,p);\
5388
 ctx.lineTo(xsize,p);\
5389
};\
5390
for(var p = zero_y ; p > 0; p = p - ystep){\
5391
 ctx.moveTo(0,p);\
5392
 ctx.lineTo(xsize,p);\
5393
};\
5394
if( typeof xaxislabel !== 'undefined' ){\
5395
 ctx.save();\
5396
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
5397
 var corr =  ctx.measureText(xaxislabel).width;\
5398
 ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
5399
 ctx.restore();\
5400
};\
5401
if( typeof yaxislabel !== 'undefined' ){\
5402
 ctx.save();\
5403
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
7988 schaersvoo 5404
 var corr =  ctx.measureText(yaxislabel).width;\
7614 schaersvoo 5405
 ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
5406
 ctx.rotate(-0.5*Math.PI);\
5407
 ctx.fillText(yaxislabel,0,0);\
5408
 ctx.restore();\
5409
};\
5410
ctx.stroke();\
5411
ctx.closePath();\
5412
if( use_axis == 1 ){\
7988 schaersvoo 5413
 ctx.save();\
7614 schaersvoo 5414
 ctx.beginPath();\
5415
 ctx.strokeStyle = stroke_color;\
5416
 ctx.lineWidth = 0.6*line_width;\
5417
 for(var p = zero_x ; p < xsize; p = p + x2step){\
5418
  ctx.moveTo(p,0);\
5419
  ctx.lineTo(p,ysize);\
5420
 };\
5421
 for(var p = zero_x ; p > 0; p = p - x2step){\
5422
  ctx.moveTo(p,0);\
5423
  ctx.lineTo(p,ysize);\
5424
 };\
5425
 for(var p = zero_y ; p < ysize; p = p + y2step){\
5426
  ctx.moveTo(0,p);\
5427
  ctx.lineTo(xsize,p);\
5428
 };\
5429
 for(var p = zero_y ; p > 0; p = p - y2step){\
5430
  ctx.moveTo(0,p);\
5431
  ctx.lineTo(xsize,p);\
5432
 };\
5433
 ctx.stroke();\
5434
 ctx.closePath();\
5435
 ctx.beginPath();\
5436
 ctx.lineWidth = 2*line_width;\
5437
 ctx.strokeStyle = axis_color;\
5438
 ctx.moveTo(0,zero_y);\
5439
 ctx.lineTo(xsize,zero_y);\
5440
 ctx.moveTo(zero_x,0);\
5441
 ctx.lineTo(zero_x,ysize);\
5442
 ctx.stroke();\
5443
 ctx.closePath();\
5444
 ctx.lineWidth = line_width+0.5;\
5445
 ctx.beginPath();\
5446
 for(var p = zero_x ; p < xsize; p = p + xstep){\
5447
  ctx.moveTo(p,zero_y-tics_length);\
5448
  ctx.lineTo(p,zero_y+tics_length);\
5449
 };\
5450
 for(var p = zero_x ; p > 0; p = p - xstep){\
5451
  ctx.moveTo(p,zero_y-tics_length);\
5452
  ctx.lineTo(p,zero_y+tics_length);\
5453
 };\
5454
 for(var p = zero_y ; p < ysize; p = p + ystep){\
5455
  ctx.moveTo(zero_x-tics_length,p);\
5456
  ctx.lineTo(zero_x+tics_length,p);\
5457
 };\
5458
 for(var p = zero_y ; p > 0; p = p - ystep){\
5459
  ctx.moveTo(zero_x-tics_length,p);\
5460
  ctx.lineTo(zero_x+tics_length,p);\
5461
 };\
5462
 for(var p = zero_x ; p < xsize; p = p + x2step){\
5463
  ctx.moveTo(p,zero_y-0.5*tics_length);\
5464
  ctx.lineTo(p,zero_y+0.5*tics_length);\
5465
 };\
5466
 for(var p = zero_x ; p > 0; p = p - x2step){\
5467
  ctx.moveTo(p,zero_y-0.5*tics_length);\
5468
  ctx.lineTo(p,zero_y+0.5*tics_length);\
5469
 };\
5470
 for(var p = zero_y ; p < ysize; p = p + y2step){\
5471
  ctx.moveTo(zero_x-0.5*tics_length,p);\
5472
  ctx.lineTo(zero_x+0.5*tics_length,p);\
5473
 };\
5474
 for(var p = zero_y ; p > 0; p = p - y2step){\
5475
  ctx.moveTo(zero_x-0.5*tics_length,p);\
5476
  ctx.lineTo(zero_x+0.5*tics_length,p);\
5477
 };\
5478
 ctx.stroke();\
5479
 ctx.closePath();\
7988 schaersvoo 5480
 ctx.restore();\
5481
};\
5482
if( use_axis_numbering == 1 ){\
5483
 ctx.save();\
5484
 ctx.fillColor = axis_color;\
5485
 ctx.font = font_family;\
5486
 var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
5487
 if( x_strings != null ){\
5488
  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
5489
  for(var p = 0 ; p < len ; p = p+2){\
5490
   var x_nums = x2px(eval(x_strings[p]));\
5491
   var x_text = x_strings[p+1];\
5492
   corr = ctx.measureText(x_text).width;\
5493
   skip = 1.2*corr/xstep;\
5494
   if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
5495
   if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
5496
   ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
5497
  };\
5498
 }\
5499
 else\
5500
 {\
5501
  skip = 1;cnt = px2x(zero_x);\
5502
  prec = Math.log(precision)/(Math.log(10));\
5503
  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
5504
  for( var p = zero_x ; p < xsize ; p = p+xstep){\
5505
   if(skip == 0 ){\
7990 schaersvoo 5506
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5507
    corr = ctx.measureText(disp_cnt).width;\
5508
    skip = parseInt(1.2*corr/xstep);\
5509
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7614 schaersvoo 5510
   }\
7988 schaersvoo 5511
   else\
5512
   {\
5513
    skip--;\
7614 schaersvoo 5514
   };\
7988 schaersvoo 5515
   cnt = cnt + xmajor;\
7614 schaersvoo 5516
  };\
7988 schaersvoo 5517
  cnt = px2x(zero_x);skip = 1;\
5518
  for( var p = zero_x ; p > 0 ; p = p-xstep){\
5519
   if(skip == 0 ){\
7990 schaersvoo 5520
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5521
    corr = ctx.measureText(disp_cnt).width;\
5522
    skip = parseInt(1.2*corr/xstep);\
5523
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
5524
   }\
5525
   else\
5526
   {\
5527
    skip--;\
7614 schaersvoo 5528
   };\
7988 schaersvoo 5529
   cnt = cnt - xmajor;\
7614 schaersvoo 5530
  };\
5531
 };\
7988 schaersvoo 5532
 if( y_strings != null ){\
5533
  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
5534
  for(var p = 0 ; p < len ; p = p+2){\
5535
   var y_nums = y2px(eval(y_strings[p]));\
5536
   var y_text = y_strings[p+1];\
5537
   corr = 2 + tics_length + ctx.measureText(y_text).width;\
5538
   if( corr > zero_x){corr = parseInt(zero_x+2); }\
5539
   ctx.fillText(y_text,zero_x - corr,y_nums);\
7614 schaersvoo 5540
  };\
7988 schaersvoo 5541
 }\
5542
 else\
5543
 {\
7991 schaersvoo 5544
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 5545
  cnt = px2y(zero_y);skip = 1;\
5546
  for( var p = zero_y ; p < ysize ; p = p+ystep){\
5547
   if(skip == 0 ){\
5548
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 5549
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5550
    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
5551
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
5552
   }\
5553
   else\
5554
   {\
5555
    skip--;\
5556
   };\
5557
   cnt = cnt - ymajor;\
7614 schaersvoo 5558
  };\
7988 schaersvoo 5559
  corr = 0;cnt = px2y(zero_y);skip = 1;\
7991 schaersvoo 5560
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 5561
  for( var p = zero_y ; p > 0 ; p = p-ystep){\
5562
   if(skip == 0 ){\
5563
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 5564
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5565
    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
5566
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
5567
   }\
5568
   else\
5569
   {\
5570
    skip--;\
5571
   };\
5572
   cnt = cnt + ymajor;\
7614 schaersvoo 5573
  };\
5574
 };\
7988 schaersvoo 5575
 ctx.stroke();\
7614 schaersvoo 5576
 ctx.restore();\
5577
};\
7956 schaersvoo 5578
if( typeof legend0  !== 'undefined' ){\
7988 schaersvoo 5579
 ctx.save();\
7614 schaersvoo 5580
 ctx.globalAlpha = 1.0;\
5581
 ctx.font = \"bold \"+font_size+\"px Ariel\";\
5582
 var y_offset = 2*font_size;\
5583
 var txt;var txt_size;\
5584
 var x_offset = xsize - 2*font_size;\
7956 schaersvoo 5585
 var l_length = legend0.length;\
5586
 if( typeof legendcolors0 !== 'undefined' ){\
7614 schaersvoo 5587
  for(var p = 0 ; p < l_length ; p++){\
7956 schaersvoo 5588
    barcolor[p] = legendcolors0[p];\
7614 schaersvoo 5589
  };\
7988 schaersvoo 5590
 }\
5591
 else\
5592
 {\
7614 schaersvoo 5593
  if( barcolor.length == 0 ){\
5594
   for(var p = 0 ; p < l_length ; p++){\
5595
    barcolor[p] = stroke_color;\
5596
   };\
5597
  };\
5598
 };\
5599
 for(var p = 0; p < l_length; p++){\
5600
  ctx.fillStyle = barcolor[p];\
7956 schaersvoo 5601
  txt = legend0[p];\
7614 schaersvoo 5602
  txt_size = ctx.measureText(txt).width;\
7956 schaersvoo 5603
  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
7614 schaersvoo 5604
  y_offset = parseInt(y_offset + 1.5*font_size);\
5605
 };\
7988 schaersvoo 5606
 ctx.restore();\
7614 schaersvoo 5607
};\
7991 schaersvoo 5608
if( typeof barchart_0  !== 'undefined' ){\
5609
 ctx.save();\
5610
 var num_barcharts = 0;\
5611
 var bar_name = eval('barchart_0');\
5612
 while( typeof bar_name !== 'undefined' ){\
5613
    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
5614
 };\
5615
 var bar_width = parseInt(0.8*xstep/(num_barcharts));\
5616
 for(var i=0 ; i< num_barcharts ; i++){\
5617
  bar_name = eval('barchart_'+i);\
5618
  var bar_x = new Array();\
5619
  var bar_y = new Array();\
5620
  var lb = bar_name.length;\
5621
  var idx = 0;\
5622
  var dx = parseInt(0.5*i*bar_width);\
5623
  for( var p = 0 ; p < lb ; p = p + 3 ){\
5624
   bar_x[idx] = x2px(bar_name[p]);\
5625
   bar_y[idx] = y2px(bar_name[p+1]);\
5626
   barcolor[idx] = bar_name[p+2];\
5627
   idx++;\
5628
  };\
5629
  ctx.globalAlpha = fill_opacity;\
5630
  ctx.beginPath();\
5631
  for( var p = 0; p < idx ; p++ ){\
5632
   ctx.strokeStyle = barcolor[p];\
5633
   ctx.fillStyle = barcolor[p];\
5634
   ctx.rect(bar_x[p]-0.4*xstep+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
5635
  };\
5636
  ctx.fill();\
5637
  ctx.stroke();\
5638
  ctx.closePath();\
5639
 };\
5640
 ctx.restore();\
5641
};\
7996 schaersvoo 5642
if( typeof linegraph_0 !== 'undefined' ){\
5643
 ctx.save();\
5644
 ctx.globalAlpha = 1.0;\
5645
 var i = 0;\
5646
 var line_name = eval('linegraph_'+i);\
5647
 while ( typeof line_name !== 'undefined' ){\
5648
  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
5649
  ctx.lineWidth = parseInt(line_name[1]);\
5650
  if(line_name[2] == \"1\"){\
5651
   var d1 = parseInt(line_name[3]);\
5652
   var d2 = parseInt(line_name[4]);\
5653
   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
5654
  }\
5655
  else\
5656
  {\
5657
  if(ctx.setLineDash){ctx.setLineDash = null;}\
5658
  if(ctx.mozDash){ctx.mozDash = null;}\
5659
  };\
5660
  var data_x = new Array();\
5661
  var data_y = new Array();\
5662
  var lb = line_name.length;\
5663
  var idx = 0;\
5664
  for( var p = 5 ; p < lb ; p = p + 2 ){\
5665
   data_x[idx] = x2px(line_name[p]);\
5666
   data_y[idx] = y2px(line_name[p+1]);\
5667
   idx++;\
5668
  };\
5669
  for( var p = 0; p < idx ; p++){\
5670
   ctx.beginPath();\
5671
   ctx.moveTo(data_x[p],data_y[p]);\
5672
   ctx.lineTo(data_x[p+1],data_y[p+1]);\
5673
   ctx.stroke();\
5674
   ctx.closePath();\
5675
  };\
5676
  i++;\
5677
  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
5678
 };\
5679
 ctx.restore();\
5680
};\
7614 schaersvoo 5681
return;\
7989 schaersvoo 5682
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5683
    break;
7956 schaersvoo 5684
 
7614 schaersvoo 5685
    case DRAW_PIECHART:
7987 schaersvoo 5686
fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
7956 schaersvoo 5687
function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
7614 schaersvoo 5688
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
5689
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
5690
 }\
5691
 else\
5692
 {\
5693
  obj = create_canvas%d(canvas_type,xsize,ysize);\
5694
 };\
5695
 var ld = data_color_list.length;\
5696
 var sum = 0;\
5697
 var idx = 0;\
7956 schaersvoo 5698
 var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
7614 schaersvoo 5699
 var colors = new Array();\
5700
 var data = new Array();\
5701
 for(var p = 0;p < ld; p = p + 2){\
5702
  data[idx] = parseFloat(data_color_list[p]);\
5703
  sum = sum + data[idx];\
5704
  colors[idx] = data_color_list[p+1];\
5705
  idx++;\
5706
 };\
5707
 var ctx = obj.getContext(\"2d\");\
5708
 ctx.save();\
5709
 var angle;\
5710
 var angle_end = 0;\
5711
 var offset = Math.PI / 2;\
5712
 ctx.globalAlpha = fill_opacity;\
5713
 for(var p=0; p < idx; p++){\
5714
  ctx.beginPath();\
5715
  ctx.fillStyle = colors[p];\
5716
  ctx.moveTo(x_center,y_center);\
5717
  angle = Math.PI * (2 * data[p] / sum);\
5718
  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
5719
  ctx.lineTo(x_center, y_center);\
5720
  ctx.fill();\
5721
  ctx.closePath();\
5722
  angle_end  = angle_end + angle;\
5723
 };\
7956 schaersvoo 5724
 if(typeof legend0 !== 'undefined'){\
5725
  var legenda = eval(\"legend\"+legend_cnt);\
7614 schaersvoo 5726
  ctx.globalAlpha = 1.0;\
7956 schaersvoo 5727
  ctx.font = font_family;\
7614 schaersvoo 5728
  var y_offset = font_size; \
5729
  var x_offset = 0;\
5730
  var txt;var txt_size;\
5731
  for(var p = 0; p < idx; p++){\
5732
   ctx.fillStyle = colors[p];\
7956 schaersvoo 5733
   txt = legenda[p];\
7614 schaersvoo 5734
   txt_size = ctx.measureText(txt).width;\
5735
   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
7956 schaersvoo 5736
   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
7614 schaersvoo 5737
   y_offset = parseInt(y_offset + 1.5*font_size);\
5738
  };\
5739
 };\
5740
 ctx.restore();\
7956 schaersvoo 5741
};",canvas_root_id,canvas_root_id,canvas_root_id);
5742
 
7614 schaersvoo 5743
    break;
5744
    case DRAW_ARCS:
5745
fprintf(js_include_file,"\n<!-- draw arcs -->\n\
8071 schaersvoo 5746
draw_arc = function(ctx,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5747
 ctx.save();\
5748
 if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8071 schaersvoo 5749
 if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 5750
 if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
5751
 if(end < start){var tmp = end;end = start;start=tmp;};\
8071 schaersvoo 5752
 start = 360 - start;\
5753
 end = 360 - end;\
7614 schaersvoo 5754
 ctx.lineWidth = line_width;\
5755
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8071 schaersvoo 5756
 ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
5757
 ctx.beginPath();\
5758
 ctx.moveTo(xc,yc);\
5759
 ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
5760
 ctx.lineTo(xc,yc);\
5761
 ctx.closePath();\
7614 schaersvoo 5762
 if( use_filled == 1 ){\
5763
  ctx.fill();\
8071 schaersvoo 5764
 };\
5765
 ctx.stroke();\
7614 schaersvoo 5766
 ctx.restore();\
8071 schaersvoo 5767
};");
7956 schaersvoo 5768
 
7614 schaersvoo 5769
    break;
7983 schaersvoo 5770
    case DRAW_CENTERSTRING:
5771
fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
5772
draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
5773
 var obj;\
5774
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
5775
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
5776
 }\
5777
 else\
5778
 {\
5779
  obj = create_canvas%d(canvas_type,xsize,ysize);\
5780
 };\
5781
 var ctx = obj.getContext(\"2d\");\
5782
 ctx.save();\
5783
 ctx.font = font_family;\
5784
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5785
 var stringwidth = ctx.measureText(text).width;\
5786
 var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
5787
 ctx.fillText(text,x,y2px(y));\
5788
return;\
5789
};",canvas_root_id,canvas_root_id,canvas_root_id);
5790
    break;
7614 schaersvoo 5791
    case DRAW_TEXTS:
5792
fprintf(js_include_file,"\n<!-- draw text -->\n\
8071 schaersvoo 5793
draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5794
  var obj;\
5795
  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
5796
   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
5797
  }\
5798
  else\
5799
  {\
5800
   obj = create_canvas%d(canvas_type,xsize,ysize);\
5801
  };\
5802
  var ctx = obj.getContext(\"2d\");\
5803
  if(angle2 == 0 && angle != 0){\
5804
   ctx.save();\
8071 schaersvoo 5805
   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5806
   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5807
  };\
5808
  if( font_family.indexOf('px') != null ){\
5809
   ctx.font = font_family;\
5810
  }\
5811
  else\
5812
  {\
7956 schaersvoo 5813
   ctx.font = font_family;\
7614 schaersvoo 5814
  };\
5815
  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5816
  if(angle2 != 0){\
5817
   ctx.save();\
5818
   ctx.translate(x,y);\
5819
   ctx.rotate((360-angle2)*(Math.PI / 180));\
5820
   ctx.fillText(text,0,0);\
5821
   ctx.restore();\
5822
  }else{ctx.fillText(text,x,y);};\
5823
 ctx.restore();\
5824
 return;\
7653 schaersvoo 5825
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5826
    break;
5827
    case DRAW_CURVE:
5828
fprintf(js_include_file,"\n<!-- draw curve -->\n\
8071 schaersvoo 5829
draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5830
 var obj;\
5831
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
5832
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
5833
 }\
5834
 else\
5835
 {\
5836
  obj = create_canvas%d(canvas_type,xsize,ysize);\
5837
 };\
5838
 var ctx = obj.getContext(\"2d\");\
5839
 ctx.save();\
8071 schaersvoo 5840
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5841
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5842
 ctx.beginPath();ctx.lineWidth = line_width;\
5843
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5844
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5845
 ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
5846
 for(var p = 1 ; p < x_points.length ; p++){\
5847
  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
5848
  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
5849
  }\
5850
  else\
5851
  {\
5852
   ctx.stroke();\
5853
   ctx.beginPath();\
5854
   p++;\
5855
   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
5856
  };\
5857
 };\
5858
 ctx.stroke();\
5859
 ctx.restore();\
7653 schaersvoo 5860
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5861
    break;
7956 schaersvoo 5862
 
7614 schaersvoo 5863
    case DRAW_INPUTS:
5864
fprintf(js_include_file,"\n<!-- draw input fields -->\n\
5865
draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
5866
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
5867
var input = document.createElement(\"input\");\
5868
input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
5869
input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
5870
input.setAttribute(\"size\",size);\
5871
input.setAttribute(\"value\",value);\
7877 schaersvoo 5872
if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
7653 schaersvoo 5873
canvas_div.appendChild(input);};");
7614 schaersvoo 5874
    break;
7956 schaersvoo 5875
 
7614 schaersvoo 5876
    case DRAW_TEXTAREAS:
5877
fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
5878
draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
5879
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
5880
var textarea = document.createElement(\"textarea\");\
5881
textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
5882
textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
5883
textarea.setAttribute(\"cols\",cols);\
5884
textarea.setAttribute(\"rows\",rows);\
7877 schaersvoo 5885
textarea.value = value;\
5886
if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
7653 schaersvoo 5887
canvas_div.appendChild(textarea);};");
7614 schaersvoo 5888
    break;
7956 schaersvoo 5889
 
7614 schaersvoo 5890
case DRAW_PIXELS:
5891
fprintf(js_include_file,"\n<!-- draw pixel -->\n\
5892
draw_setpixel = function(x,y,color,opacity,pixelsize){\
5893
 var canvas = create_canvas%d(10,xsize,ysize);\
5894
 var d = 0.5*pixelsize;\
5895
 var ctx = canvas.getContext(\"2d\");\
5896
 ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
5897
 ctx.clearRect(0,0,xsize,ysize);\
5898
 for(var p=0; p<x.length;p++){\
5899
  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
5900
 };\
5901
 ctx.fill();ctx.stroke();\
5902
};",canvas_root_id);
5903
break;
5904
 
5905
case DRAW_CLOCK:
5906
fprintf(js_include_file,"\n<!-- begin command clock -->\n\
5907
var clock_canvas = create_canvas%d(%d,xsize,ysize);\
5908
var clock_ctx = clock_canvas.getContext(\"2d\");\
5909
var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
5910
 clock_ctx.save();\
8000 schaersvoo 5911
 clock_ctx.clearRect(xc-radius,yc-radius,xc+radius,yc+radius);\
7997 schaersvoo 5912
 clock_ctx.globalAlpha = clock_bg_opacity;\
7614 schaersvoo 5913
 this.type = type || 0;\
5914
 this.interaction = interaction || 0;\
7862 schaersvoo 5915
 this.H = H;\
5916
 this.M = M;\
5917
 this.S = S;\
8000 schaersvoo 5918
 if(this.S == -1){this.S = 59;this.M = this.M - 1;};\
5919
 if(this.M == -1){this.M = 59;this.H = this.H - 1;};\
5920
 if(this.H == -1){this.H = 11;};\
7614 schaersvoo 5921
 this.xc = xc || xsize/2;\
5922
 this.yc = yc || ysize/2;\
5923
 this.radius = radius || xsize/4;\
5924
 var font_size = parseInt(0.2*this.radius);\
5925
 this.H_color = h_color || \"blue\";\
5926
 this.M_color = m_color || \"blue\";\
5927
 this.S_color = s_color || \"blue\";\
5928
 this.fg_color = fg_color || \"red\";\
5929
 this.bg_color = bg_color || \"white\";\
5930
 clock_ctx.translate(this.xc,this.yc);\
5931
 clock_ctx.beginPath();\
5932
 clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
5933
 clock_ctx.fillStyle = this.bg_color;\
5934
 clock_ctx.fill();\
5935
 clock_ctx.closePath();\
5936
 clock_ctx.beginPath();\
5937
 clock_ctx.font = font_size+\"px Arial\";\
5938
 clock_ctx.fillStyle = this.fg_color;\
5939
 clock_ctx.textAlign = \"center\";\
5940
 clock_ctx.textBaseline = 'middle';\
5941
 var angle;var x1,y1,x2,y2;\
5942
 var angle_cos;var angle_sin;\
7997 schaersvoo 5943
 clock_ctx.globalAlpha = clock_fg_opacity;\
7614 schaersvoo 5944
 switch(type){\
5945
 case 0:clock_ctx.beginPath();\
5946
 for(var p = 1; p <= 12 ; p++){\
5947
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
5948
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
5949
  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
5950
  clock_ctx.moveTo(x1,y1);\
5951
  clock_ctx.lineTo(x2,y2);\
5952
 };\
5953
 for(var p = 1; p <= 60 ; p++){\
5954
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
5955
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
5956
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
5957
  clock_ctx.moveTo(x1,y1);\
5958
  clock_ctx.lineTo(x2,y2);\
5959
 };\
5960
 clock_ctx.closePath();\
5961
 clock_ctx.stroke();\
5962
 break;\
5963
 case 1:\
5964
 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;\
7862 schaersvoo 5965
 case 2:\
5966
 for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.8*this.radius*Math.cos(angle);y1 = 0.8*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\
7614 schaersvoo 5967
 clock_ctx.beginPath();\
5968
 for(var p = 1; p <= 12 ; p++){\
5969
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
5970
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
5971
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
5972
  clock_ctx.moveTo(x1,y1);\
5973
  clock_ctx.lineTo(x2,y2);\
5974
 };\
5975
 for(var p = 1; p <= 60 ; p++){\
5976
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
5977
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
5978
  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
5979
  clock_ctx.moveTo(x1,y1);\
5980
  clock_ctx.lineTo(x2,y2);\
5981
 };\
5982
 clock_ctx.closePath();\
5983
 clock_ctx.stroke();\
5984
 break;\
5985
 };\
5986
 angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
5987
 clock_ctx.rotate(angle);\
5988
 clock_ctx.beginPath();\
5989
 clock_ctx.moveTo(-3, -2);\
5990
 clock_ctx.lineTo(-3, 2);\
5991
 clock_ctx.lineTo(this.radius * 0.7, 1);\
5992
 clock_ctx.lineTo(this.radius  * 0.7, -1);\
5993
 clock_ctx.fillStyle = this.H_color;\
5994
 clock_ctx.fill();\
5995
 clock_ctx.rotate(-angle);\
5996
 angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
5997
 clock_ctx.rotate(angle);\
5998
 clock_ctx.beginPath();\
5999
 clock_ctx.moveTo(-3, -2);\
6000
 clock_ctx.lineTo(-3, 2);\
6001
 clock_ctx.lineTo(this.radius  * 0.8, 1);\
6002
 clock_ctx.lineTo(this.radius  * 0.8, -1);\
6003
 clock_ctx.fillStyle = this.M_color;\
6004
 clock_ctx.fill();\
6005
 clock_ctx.rotate(-angle);\
6006
 angle = (this.S - 15) * 2 * Math.PI / 60;\
6007
 clock_ctx.rotate(angle);\
6008
 clock_ctx.beginPath();\
6009
 clock_ctx.moveTo(0,0);\
6010
 clock_ctx.lineTo(this.radius  * 0.95, 0);\
6011
 clock_ctx.lineTo(this.radius  * 0.9, -1);\
6012
 clock_ctx.strokeStyle = this.S_color;\
6013
 clock_ctx.stroke();\
6014
 clock_ctx.restore();\
7653 schaersvoo 6015
};",canvas_root_id,CLOCK_CANVAS);
7614 schaersvoo 6016
break;
6017
 
6018
case DRAW_LATTICE:
6019
fprintf(js_include_file,"\n<!-- draw lattice -->\n\
8071 schaersvoo 6020
draw_lattice = function(canvas_type,line_width,x0,y0,dx1,dy1,dx2,dy2,n1,n2,fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 6021
 var obj;\
6022
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6023
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6024
 }\
6025
 else\
6026
 {\
6027
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6028
 };\
6029
 var ctx = obj.getContext(\"2d\");\
6030
 ctx.save();\
8071 schaersvoo 6031
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6032
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6033
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6034
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6035
 var radius = line_width;\
6036
 var x = 0;\
6037
 var y = 0;\
6038
 var x_step_px = xsize/(xmax-xmin);\
6039
 var y_step_px = ysize/(ymax-ymin);\
6040
 var xv1 = dx1*x_step_px;\
6041
 var yv1 = dy1*y_step_px;\
6042
 var xv2 = dx2*x_step_px;\
6043
 var yv2 = dy2*y_step_px;\
6044
 for(var p = 0; p < n1 ;p++){\
6045
  x = p*xv1 + x0;\
6046
  y = p*yv1 + y0;\
6047
  for(var c = 0; c < n2 ; c++){\
6048
   ctx.beginPath();\
6049
   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
6050
   ctx.fill();\
6051
   ctx.stroke();\
6052
   ctx.closePath();\
6053
  };\
6054
 };\
6055
 ctx.restore();\
6056
 return;\
7653 schaersvoo 6057
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6058
    break;
7735 schaersvoo 6059
case DRAW_XYLOGSCALE:
6060
fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
7956 schaersvoo 6061
draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,precision){\
6062
 var obj;\
6063
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6064
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6065
 }\
6066
 else\
6067
 {\
6068
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6069
 };\
6070
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 6071
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6072
 ctx.save();\
7739 schaersvoo 6073
 var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
7956 schaersvoo 6074
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
6075
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
6076
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
6077
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
7739 schaersvoo 6078
 if(use_axis_numbering == 1){\
7956 schaersvoo 6079
  ctx.font = font_family;\
6080
  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
6081
  ymarge = parseInt(1.5*font_size);\
6082
  ctx.save();\
6083
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6084
  ctx.rect(0,0,xmarge,ysize);\
6085
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6086
  ctx.fill();\
6087
  ctx.restore();\
6088
 }else{xmarge = 0;ymarge = 0;};\
7735 schaersvoo 6089
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6090
  ctx.save();\
6091
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6092
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6093
  corr =  ctx.measureText(xaxislabel).width;\
6094
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6095
  ctx.restore();\
6096
 };\
7735 schaersvoo 6097
 if( typeof yaxislabel !== 'undefined' ){\
7956 schaersvoo 6098
  ctx.save();\
6099
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6100
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6101
  corr = ctx.measureText(yaxislabel).width;\
6102
  ctx.translate(xmarge+font_size,corr+font_size);\
6103
  ctx.rotate(-0.5*Math.PI);\
6104
  ctx.fillText(yaxislabel,0,0);\
6105
  ctx.restore();\
6106
 };\
6107
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6108
 ctx.lineWidth = line_width;\
6109
 for(var p = x_min; p <= x_max ; p++){\
6110
  num = Math.pow(xlogbase,p);\
6111
  for(var i = 1 ; i < xlogbase ; i++){\
6112
   x_e = x2px(i*num);\
7735 schaersvoo 6113
   if( i == 1 ){\
7956 schaersvoo 6114
    ctx.lineWidth = line_width;\
6115
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7738 schaersvoo 6116
    if( use_axis_numbering == 1 && p > x_min){\
7956 schaersvoo 6117
      xtxt = xlogbase+'^'+p.toFixed(0);\
6118
      corr = 0.5*(ctx.measureText(xtxt).width);\
6119
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
6120
    };\
7735 schaersvoo 6121
   }else{\
7956 schaersvoo 6122
    ctx.lineWidth = 0.2*line_width;\
6123
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6124
   };\
7738 schaersvoo 6125
   if( x_e >= xmarge ){\
7956 schaersvoo 6126
    ctx.beginPath();\
6127
    ctx.moveTo(x_e,0);\
6128
    ctx.lineTo(x_e,ysize - ymarge);\
6129
    ctx.stroke();\
6130
    ctx.closePath();\
7738 schaersvoo 6131
   };\
7956 schaersvoo 6132
  };\
6133
 };\
6134
 for(var p = y_min; p <= y_max ; p++){\
6135
  num = Math.pow(ylogbase,p);\
6136
  for(var i = 1 ; i < ylogbase ; i++){\
6137
   y_e = y2px(i*num);\
6138
   if( i == 1 ){\
6139
    ctx.lineWidth = line_width;\
7735 schaersvoo 6140
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6141
    if( use_axis_numbering == 1 && p > y_min){\
6142
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
6143
    };\
6144
   }else{\
6145
    ctx.lineWidth = 0.2*line_width;\
6146
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6147
   };\
6148
   ctx.beginPath();\
6149
   ctx.moveTo(xmarge,y_e);\
6150
   ctx.lineTo(xsize,y_e);\
6151
   ctx.stroke();\
6152
   ctx.closePath();\
6153
  };\
6154
 };\
7735 schaersvoo 6155
 ctx.restore();\
6156
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
6157
    break;
7614 schaersvoo 6158
 
7735 schaersvoo 6159
case DRAW_XLOGSCALE:
6160
fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
7956 schaersvoo 6161
draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,ymajor,yminor,precision){\
6162
 var obj;\
6163
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6164
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6165
 }\
6166
 else\
6167
 {\
6168
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6169
 };\
6170
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 6171
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6172
 ctx.save();\
6173
 ctx.lineWidth = line_width;\
7739 schaersvoo 6174
 var prec = Math.log(precision)/Math.log(10);\
7735 schaersvoo 6175
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
6176
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
6177
 var y_min = 0;var y_max = ysize;var x_e;var corr;\
7739 schaersvoo 6178
 var xtxt;var ytxt;var num;var xmarge;var ymarge;\
6179
 if(use_axis_numbering == 1){\
7956 schaersvoo 6180
  ctx.font = font_family;\
6181
  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
6182
  ymarge = parseInt(1.5*font_size);\
6183
  ctx.save();\
6184
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6185
  ctx.rect(0,0,xmarge,ysize);\
6186
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6187
  ctx.fill();\
6188
  ctx.restore();\
6189
 }else{xmarge = 0;ymarge = 0;};\
7739 schaersvoo 6190
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6191
  ctx.save();\
6192
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6193
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6194
  corr =  ctx.measureText(xaxislabel).width;\
6195
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6196
  ctx.restore();\
6197
 };\
7739 schaersvoo 6198
 if( typeof yaxislabel !== 'undefined' ){\
7956 schaersvoo 6199
  ctx.save();\
6200
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6201
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6202
  corr = ctx.measureText(yaxislabel).width;\
6203
  ctx.translate(xmarge+font_size,corr+font_size);\
6204
  ctx.rotate(-0.5*Math.PI);\
6205
  ctx.fillText(yaxislabel,0,0);\
6206
  ctx.restore();\
6207
 };\
6208
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6209
 ctx.lineWidth = line_width;\
6210
 for(var p = x_min; p <= x_max ; p++){\
6211
  num = Math.pow(xlogbase,p);\
6212
  for(var i = 1 ; i < xlogbase ; i++){\
6213
   x_e = x2px(i*num);\
7735 schaersvoo 6214
   if( i == 1 ){\
7956 schaersvoo 6215
     ctx.lineWidth = line_width;\
7739 schaersvoo 6216
     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
6217
    if( use_axis_numbering == 1 && p > x_min ){\
7735 schaersvoo 6218
      xtxt = xlogbase+'^'+p.toFixed(0);\
6219
      corr = 0.5*(ctx.measureText(xtxt).width);\
6220
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
6221
    };\
6222
   }else{\
7956 schaersvoo 6223
    ctx.lineWidth = 0.2*line_width;\
7735 schaersvoo 6224
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6225
   };\
7739 schaersvoo 6226
   if( x_e >= xmarge ){\
7956 schaersvoo 6227
    ctx.beginPath();\
6228
    ctx.moveTo(x_e,0);\
6229
    ctx.lineTo(x_e,ysize - ymarge);\
6230
    ctx.stroke();\
6231
    ctx.closePath();\
7739 schaersvoo 6232
   };\
6233
  };\
7956 schaersvoo 6234
 };\
7735 schaersvoo 6235
 var stepy = Math.abs(y2px(ymajor) - y2px(0));\
6236
 var minor_step = stepy / yminor;\
7749 schaersvoo 6237
 for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
7735 schaersvoo 6238
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6239
  ctx.lineWidth = line_width;\
6240
  ctx.beginPath();\
6241
  ctx.moveTo(xmarge,y);\
6242
  ctx.lineTo(xsize,y);\
6243
  ctx.stroke();\
6244
  ctx.closePath();\
7735 schaersvoo 6245
  if( use_axis_numbering == 1){\
6246
   ytxt = (px2y(y)).toFixed(prec);\
6247
   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
6248
  };\
6249
  for(var dy = 1 ; dy < yminor ; dy++){\
6250
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 6251
   ctx.lineWidth = 0.2*line_width;\
6252
   ctx.beginPath();\
7739 schaersvoo 6253
   ctx.moveTo(xmarge,y+dy*minor_step);\
7956 schaersvoo 6254
   ctx.lineTo(xsize,y+dy*minor_step);\
6255
   ctx.stroke();\
6256
   ctx.closePath();\
7735 schaersvoo 6257
  };\
6258
 };\
7956 schaersvoo 6259
 ctx.restore();\
6260
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7735 schaersvoo 6261
    break;
7729 schaersvoo 6262
case DRAW_YLOGSCALE:
6263
fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
7956 schaersvoo 6264
draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,xmajor,xminor,precision){\
6265
 var obj;\
6266
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6267
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6268
 }\
6269
 else\
6270
 {\
6271
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6272
 };\
6273
 var ctx = obj.getContext(\"2d\");\
7729 schaersvoo 6274
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6275
 ctx.save();\
6276
 ctx.lineWidth = line_width;\
7735 schaersvoo 6277
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
6278
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
6279
 var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;\
7739 schaersvoo 6280
 if(use_axis_numbering == 1){\
7956 schaersvoo 6281
  ctx.font = font_family;\
6282
  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
6283
  ymarge = 2*font_size;\
6284
  ctx.save();\
6285
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6286
  ctx.rect(0,0,xmarge,ysize);\
6287
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6288
  ctx.fill();\
6289
  ctx.restore();\
6290
 }else{xmarge = 0;ymarge = 0;};\
7739 schaersvoo 6291
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6292
  ctx.save();\
6293
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6294
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6295
  corr =  ctx.measureText(xaxislabel).width;\
6296
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6297
  ctx.restore();\
6298
 };\
7739 schaersvoo 6299
 if( typeof yaxislabel !== 'undefined' ){\
7956 schaersvoo 6300
  ctx.save();\
6301
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6302
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6303
  corr = ctx.measureText(yaxislabel).width;\
6304
  ctx.translate(xmarge+font_size,corr+font_size);\
6305
  ctx.rotate(-0.5*Math.PI);\
6306
  ctx.fillText(yaxislabel,0,0);\
6307
  ctx.restore();\
6308
 };\
6309
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6310
 ctx.lineWidth = line_width;\
6311
 for(var p = y_min; p <= y_max ; p++){\
6312
  num = Math.pow(ylogbase,p);\
6313
  for(var i = 1 ; i < ylogbase ; i++){\
6314
   y_e = y2px(i*num);\
7729 schaersvoo 6315
   if( i == 1 ){\
7956 schaersvoo 6316
    ctx.lineWidth = line_width;\
7729 schaersvoo 6317
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7739 schaersvoo 6318
    if( use_axis_numbering == 1 && p > y_min){\
7735 schaersvoo 6319
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
7729 schaersvoo 6320
    };\
6321
   }else{\
7956 schaersvoo 6322
    ctx.lineWidth = 0.2*line_width;\
7729 schaersvoo 6323
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6324
   };\
7956 schaersvoo 6325
   ctx.beginPath();\
6326
   ctx.moveTo(xmarge,y_e);\
6327
   ctx.lineTo(xsize,y_e);\
6328
   ctx.stroke();\
6329
   ctx.closePath();\
6330
  };\
6331
 };\
7729 schaersvoo 6332
 var stepx = Math.abs(x2px(xmajor) - x2px(0));\
6333
 var minor_step = stepx / xminor;\
6334
 var prec = Math.log(precision)/Math.log(10);\
6335
 var xtxt;var corr;var flip = 0;\
7749 schaersvoo 6336
 for(var x = stepx ; x < xsize ; x = x + stepx){\
7729 schaersvoo 6337
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6338
  ctx.lineWidth = line_width;\
6339
  ctx.beginPath();\
6340
  ctx.moveTo(x,ysize-ymarge);\
6341
  ctx.lineTo(x,0);\
6342
  ctx.stroke();\
6343
  ctx.closePath();\
7729 schaersvoo 6344
  if( use_axis_numbering == 1){\
6345
   xtxt = (px2x(x)).toFixed(prec);\
6346
   corr = 0.5*(ctx.measureText(xtxt).width);\
6347
   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
6348
   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
6349
  };\
6350
  for(var dx = 1 ; dx < xminor ; dx++){\
6351
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 6352
   ctx.lineWidth = 0.2*line_width;\
6353
   ctx.beginPath();\
7739 schaersvoo 6354
   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
7956 schaersvoo 6355
   ctx.lineTo(x+dx*minor_step,0);\
6356
   ctx.stroke();\
6357
   ctx.closePath();\
7735 schaersvoo 6358
  };\
6359
 };\
7956 schaersvoo 6360
 ctx.restore();\
6361
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7729 schaersvoo 6362
    break;
7614 schaersvoo 6363
    default:break;
6364
   }
6365
  }
6366
 }
6367
  return;
6368
}
6369
 
6370
void check_string_length(int L){
6371
 if(L<1 || L > MAX_BUFFER-1){
6372
  canvas_error("problem with your arguments to command...");
6373
 }
6374
 return;
6375
}
6376
 
6377
 
6378
int get_token(FILE *infile){
6379
        int     c,i=0;
6380
        char    temp[MAX_INT], *input_type;
6381
        char    *line="line",
6382
        *audio="audio",
6383
        *blink="blink",
6384
        *arrowhead="arrowhead",
6385
        *crosshairsize="crosshairsize",
6386
        *crosshair="crosshair",
6387
        *crosshairs="crosshairs",
6388
        *audioobject="audioobject",
6389
        *style="style",
6390
        *mouse="mouse",
7991 schaersvoo 6391
        *mousex="mousex",
6392
        *mousey="mousey",
8071 schaersvoo 6393
        *mouse_display="display",
6394
        *mouse_degree="mouse_degree",
7614 schaersvoo 6395
        *userdraw="userdraw",
6396
        *highlight="highlight",
6397
        *http="http",
6398
        *rays="rays",
6399
        *dashtype="dashtype",
6400
        *dashed="dashed",
6401
        *filled="filled",
6402
        *lattice="lattice",
6403
        *parallel="parallel",
6404
        *segment="segment",
6405
        *dsegment="dsegment",
6406
        *seg="seg",
6407
        *bgimage="bgimage",
6408
        *bgcolor="bgcolor",
6409
        *strokecolor="strokecolor",
6410
        *backgroundimage="backgroundimage",
6411
        *text="text",
6412
        *textup="textup",
6413
        *mouseprecision="mouseprecision",
6414
        *precision="precision",
6415
        *plotsteps="plotsteps",
6416
        *plotstep="plotstep",
6417
        *tsteps="tsteps",
6418
        *curve="curve",
6419
        *dcurve="dcurve",
6420
        *plot="plot",
6421
        *dplot="dplot",
7788 schaersvoo 6422
        *levelcurve="levelcurve",
7614 schaersvoo 6423
        *fontsize="fontsize",
6424
        *fontcolor="fontcolor",
6425
        *axis="axis",
6426
        *axisnumbering="axisnumbering",
6427
        *axisnumbers="axisnumbers",
6428
        *arrow="arrow",
6429
        *darrow="darrow",
6430
        *arrow2="arrow2",
6431
        *darrow2="darrow2",
6432
        *zoom="zoom",
6433
        *grid="grid",
6434
        *hline="hline",
7786 schaersvoo 6435
        *dhline="dhline",
7614 schaersvoo 6436
        *drag="drag",
6437
        *horizontalline="horizontalline",
6438
        *vline="vline",
7786 schaersvoo 6439
        *dvline="dvline",
7614 schaersvoo 6440
        *verticalline="verticalline",
6441
        *triangle="triangle",
6442
        *ftriangle="ftriangle",
6443
        *mathml="mathml",
6444
        *html="html",
6445
        *input="input",
6446
        *button="button",
6447
        *inputstyle="inputstyle",
6448
        *textarea="textarea",
6449
        *trange="trange",
6450
        *ranget="ranget",
6451
        *xrange="xrange",
6452
        *yrange="yrange",
6453
        *rangex="rangex",
6454
        *rangey="rangey",
6455
        *polyline="polyline",
6456
        *lines="lines",
6457
        *poly="poly",
6458
        *polygon="polygon",
6459
        *fpolygon="fpolygon",
6460
        *fpoly="fpoly",
6461
        *filledpoly="filledpoly",
6462
        *filledpolygon="filledpolygon",
6463
        *rect="rect",
6464
        *frect="frect",
6465
        *rectangle="rectangle",
6466
        *frectangle="frectangle",
6467
        *square="square",
6468
        *fsquare="fsquare",
6469
        *dline="dline",
6470
        *arc="arc",
6471
        *filledarc="filledarc",
6472
        *size="size",
6473
        *string="string",
6474
        *stringup="stringup",
6475
        *copy="copy",
6476
        *copyresized="copyresized",
6477
        *opacity="opacity",
6478
        *transparent="transparent",
6479
        *fill="fill",
6480
        *point="point",
6481
        *points="points",
6482
        *linewidth="linewidth",
6483
        *circle="circle",
6484
        *fcircle="fcircle",
6485
        *disk="disk",
6486
        *comment="#",
6487
        *end="end",
6488
        *ellipse="ellipse",
6489
        *fellipse="fellipse",
6490
        *rotate="rotate",
7785 schaersvoo 6491
        *affine="affine",
6492
        *killaffine="killaffine",
7614 schaersvoo 6493
        *fontfamily="fontfamily",
6494
        *fillcolor="fillcolor",
6495
        *clicktile="clicktile",
6496
        *clicktile_colors="clicktile_colors",
6497
        *translation="translation",
6498
        *translate="translate",
6499
        *killtranslation="killtranslation",
6500
        *killtranslate="killtranslate",
6501
        *onclick="onclick",
6502
        *roundrect="roundrect",
6503
        *froundrect="froundrect",
6504
        *roundrectangle="roundrectangle",
6505
        *patternfill="patternfill",
6506
        *hatchfill="hatchfill",
6507
        *diafill="diafill",
7647 schaersvoo 6508
        *diamondfill="diamondfill",
7614 schaersvoo 6509
        *dotfill="dotfill",
6510
        *gridfill="gridfill",
6511
        *imagefill="imagefill",
7735 schaersvoo 6512
        *xlogbase="xlogbase",
6513
        *ylogbase="ylogbase",
7614 schaersvoo 6514
        *xlogscale="xlogscale",
6515
        *ylogscale="ylogscale",
6516
        *xylogscale="xylogscale",
6517
        *intooltip="intooltip",
6518
        *replyformat="replyformat",
6519
        *floodfill="floodfill",
6520
        *filltoborder="filltoborder",
6521
        *clickfill="clickfill",
6522
        *setpixel="setpixel",
6523
        *pixels="pixels",
6524
        *pixelsize="pixelsize",
6525
        *clickfillmarge="clickfillmarge",
6526
        *xaxis="xaxis",
6527
        *yaxis="yaxis",
6528
        *xaxistext="xaxistext",
6529
        *yaxistext="yaxistext",
6530
        *piechart="piechart",
6531
        *legend="legend",
6532
        *legendcolors="legendcolors",
6533
        *xlabel="xlabel",
6534
        *ylabel="ylabel",
6535
        *barchart="barchart",
6536
        *linegraph="linegraph",
6537
        *clock="clock",
6538
        *animate="animate",
6539
        *video="video",
6540
        *status="status",
7877 schaersvoo 6541
        *nostatus="nostatus",
7652 schaersvoo 6542
        *snaptogrid="snaptogrid",
7784 schaersvoo 6543
        *xsnaptogrid="xsnaptogrid",
6544
        *ysnaptogrid="ysnaptogrid",
7654 schaersvoo 6545
        *userinput_xy="userinput_xy",
7663 schaersvoo 6546
        *usertextarea_xy="usertextarea_xy",
7823 schaersvoo 6547
        *jsmath="jsmath",
7858 schaersvoo 6548
        *trace_jscurve="trace_jscurve",
7838 schaersvoo 6549
        *setlimits="setlimits",
7858 schaersvoo 6550
        *jscurve="jscurve",
6551
        *jsplot="jsplot",
7983 schaersvoo 6552
        *sgraph="sgraph",
7984 schaersvoo 6553
        *title="title",
7996 schaersvoo 6554
        *centerstring="centerstring",
6555
        *xunit="xunit",
8071 schaersvoo 6556
        *yunit="yunit",
8101 schaersvoo 6557
        *slider="slider",
6558
        *killslider="killslider";
7614 schaersvoo 6559
 
6560
        while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
6561
            if( i == 0 && (c == ' ' || c == '\t') ){
6562
        continue; /* white spaces or tabs allowed before first command identifier */
6563
            }
6564
            else
6565
            {
6566
        if( c == ' ' || c == '\t' ){
6567
            break;
6568
        }
6569
        else
6570
        {
6571
            temp[i] = c;
6572
            if(i > MAX_INT - 2){canvas_error("command string too long !");}
6573
            i++;
6574
        }
6575
            }
6576
            if(temp[0] == '#') break;
6577
        }
6578
        if (c == EOF) finished = 1;
6579
 
6580
        if (c == '\n' || c == '\r') {
6581
        line_number++;
6582
        if (i == 0) { return EMPTY; }
6583
        } else if (c == EOF) {
6584
        return 0;
6585
        }
6586
 
6587
        temp[i]='\0';
6588
        input_type=(char*)my_newmem(strlen(temp));
6589
        snprintf(input_type,sizeof(temp),"%s",temp);
6590
 
6591
        if( strcmp(input_type, size) == 0 ){
6592
        free(input_type);
6593
        return SIZE;
6594
        }
6595
        if( strcmp(input_type, xrange) == 0 ){
6596
        free(input_type);
6597
        return XRANGE;
6598
        }
6599
        if( strcmp(input_type, rangex) == 0 ){
6600
        free(input_type);
6601
        return XRANGE;
6602
        }
6603
        if( strcmp(input_type, trange) == 0 ){
6604
        free(input_type);
6605
        return TRANGE;
6606
        }
6607
        if( strcmp(input_type, ranget) == 0 ){
6608
        free(input_type);
6609
        return TRANGE;
6610
        }
6611
        if( strcmp(input_type, yrange) == 0 ){
6612
        free(input_type);
6613
        return YRANGE;
6614
        }
6615
        if( strcmp(input_type, rangey) == 0 ){
6616
        free(input_type);
6617
        return YRANGE;
6618
        }
6619
        if( strcmp(input_type, linewidth) == 0 ){
6620
        free(input_type);
6621
        return LINEWIDTH;
6622
        }
6623
        if( strcmp(input_type, dashed) == 0 ){
6624
        free(input_type);
6625
        return DASHED;
6626
        }
6627
        if( strcmp(input_type, dashtype) == 0 ){
6628
        free(input_type);
6629
        return DASHTYPE;
6630
        }
6631
        if( strcmp(input_type, axisnumbering) == 0 ){
6632
        free(input_type);
6633
        return AXIS_NUMBERING;
6634
        }
6635
        if( strcmp(input_type, axisnumbers) == 0 ){
6636
        free(input_type);
6637
        return AXIS_NUMBERING;
6638
        }
6639
        if( strcmp(input_type, axis) == 0 ){
6640
        free(input_type);
6641
        return AXIS;
6642
        }
6643
        if( strcmp(input_type, grid) == 0 ){
6644
        free(input_type);
6645
        return GRID;
6646
        }
6647
        if( strcmp(input_type, parallel) == 0 ){
6648
        free(input_type);
6649
        return PARALLEL;
6650
        }
6651
        if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
6652
        free(input_type);
6653
        return HLINE;
6654
        }
6655
        if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
6656
        free(input_type);
6657
        return VLINE;
6658
        }
6659
        if( strcmp(input_type, line) == 0 ){
6660
        free(input_type);
6661
        return LINE;
6662
        }
6663
        if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
6664
        free(input_type);
6665
        return SEGMENT;
6666
        }
6667
        if( strcmp(input_type, dsegment) == 0 ){
6668
        free(input_type);
6669
        use_dashed = TRUE;
6670
        return SEGMENT;
6671
        }
6672
        if( strcmp(input_type, crosshairsize) == 0 ){
6673
        free(input_type);
6674
        return CROSSHAIRSIZE;
6675
        }
6676
        if( strcmp(input_type, arrowhead) == 0 ){
6677
        free(input_type);
6678
        return ARROWHEAD;
6679
        }
6680
        if( strcmp(input_type, crosshairs) == 0 ){
6681
        free(input_type);
6682
        return CROSSHAIRS;
6683
        }
6684
        if( strcmp(input_type, crosshair) == 0 ){
6685
        free(input_type);
6686
        return CROSSHAIR;
6687
        }
6688
        if( strcmp(input_type, onclick) == 0 ){
6689
        free(input_type);
6690
        return ONCLICK;
6691
        }
6692
        if( strcmp(input_type, drag) == 0 ){
6693
        free(input_type);
6694
        return DRAG;
6695
        }
6696
        if( strcmp(input_type, userdraw) == 0 ){
6697
        free(input_type);
6698
        return USERDRAW;
6699
        }
6700
        if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
6701
        free(input_type);
6702
        return STYLE;
6703
        }
6704
        if( strcmp(input_type, fillcolor) == 0 ){
6705
        free(input_type);
6706
        return FILLCOLOR;
6707
        }
6708
        if( strcmp(input_type, strokecolor) == 0 ){
6709
        free(input_type);
6710
        return STROKECOLOR;
6711
        }
6712
        if( strcmp(input_type, filled) == 0  ){
6713
        free(input_type);
6714
        return FILLED;
6715
        }
6716
        if( strcmp(input_type, http) == 0 ){
6717
        free(input_type);
6718
        return HTTP;
6719
        }
6720
        if( strcmp(input_type, rays) == 0 ){
6721
        free(input_type);
6722
        return RAYS;
6723
        }
6724
        if( strcmp(input_type, lattice) == 0 ){
6725
        free(input_type);
6726
        return LATTICE;
6727
        }
6728
        if( strcmp(input_type, bgimage) == 0 ){
6729
        free(input_type);
6730
        return BGIMAGE;
6731
        }
6732
        if( strcmp(input_type, bgcolor) == 0 ){
6733
        free(input_type);
6734
        return BGCOLOR;
6735
        }
6736
        if( strcmp(input_type, backgroundimage) == 0 ){
6737
        free(input_type);
6738
        return BGIMAGE;
6739
        }
6740
        if( strcmp(input_type, text) == 0 ){
6741
        free(input_type);
6742
        return FLY_TEXT;
6743
        }
6744
        if( strcmp(input_type, textup) == 0 ){
6745
        free(input_type);
6746
        return FLY_TEXTUP;
6747
        }
6748
        if( strcmp(input_type, mouse) == 0 ){
6749
        free(input_type);
6750
        return MOUSE;
6751
        }
7991 schaersvoo 6752
        if( strcmp(input_type, mousex) == 0 ){
6753
        free(input_type);
6754
        return MOUSEX;
6755
        }
6756
        if( strcmp(input_type, mousey) == 0 ){
6757
        free(input_type);
6758
        return MOUSEY;
6759
        }
8071 schaersvoo 6760
        if( strcmp(input_type, mouse_degree) == 0 ){
6761
        free(input_type);
6762
        return MOUSE_DEGREE;
6763
        }
6764
        if( strcmp(input_type, mouse_display) == 0 ){
6765
        free(input_type);
6766
        return MOUSE_DISPLAY;
6767
        }
7614 schaersvoo 6768
        if( strcmp(input_type, mouseprecision) == 0 ){
6769
        free(input_type);
6770
        return MOUSE_PRECISION;
6771
        }
6772
        if( strcmp(input_type, precision) == 0 ){
6773
        free(input_type);
6774
        return MOUSE_PRECISION;
6775
        }
6776
        if( strcmp(input_type, curve) == 0 ){
6777
        free(input_type);
6778
        return CURVE;
6779
        }
6780
        if( strcmp(input_type, dcurve) == 0 ){
7788 schaersvoo 6781
        use_dashed = TRUE;
7614 schaersvoo 6782
        free(input_type);
6783
        return CURVE;
6784
        }
6785
        if( strcmp(input_type, plot) == 0 ){
6786
        free(input_type);
6787
        return CURVE;
6788
        }
6789
        if( strcmp(input_type, dplot) == 0 ){
7788 schaersvoo 6790
        use_dashed = TRUE;
7614 schaersvoo 6791
        free(input_type);
6792
        return CURVE;
6793
        }
7788 schaersvoo 6794
        if( strcmp(input_type, levelcurve) == 0 ){
6795
        free(input_type);
6796
        return LEVELCURVE;
6797
        }
7614 schaersvoo 6798
        if( strcmp(input_type, plotsteps) == 0 ){
6799
        free(input_type);
6800
        return PLOTSTEPS;
6801
        }
6802
        if( strcmp(input_type, plotstep) == 0 ){
6803
        free(input_type);
6804
        return PLOTSTEPS;
6805
        }
6806
        if( strcmp(input_type, tsteps) == 0 ){
6807
        free(input_type);
6808
        return PLOTSTEPS;
6809
        }
6810
        if( strcmp(input_type, fontsize) == 0 ){
6811
        free(input_type);
6812
        return FONTSIZE;
6813
        }
6814
        if( strcmp(input_type, fontcolor) == 0 ){
6815
        free(input_type);
6816
        return FONTCOLOR;
6817
        }
6818
        if( strcmp(input_type, arrow) == 0 ){
6819
        free(input_type);
6820
        return ARROW;
6821
        }
6822
        if( strcmp(input_type, arrow2) == 0 ){
6823
        free(input_type);
6824
        return ARROW2;
6825
        }
6826
        if( strcmp(input_type, darrow) == 0 ){
6827
        free(input_type);
8071 schaersvoo 6828
        use_dashed = TRUE;
7614 schaersvoo 6829
        return ARROW;
6830
        }
6831
        if( strcmp(input_type, darrow2) == 0 ){
6832
        free(input_type);
6833
        use_dashed = TRUE;
6834
        return ARROW2;
6835
        }
6836
        if( strcmp(input_type, zoom) == 0 ){
6837
        free(input_type);
6838
        return ZOOM;
6839
        }
6840
        if( strcmp(input_type, triangle) == 0 ){
6841
        free(input_type);
6842
        return TRIANGLE;
6843
        }
6844
        if( strcmp(input_type, ftriangle) == 0 ){
6845
        free(input_type);
6846
        use_filled = TRUE;
6847
        return TRIANGLE;
6848
        }
6849
        if( strcmp(input_type, input) == 0 ){
6850
        free(input_type);
6851
        return INPUT;
6852
        }
6853
        if( strcmp(input_type, inputstyle) == 0 ){
6854
        free(input_type);
6855
        return INPUTSTYLE;
6856
        }
6857
        if( strcmp(input_type, textarea) == 0 ){
6858
        free(input_type);
6859
        return TEXTAREA;
6860
        }
6861
        if( strcmp(input_type, mathml) == 0 ){
6862
        free(input_type);
6863
        return MATHML;
6864
        }
6865
        if( strcmp(input_type, html) == 0 ){
6866
        free(input_type);
6867
        return MATHML;
6868
        }
6869
        if( strcmp(input_type, fontfamily) == 0 ){
6870
        free(input_type);
6871
        return FONTFAMILY;
6872
        }
6873
        if( strcmp(input_type, lines) == 0  ||  strcmp(input_type, polyline) == 0 ){
6874
        free(input_type);
6875
        return POLYLINE;
6876
        }
6877
        if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
6878
        free(input_type);
6879
        return RECT;
6880
        }
6881
        if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
6882
        free(input_type);
6883
        return ROUNDRECT;
6884
        }
6885
        if( strcmp(input_type, froundrect) == 0 ){
6886
        free(input_type);
6887
        use_filled = TRUE;
6888
        return ROUNDRECT;
6889
        }
6890
        if( strcmp(input_type, square) == 0 ){
6891
        free(input_type);
6892
        return SQUARE;
6893
        }
6894
        if( strcmp(input_type, fsquare) == 0 ){
6895
        free(input_type);
6896
        use_filled = TRUE;
6897
        return SQUARE;
6898
        }
6899
        if( strcmp(input_type, dline) == 0 ){
6900
        use_dashed = TRUE;
6901
        free(input_type);
6902
        return LINE;
6903
        }
7786 schaersvoo 6904
        if( strcmp(input_type, dvline) == 0 ){
6905
        use_dashed = TRUE;
6906
        free(input_type);
6907
        return VLINE;
6908
        }
6909
        if( strcmp(input_type, dhline) == 0 ){
6910
        use_dashed = TRUE;
6911
        free(input_type);
6912
        return HLINE;
6913
        }
7614 schaersvoo 6914
        if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
6915
        use_filled = TRUE;
6916
        free(input_type);
6917
        return RECT;
6918
        }
6919
        if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
6920
        use_filled = TRUE;
6921
        free(input_type);
6922
        return CIRCLE;
6923
        }
6924
        if( strcmp(input_type, circle) == 0 ){
6925
        free(input_type);
6926
        return CIRCLE;
6927
        }
6928
        if( strcmp(input_type, point) == 0 ){
6929
        free(input_type);
6930
        return POINT;
6931
        }
6932
        if( strcmp(input_type, points) == 0 ){
6933
        free(input_type);
6934
        return POINTS;
6935
        }
6936
        if( strcmp(input_type, filledarc) == 0 ){
6937
        use_filled = TRUE;
6938
        free(input_type);
6939
        return ARC;
6940
        }
6941
        if( strcmp(input_type, arc) == 0 ){
6942
        free(input_type);
6943
        return ARC;
6944
        }
6945
        if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
6946
        free(input_type);
6947
        return POLY;
6948
        }
6949
        if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
6950
        use_filled = TRUE;
6951
        free(input_type);
6952
        return POLY;
6953
        }
6954
        if( strcmp(input_type, ellipse) == 0){
6955
        free(input_type);
6956
        return ELLIPSE;
6957
        }
6958
        if( strcmp(input_type, fill) == 0 ){
6959
        free(input_type);
6960
        return FLOODFILL;
6961
        }
6962
        if( strcmp(input_type, string) == 0 ){
6963
        free(input_type);
6964
        return STRING;
6965
        }
6966
        if( strcmp(input_type, stringup) == 0 ){
6967
        free(input_type);
6968
        return STRINGUP;
6969
        }
6970
        if( strcmp(input_type, opacity) == 0 ){
6971
        free(input_type);
6972
        return OPACITY;
6973
        }
6974
        if( strcmp(input_type, comment) == 0){
6975
        free(input_type);
6976
        return COMMENT;
6977
        }
6978
        if( strcmp(input_type, end) == 0){
6979
        free(input_type);
6980
        return END;
6981
        }
6982
        if( strcmp(input_type, fellipse) == 0){
6983
        free(input_type);
6984
        use_filled = TRUE;
6985
        return ELLIPSE;
7956 schaersvoo 6986
        }      
7614 schaersvoo 6987
        if( strcmp(input_type, blink) == 0 ){
6988
        free(input_type);
6989
        return BLINK;
6990
        }
6991
        if( strcmp(input_type, button) == 0){
6992
        free(input_type);
6993
        return BUTTON;
6994
        }
6995
        if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
6996
        free(input_type);
6997
        return TRANSLATION;
6998
        }
6999
        if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
7000
        free(input_type);
7001
        return KILLTRANSLATION;
7002
        }
7003
        if( strcmp(input_type, rotate) == 0){
7004
        free(input_type);
7005
        return ROTATE;
7006
        }
7785 schaersvoo 7007
        if( strcmp(input_type, affine) == 0){
7008
        free(input_type);
7009
        return AFFINE;
7010
        }
7011
        if( strcmp(input_type, killaffine) == 0){
7012
        free(input_type);
7013
        return KILLAFFINE;
7014
        }
7614 schaersvoo 7015
        if( strcmp(input_type, audio) == 0 ){
7016
        free(input_type);
7017
        return AUDIO;
7018
        }
7019
        if( strcmp(input_type, audioobject) == 0 ){
7020
        free(input_type);
7021
        return AUDIOOBJECT;
7022
        }
7023
        if( strcmp(input_type, slider) == 0 ){
7024
        free(input_type);
7025
        return SLIDER;
7026
        }
8101 schaersvoo 7027
        if( strcmp(input_type, killslider) == 0 ){
7028
        free(input_type);
7029
        return KILLSLIDER;
7030
        }
7614 schaersvoo 7031
        if( strcmp(input_type, copy) == 0 ){
7032
        free(input_type);
7033
        return COPY;
7034
        }
7035
        if( strcmp(input_type, copyresized) == 0 ){
7036
        free(input_type);
7037
        return COPYRESIZED;
7038
        }
7039
        if( strcmp(input_type, patternfill) == 0 ){
7040
        free(input_type);
7041
        return PATTERNFILL;
7042
        }
7043
        if( strcmp(input_type, hatchfill) == 0 ){
7044
        free(input_type);
7045
        return HATCHFILL;
7046
        }
7647 schaersvoo 7047
        if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
7614 schaersvoo 7048
        free(input_type);
7647 schaersvoo 7049
        return DIAMONDFILL;
7614 schaersvoo 7050
        }
7051
        if( strcmp(input_type, dotfill) == 0 ){
7052
        free(input_type);
7053
        return DOTFILL;
7054
        }
7055
        if( strcmp(input_type, gridfill) == 0 ){
7056
        free(input_type);
7057
        return GRIDFILL;
7058
        }
7059
        if( strcmp(input_type, imagefill) == 0 ){
7060
        free(input_type);
7061
        return IMAGEFILL;
7062
        }
7063
        if( strcmp(input_type, clicktile_colors) == 0 ){
7064
        free(input_type);
7065
        return CLICKTILE_COLORS;
7066
        }
7067
        if( strcmp(input_type, clicktile) == 0 ){
7068
        free(input_type);
7069
        return CLICKTILE;
7070
        }
7071
        if( strcmp(input_type, xlogscale) == 0 ){
7072
        free(input_type);
7073
        return XLOGSCALE;
7074
        }
7075
        if( strcmp(input_type, ylogscale) == 0 ){
7076
        free(input_type);
7077
        return YLOGSCALE;
7078
        }
7079
        if( strcmp(input_type, xylogscale) == 0 ){
7080
        free(input_type);
7081
        return XYLOGSCALE;
7082
        }
7083
        if( strcmp(input_type, ylogscale) == 0 ){
7084
        free(input_type);
7085
        return YLOGSCALE;
7086
        }
7735 schaersvoo 7087
        if( strcmp(input_type, xlogbase) == 0 ){
7614 schaersvoo 7088
        free(input_type);
7735 schaersvoo 7089
        return XLOGBASE;
7614 schaersvoo 7090
        }
7735 schaersvoo 7091
        if( strcmp(input_type, ylogbase) == 0 ){
7092
        free(input_type);
7093
        return YLOGBASE;
7094
        }
7614 schaersvoo 7095
        if( strcmp(input_type, intooltip) == 0 ){
7096
        free(input_type);
7097
        return INTOOLTIP;
7098
        }
7099
        if( strcmp(input_type,video) == 0 ){
7100
        free(input_type);
7101
        return VIDEO;
7102
        }
7103
        if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
7104
        free(input_type);
7105
        return FLOODFILL;
7956 schaersvoo 7106
        }      
7614 schaersvoo 7107
        if( strcmp(input_type,filltoborder) == 0 ){
7108
        free(input_type);
7109
        return FILLTOBORDER;
7956 schaersvoo 7110
        }      
7614 schaersvoo 7111
        if( strcmp(input_type,clickfill) == 0 ){
7112
        free(input_type);
7113
        return CLICKFILL;
7956 schaersvoo 7114
        }      
7614 schaersvoo 7115
        if( strcmp(input_type, replyformat) == 0 ){
7116
        free(input_type);
7117
        return REPLYFORMAT;
7118
        }
7119
        if( strcmp(input_type, pixelsize) == 0 ){
7120
        free(input_type);
7121
        return PIXELSIZE;
7122
        }
7123
        if( strcmp(input_type, setpixel) == 0 ){
7124
        free(input_type);
7125
        return SETPIXEL;
7126
        }
7127
        if( strcmp(input_type, pixels) == 0 ){
7128
        free(input_type);
7129
        return PIXELS;
7130
        }
7131
        if( strcmp(input_type, clickfillmarge) == 0 ){
7132
        free(input_type);
7133
        return CLICKFILLMARGE;
7134
        }
7135
        if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
7136
        free(input_type);
7137
        return X_AXIS_STRINGS;
7138
        }
7139
        if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
7140
        free(input_type);
7141
        return Y_AXIS_STRINGS;
7142
        }
7143
        if( strcmp(input_type, piechart) == 0  ){
7144
        free(input_type);
7145
        return PIECHART;
7146
        }
7147
        if( strcmp(input_type, barchart) == 0  ){
7148
        free(input_type);
7149
        return BARCHART;
7150
        }
7151
        if( strcmp(input_type, linegraph) == 0  ){
7152
        free(input_type);
7153
        return LINEGRAPH;
7154
        }
7155
        if( strcmp(input_type, clock) == 0  ){
7156
        free(input_type);
7157
        return CLOCK;
7158
        }
7159
        if( strcmp(input_type, legend) == 0  ){
7160
        free(input_type);
7161
        return LEGEND;
7162
        }
7163
        if( strcmp(input_type, legendcolors) == 0  ){
7164
        free(input_type);
7165
        return LEGENDCOLORS;
7166
        }
7167
        if( strcmp(input_type, xlabel) == 0  ){
7168
        free(input_type);
7169
        return XLABEL;
7170
        }
7171
        if( strcmp(input_type, ylabel) == 0  ){
7172
        free(input_type);
7173
        return YLABEL;
7174
        }
7175
        if( strcmp(input_type, animate) == 0  ){
7176
        free(input_type);
7177
        return ANIMATE;
7178
        }
7179
        /* these are bitmap related flydraw commmands...must be removed. eventually */
7180
        if( strcmp(input_type, transparent) == 0 ){
7181
        free(input_type);
7182
        return TRANSPARENT;
7183
        }
7877 schaersvoo 7184
        if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
7614 schaersvoo 7185
        free(input_type);
7186
        return STATUS;
7187
        }
7188
        if( strcmp(input_type, snaptogrid) == 0 ){
7189
        free(input_type);
7190
        return SNAPTOGRID;
7191
        }
7784 schaersvoo 7192
        if( strcmp(input_type, xsnaptogrid) == 0 ){
7193
        free(input_type);
7194
        return XSNAPTOGRID;
7195
        }
7196
        if( strcmp(input_type, ysnaptogrid) == 0 ){
7197
        free(input_type);
7198
        return YSNAPTOGRID;
7199
        }
7652 schaersvoo 7200
        if( strcmp(input_type, userinput_xy) == 0 ){
7614 schaersvoo 7201
        free(input_type);
7652 schaersvoo 7202
        return USERINPUT_XY;
7203
        }
7663 schaersvoo 7204
        if( strcmp(input_type, usertextarea_xy) == 0 ){
7205
        free(input_type);
7206
        return USERTEXTAREA_XY;
7207
        }
7654 schaersvoo 7208
        if( strcmp(input_type, sgraph) == 0 ){
7652 schaersvoo 7209
        free(input_type);
7654 schaersvoo 7210
        return SGRAPH;
7211
        }
7823 schaersvoo 7212
        if( strcmp(input_type, jsmath) == 0 ){
7654 schaersvoo 7213
        free(input_type);
7823 schaersvoo 7214
        return JSMATH;
7215
        }
7858 schaersvoo 7216
        if( strcmp(input_type, trace_jscurve) == 0 ){
7823 schaersvoo 7217
        free(input_type);
7858 schaersvoo 7218
        return TRACE_JSCURVE;
7823 schaersvoo 7219
        }
7858 schaersvoo 7220
        if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
7221
        free(input_type);
7222
        return JSCURVE;
7223
        }
7984 schaersvoo 7224
        if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
7983 schaersvoo 7225
        free(input_type);
7226
        return CENTERSTRING;
7227
        }
7838 schaersvoo 7228
        if( strcmp(input_type, setlimits) == 0 ){
7823 schaersvoo 7229
        free(input_type);
7838 schaersvoo 7230
        return SETLIMITS;
7231
        }
7996 schaersvoo 7232
        if( strcmp(input_type, xunit) == 0 ){
7838 schaersvoo 7233
        free(input_type);
7996 schaersvoo 7234
        return XUNIT;
7235
        }
7236
        if( strcmp(input_type, yunit) == 0 ){
7237
        free(input_type);
7238
        return YUNIT;
7239
        }
7240
        free(input_type);
7614 schaersvoo 7241
        ungetc(c,infile);
7242
        return 0;
7243
}
7856 schaersvoo 7244