Subversion Repositories wimsdev

Rev

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