Subversion Repositories wimsdev

Rev

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

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