Subversion Repositories wimsdev

Rev

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