Subversion Repositories wimsdev

Rev

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