Subversion Repositories wimsdev

Rev

Rev 7747 | Rev 7749 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7747 Rev 7748
Line 180... Line 180...
180
        type = get_token(infile);
180
        type = get_token(infile);
181
        done = FALSE;
181
        done = FALSE;
182
        /*
182
        /*
183
        @canvasdraw
183
        @canvasdraw
184
        @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...)
184
        @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...)
185
        @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>
-
 
186
        <li>a fillable object can be set fillable by starting the object command with an 'f'<br />(like frect,fcircle,ftriangle...)<br />or by using the keyword 'filled' before the object command.<br />The fill colour will be the stroke colour...(19/10/2013)<li> a draggable object can be set draggable by a preceding command 'drag x/y/xy'<br />The translation can be read by javascript:read_dragdrop();<br />Multiple objects may be set draggable / clickable (no limit)<br /> not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on zoom and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword 'onclick'<br />not all flydraw objects can be set clickable</li></ul>
185
        @General syntax <ul><li>The transparency of all objects can be controlled by command 'opacity [0-255],[0,255]'</il><li>a line based object can be controlled by command 'linewidth int'</li><li>a line based object may be dashed by using keyword 'dashed' before the object command.<br />the dashing type can be controled by command 'dashtype int,int'</li><li>a fillable object can be set fillable by starting the object command with an 'f'<br />(like frect,fcircle,ftriangle...)<br />or by using the keyword 'filled' before the object command.<br />The fill colour will be the stroke colour...(19/10/2013)<li> a draggable object can be set draggable by a preceding command 'drag x/y/xy'<br />The translation can be read by javascript:read_dragdrop();<br />Multiple objects may be set draggable / clickable (no limit)<br /> not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on zoom and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword 'onclick'<br />not all flydraw objects can be set clickable</li><li><b>remarks using a ';' as command separator</b><br />commands with only numeric or colour arguments may be using a ';' as command separator (in stead of a new line)<br />commands with a string argument may not use a ';' as command separator !<br />these exceptions are not really straight forward... so keep this in mind.<br />example:<br />size 200,200;xrange -5,5;yrange -5,5;hline 0,0,black;vline 0,0,black<br />plot red,sin(x)<br />drag xy<br />html 0,0,5,-5, &euro; <br />lines green,2,0,2,-2,-2,2,-2,0;rectangle 1,1,4,4,purple;frectangle -1,-1,-4,-4,yellow</li></ul>
187
        */
186
        */
188
        switch(type){
187
        switch(type){
189
        case END:
188
        case END:
190
        finished = 1;
189
        finished = 1;
191
        done = TRUE;
190
        done = TRUE;
Line 2773... Line 2772...
2773
}
2772
}
2774
 
2773
 
2775
char *get_color(FILE *infile , int last){
2774
char *get_color(FILE *infile , int last){
2776
    int c,i = 0,is_hex = 0;
2775
    int c,i = 0,is_hex = 0;
2777
    char temp[MAX_COLOR_STRING], *string;
2776
    char temp[MAX_COLOR_STRING], *string;
2778
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' )  && ( c != ';')){
2777
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
2779
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
2778
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
2780
        if( c == '#' ){
2779
        if( c == '#' ){
2781
            is_hex = 1;
2780
            is_hex = 1;
2782
        }
2781
        }
2783
        if( c != ' '){
2782
        if( c != ' '){
2784
            temp[i]=tolower(c);
2783
            temp[i]=tolower(c);
2785
            i++;
2784
            i++;
2786
        }
2785
        }
2787
    }
2786
    }
2788
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
2787
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
2789
    if( c == '\n' || c == ';'){ done = TRUE; line_number++; }
2788
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
2790
    if( c == EOF ){finished = 1;}
2789
    if( c == EOF ){finished = 1;}
2791
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
2790
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
2792
    temp[i]='\0';
2791
    temp[i]='\0';
2793
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
2792
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
2794
    if( is_hex == 1 ){
2793
    if( is_hex == 1 ){
Line 2820... Line 2819...
2820
}
2819
}
2821
 
2820
 
2822
char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
2821
char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
2823
    int c,i=0;
2822
    int c,i=0;
2824
    char  temp[MAX_BUFFER], *string;
2823
    char  temp[MAX_BUFFER], *string;
2825
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ';' )){
2824
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
2826
        temp[i]=c;
2825
        temp[i]=c;
2827
        i++;
2826
        i++;
2828
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
2827
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
2829
    }
2828
    }
2830
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
2829
    if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
2831
    if( c == '\n' || c == ';') { done = TRUE; line_number++; }
2830
    if( c == '\n') { done = TRUE; line_number++; }
2832
    if( c == EOF ) {
2831
    if( c == EOF ) {
2833
        finished = 1;
2832
        finished = 1;
2834
        if( last != 1 ){ canvas_error("expected more arguments");}
2833
        if( last != 1 ){ canvas_error("expected more arguments");}
2835
    }
2834
    }
2836
    temp[i]='\0';
2835
    temp[i]='\0';
2837
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
2836
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
2838
    string=(char *)my_newmem(strlen(temp));
2837
    string=(char *)my_newmem(strlen(temp));
2839
    snprintf(string,sizeof(temp),"%s",temp);
2838
    snprintf(string,sizeof(temp),"%s",temp);
2840
    return string;
2839
    return string;
2841
}
2840
}
2842
 
2841
 
2843
char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
2842
char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
2844
    int c,i=0;
2843
    int c,i=0;
2845
    char temp[MAX_BUFFER], *string;
2844
    char temp[MAX_BUFFER], *string;
2846
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',') && ( c != ';' )){
2845
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
2847
        temp[i]=c;
2846
        temp[i]=c;
2848
        i++;
2847
        i++;
2849
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
2848
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
2850
    }
2849
    }
2851
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
2850
    if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
2852
    if( c == '\n' || c == ';') { line_number++; }
2851
    if( c == '\n') { line_number++; }
2853
    if( c == EOF ) {finished = 1;}
2852
    if( c == EOF ) {finished = 1;}
2854
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
2853
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
2855
    temp[i]='\0';
2854
    temp[i]='\0';
2856
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
2855
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
2857
    string=(char *)my_newmem(sizeof(temp));
2856
    string=(char *)my_newmem(sizeof(temp));
Line 2969... Line 2968...
2969
    {
2968
    {
2970
        return y2px( dx );/* convert to pixels according yrange */
2969
        return y2px( dx );/* convert to pixels according yrange */
2971
    }
2970
    }
2972
}
2971
}
2973
void canvas_error(char *msg){
2972
void canvas_error(char *msg){
2974
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg);
2973
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
2975
    finished = 1;
2974
    finished = 1;
2976
    exit(EXIT_SUCCESS);
2975
    exit(EXIT_SUCCESS);
2977
}
2976
}
2978
 
2977
 
2979
 
2978