Subversion Repositories wimsdev

Rev

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