Subversion Repositories wimsdev

Rev

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