Subversion Repositories wimsdev

Rev

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