Subversion Repositories wimsdev

Rev

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

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