Subversion Repositories wimsdev

Rev

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

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