Subversion Repositories wimsdev

Rev

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