Subversion Repositories wimsdev

Rev

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