Subversion Repositories wimsdev

Rev

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

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