Subversion Repositories wimsdev

Rev

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

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