Subversion Repositories wimsdev

Rev

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