Rev 7785 | Rev 7788 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7785 | Rev 7786 | ||
---|---|---|---|
Line 47... | Line 47... | ||
47 | int x2px(double x); |
47 | int x2px(double x); |
48 | int y2px(double y); |
48 | int y2px(double y); |
49 | double px2x(int x); |
49 | double px2x(int x); |
50 | double px2y(int y); |
50 | double px2y(int y); |
51 | double get_real(FILE *infile,int last); /* read a values; calculation and symbols allowed */ |
51 | double get_real(FILE *infile,int last); /* read a values; calculation and symbols allowed */ |
52 | double get_double(FILE *infile , int orientation , int last); /*the same as get_real(): but for an unknown amount of data args*/ |
- | |
53 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
52 | char *str_replace ( const char *word, const char *sub_word, const char *rep_word ); |
54 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
53 | char *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */ |
55 | char *get_string(FILE *infile,int last); /* get the string at theend of a command */ |
54 | char *get_string(FILE *infile,int last); /* get the string at theend of a command */ |
56 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
55 | char *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as separator */ |
57 | char *convert_hex2rgb(char *hexcolor); |
56 | char *convert_hex2rgb(char *hexcolor); |
Line 733... | Line 732... | ||
733 | break; |
732 | break; |
734 | case RAYS: |
733 | case RAYS: |
735 | /* |
734 | /* |
736 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
735 | @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n |
737 | @ draw rays in color 'color' and center (xc:yc) |
736 | @ draw rays in color 'color' and center (xc:yc) |
738 | @ may be set draggable or onclick ( |
737 | @ may be set draggable or onclick (every individual ray) |
739 | */ |
738 | */ |
740 | stroke_color=get_color(infile,0); |
739 | stroke_color=get_color(infile,0); |
- | 740 | fill_color = stroke_color; |
|
- | 741 | double_data[0] = get_real(infile,0);/* xc */ |
|
- | 742 | double_data[1] = get_real(infile,0);/* yc */ |
|
741 | i= |
743 | i=2; |
742 | while( ! done ){ /* get next until EOL*/ |
744 | while( ! done ){ /* get next item until EOL*/ |
743 | if(i > MAX_INT - 1){canvas_error("to |
745 | if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");} |
744 | if( |
746 | if(i%2 == 0 ){ |
745 | double_data[i++] = double_data[0]; |
- | |
746 | double_data[i++] = double_data[1]; |
- | |
747 | } |
- | |
748 | for(c=0; c<=1 ;c++){ /* switch x2px / y2px */ |
- | |
749 | double_data[i |
747 | double_data[i] = get_real(infile,0); /* x */ |
750 | } |
748 | } |
- | 749 | else |
|
- | 750 | { |
|
- | 751 | double_data[i] = get_real(infile,1); /* y */ |
|
- | 752 | } |
|
- | 753 | fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]); |
|
- | 754 | i++; |
|
751 | } |
755 | } |
- | 756 | ||
- | 757 | if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");} |
|
752 | decimals = find_number_of_digits(precision); |
758 | decimals = find_number_of_digits(precision); |
753 | for(c= |
759 | for(c=2; c<i;c = c+2){ |
754 | click_cnt++; |
760 | click_cnt++; |
755 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c |
761 | fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix); |
756 | } |
762 | } |
757 | reset(); |
763 | reset(); |
758 | break; |
764 | break; |
759 | case ARROW: |
765 | case ARROW: |
760 | /* |
766 | /* |
Line 1655... | Line 1661... | ||
1655 | @ note 3: no matrix operations on the transformation matrix implemented (yet) |
1661 | @ note 3: no matrix operations on the transformation matrix implemented (yet) |
1656 | @ a : Scales the drawings horizontally |
1662 | @ a : Scales the drawings horizontally |
1657 | @ b : Skews the drawings horizontally |
1663 | @ b : Skews the drawings horizontally |
1658 | @ c : Skews the drawings vertically |
1664 | @ c : Skews the drawings vertically |
1659 | @ d : Scales the drawings vertically |
1665 | @ d : Scales the drawings vertically |
1660 | @ tx: Moves |
1666 | @ tx: Moves the drawings horizontally in pixels ! |
1661 | @ ty: Moves |
1667 | @ ty: Moves the drawings vertically in pixels ! |
1662 | */ |
1668 | */ |
1663 | for(i = 0 ; i<6;i++){ |
1669 | for(i = 0 ; i<6;i++){ |
1664 | switch(i){ |
1670 | switch(i){ |
1665 | case 0: double_data[0] = get_real(infile,0);break; |
1671 | case 0: double_data[0] = get_real(infile,0);break; |
1666 | case 1: double_data[1] = get_real(infile,0);break; |
1672 | case 1: double_data[1] = get_real(infile,0);break; |
Line 2142... | Line 2148... | ||
2142 | @ gridfill x0,y0,dx,dy,color |
2148 | @ gridfill x0,y0,dx,dy,color |
2143 | @ x0,y0 in xrange / yrange |
2149 | @ x0,y0 in xrange / yrange |
2144 | @ distances dx,dy in pixels |
2150 | @ distances dx,dy in pixels |
2145 | */ |
2151 | */ |
2146 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
2152 | if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;} |
2147 | for(i=0;i<5;i++){ |
2153 | for(i=0;i<5;i++){ |
2148 | switch(i){ |
2154 | switch(i){ |
2149 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
2155 | case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */ |
2150 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
2156 | case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y */ |
2151 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
2157 | case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */ |
2152 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
2158 | case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/ |
2153 | case 4: stroke_color = get_color(infile,1); |
2159 | case 4: stroke_color = get_color(infile,1); |
2154 | /* draw_gridfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
2160 | /* draw_gridfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */ |
2155 | 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); |
2161 | string_length = snprintf(NULL,0, "draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
2156 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
2162 | check_string_length(string_length);tmp_buffer = my_newmem(string_length+1); |
2157 | 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); |
2163 | snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize); |
2158 | add_to_buffer(tmp_buffer); |
2164 | add_to_buffer(tmp_buffer); |
Line 2934... | Line 2940... | ||
2934 | else |
2940 | else |
2935 | { |
2941 | { |
2936 | y = atof(tmp); |
2942 | y = atof(tmp); |
2937 | } |
2943 | } |
2938 | return y; |
2944 | return y; |
2939 | } |
- | |
2940 | - | ||
2941 | double get_double(FILE *infile , int orientation , int last){ /* last = 0 : more arguments ; last=1 final argument */ |
- | |
2942 | /* orientation=0 : x-values ... orientation=1 :y-values */ |
- | |
2943 | int c; |
- | |
2944 | int i = 0; |
- | |
2945 | int found_calc = 0; /* signal user input like : 2*pi/3 */ |
- | |
2946 | char tmp[MAX_INT]; |
- | |
2947 | double dx; |
- | |
2948 | while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){ |
- | |
2949 | if( c != ' '){/* no spaces in numbers */ |
- | |
2950 | if(canvas_iscalculation(c) != 0 ){ |
- | |
2951 | found_calc = 1; |
- | |
2952 | c = tolower(c); |
- | |
2953 | } |
- | |
2954 | tmp[i]=c; |
- | |
2955 | i++; |
- | |
2956 | if( i > MAX_INT-1){canvas_error("number too large");} |
- | |
2957 | } |
- | |
2958 | } |
- | |
2959 | if( c == '\n' || c == EOF || c == ';' ){ |
- | |
2960 | if( last == 0 ){canvas_error("expecting more arguments");} |
- | |
2961 | if( c == EOF ){finished = TRUE;} |
- | |
2962 | done = TRUE; |
- | |
2963 | /*return 0; */ |
- | |
2964 | } |
- | |
2965 | tmp[i]='\0'; |
- | |
2966 | - | ||
2967 | if( strlen(tmp) == 0 || i == 0){ |
- | |
2968 | if( orientation == 0 ){ |
- | |
2969 | canvas_error("expected a x-value \n e.g. a number in x-range / y-range coordinate system\nbut found nothing !!"); |
- | |
2970 | } |
- | |
2971 | else |
- | |
2972 | { |
- | |
2973 | canvas_error("expected a y-value \n e.g. a number in x-range / y-range coordinate system\nbut found nothing !!"); |
- | |
2974 | } |
- | |
2975 | } |
- | |
2976 | if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */ |
- | |
2977 | void *f = evaluator_create(tmp); |
- | |
2978 | assert(f); |
- | |
2979 | if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ");} |
- | |
2980 | dx = evaluator_evaluate_x(f, 1); |
- | |
2981 | evaluator_destroy(f); |
- | |
2982 | } |
- | |
2983 | else |
- | |
2984 | { |
- | |
2985 | dx = atof(tmp); /* no pi/e/sin(2*pi/3) found : will use atof to convert inputstring to float */ |
- | |
2986 | } |
- | |
2987 | if( c == '\n' || c == ';') { line_number++; } |
- | |
2988 | if( c != EOF ) { |
- | |
2989 | if( c == '\n' || c ==';') { |
- | |
2990 | done = TRUE; |
- | |
2991 | } |
- | |
2992 | } |
- | |
2993 | else |
- | |
2994 | { |
- | |
2995 | finished = TRUE; |
- | |
2996 | } |
- | |
2997 | if( (done == TRUE || finished == TRUE) && last != 1 ){ canvas_error("expected more arguments");} |
- | |
2998 | if(orientation == 0){ |
- | |
2999 | return x2px( dx ); /* convert to pixels according xrange */ |
- | |
3000 | } |
- | |
3001 | else |
- | |
3002 | { |
- | |
3003 | return y2px( dx );/* convert to pixels according yrange */ |
- | |
3004 | } |
- | |
3005 | } |
2945 | } |
3006 | void canvas_error(char *msg){ |
2946 | void canvas_error(char *msg){ |
3007 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg); |
2947 | fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg); |
3008 | finished = 1; |
2948 | finished = 1; |
3009 | exit(EXIT_SUCCESS); |
2949 | exit(EXIT_SUCCESS); |
Line 5032... | Line 4972... | ||
5032 | ctx.moveTo(zero_x,0);\ |
4972 | ctx.moveTo(zero_x,0);\ |
5033 | ctx.lineTo(zero_x,ysize);\ |
4973 | ctx.lineTo(zero_x,ysize);\ |
5034 | ctx.stroke();\ |
4974 | ctx.stroke();\ |
5035 | ctx.closePath();\ |
4975 | ctx.closePath();\ |
5036 | ctx.lineWidth = line_width+0.5;\ |
4976 | ctx.lineWidth = line_width+0.5;\ |
5037 | ctx.beginPath();\ |
4977 | ctx.beginPath();\ |
5038 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
4978 | for(var p = zero_x ; p < xsize; p = p + xstep){\ |
5039 | ctx.moveTo(p,zero_y-tics_length);\ |
4979 | ctx.moveTo(p,zero_y-tics_length);\ |
5040 | ctx.lineTo(p,zero_y+tics_length);\ |
4980 | ctx.lineTo(p,zero_y+tics_length);\ |
5041 | };\ |
4981 | };\ |
5042 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
4982 | for(var p = zero_x ; p > 0; p = p - xstep){\ |
Line 5205... | Line 5145... | ||
5205 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
5145 | try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\ |
5206 | };\ |
5146 | };\ |
5207 | };\ |
5147 | };\ |
5208 | var barcolor = new Array();\ |
5148 | var barcolor = new Array();\ |
5209 | if( typeof barchart%d !== 'undefined' ){\ |
5149 | if( typeof barchart%d !== 'undefined' ){\ |
5210 | ctx.restore();\ |
5150 | ctx.restore();\ |
5211 | ctx.save();\ |
5151 | ctx.save();\ |
5212 | ctx.globalAlpha = 1.0;\ |
5152 | ctx.globalAlpha = 1.0;\ |
5213 | var bar_x = new Array();\ |
5153 | var bar_x = new Array();\ |
5214 | var bar_y = new Array();\ |
5154 | var bar_y = new Array();\ |
5215 | var lb = barchart%d.length;\ |
5155 | var lb = barchart%d.length;\ |
5216 | var idx = 0;\ |
5156 | var idx = 0;\ |
Line 5556... | Line 5496... | ||
5556 | clock_ctx.closePath();\ |
5496 | clock_ctx.closePath();\ |
5557 | clock_ctx.stroke();\ |
5497 | clock_ctx.stroke();\ |
5558 | break;\ |
5498 | break;\ |
5559 | };\ |
5499 | };\ |
5560 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
5500 | angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\ |
5561 | clock_ctx.rotate(angle);\ |
5501 | clock_ctx.rotate(angle);\ |
5562 | clock_ctx.beginPath();\ |
5502 | clock_ctx.beginPath();\ |
5563 | clock_ctx.moveTo(-3, -2);\ |
5503 | clock_ctx.moveTo(-3, -2);\ |
5564 | clock_ctx.lineTo(-3, 2);\ |
5504 | clock_ctx.lineTo(-3, 2);\ |
5565 | clock_ctx.lineTo(this.radius * 0.7, 1);\ |
5505 | clock_ctx.lineTo(this.radius * 0.7, 1);\ |
5566 | clock_ctx.lineTo(this.radius * 0.7, -1);\ |
5506 | clock_ctx.lineTo(this.radius * 0.7, -1);\ |
Line 5731... | Line 5671... | ||
5731 | break; |
5671 | break; |
5732 | 5672 | ||
5733 | case DRAW_XLOGSCALE: |
5673 | case DRAW_XLOGSCALE: |
5734 | fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\ |
5674 | fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\ |
5735 | draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,ymajor,yminor,precision){\n\ |
5675 | draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,ymajor,yminor,precision){\n\ |
5736 | var obj;\n\ |
5676 | var obj;\n\ |
5737 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\ |
5677 | if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\n\ |
5738 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\ |
5678 | obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\n\ |
5739 | }\n\ |
5679 | }\n\ |
5740 | else\n\ |
5680 | else\n\ |
5741 | {\n\ |
5681 | {\n\ |
5742 | obj = create_canvas%d(canvas_type,xsize,ysize);\n\ |
5682 | obj = create_canvas%d(canvas_type,xsize,ysize);\n\ |
5743 | };\n\ |
5683 | };\n\ |
5744 | var ctx = obj.getContext(\"2d\");\n\ |
5684 | var ctx = obj.getContext(\"2d\");\n\ |
5745 | ctx.clearRect(0,0,xsize,ysize);\ |
5685 | ctx.clearRect(0,0,xsize,ysize);\ |
5746 | ctx.save();\n\ |
5686 | ctx.save();\n\ |
5747 | ctx.lineWidth = line_width;\n\ |
5687 | ctx.lineWidth = line_width;\n\ |
Line 6002... | Line 5942... | ||
6002 | *arrow2="arrow2", |
5942 | *arrow2="arrow2", |
6003 | *darrow2="darrow2", |
5943 | *darrow2="darrow2", |
6004 | *zoom="zoom", |
5944 | *zoom="zoom", |
6005 | *grid="grid", |
5945 | *grid="grid", |
6006 | *hline="hline", |
5946 | *hline="hline", |
- | 5947 | *dhline="dhline", |
|
6007 | *drag="drag", |
5948 | *drag="drag", |
6008 | *horizontalline="horizontalline", |
5949 | *horizontalline="horizontalline", |
6009 | *vline="vline", |
5950 | *vline="vline", |
- | 5951 | *dvline="dvline", |
|
6010 | *verticalline="verticalline", |
5952 | *verticalline="verticalline", |
6011 | *triangle="triangle", |
5953 | *triangle="triangle", |
6012 | *ftriangle="ftriangle", |
5954 | *ftriangle="ftriangle", |
6013 | *mathml="mathml", |
5955 | *mathml="mathml", |
6014 | *html="html", |
5956 | *html="html", |
Line 6170... | Line 6112... | ||
6170 | if( strcmp(input_type, yrange) == 0 ){ |
6112 | if( strcmp(input_type, yrange) == 0 ){ |
6171 | free(input_type); |
6113 | free(input_type); |
6172 | return YRANGE; |
6114 | return YRANGE; |
6173 | } |
6115 | } |
6174 | if( strcmp(input_type, rangey) == 0 ){ |
6116 | if( strcmp(input_type, rangey) == 0 ){ |
6175 | free(input_type); |
6117 | free(input_type); |
6176 | return YRANGE; |
6118 | return YRANGE; |
6177 | } |
6119 | } |
6178 | if( strcmp(input_type, linewidth) == 0 ){ |
6120 | if( strcmp(input_type, linewidth) == 0 ){ |
6179 | free(input_type); |
6121 | free(input_type); |
6180 | return LINEWIDTH; |
6122 | return LINEWIDTH; |
Line 6434... | Line 6376... | ||
6434 | } |
6376 | } |
6435 | if( strcmp(input_type, dline) == 0 ){ |
6377 | if( strcmp(input_type, dline) == 0 ){ |
6436 | use_dashed = TRUE; |
6378 | use_dashed = TRUE; |
6437 | free(input_type); |
6379 | free(input_type); |
6438 | return LINE; |
6380 | return LINE; |
- | 6381 | } |
|
- | 6382 | if( strcmp(input_type, dvline) == 0 ){ |
|
- | 6383 | use_dashed = TRUE; |
|
- | 6384 | free(input_type); |
|
- | 6385 | return VLINE; |
|
- | 6386 | } |
|
- | 6387 | if( strcmp(input_type, dhline) == 0 ){ |
|
- | 6388 | use_dashed = TRUE; |
|
- | 6389 | free(input_type); |
|
- | 6390 | return HLINE; |
|
6439 | } |
6391 | } |
6440 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
6392 | if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){ |
6441 | use_filled = TRUE; |
6393 | use_filled = TRUE; |
6442 | free(input_type); |
6394 | free(input_type); |
6443 | return RECT; |
6395 | return RECT; |