Subversion Repositories wimsdev

Rev

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

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