Subversion Repositories wimsdev

Rev

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

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