Subversion Repositories wimsdev

Rev

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