Subversion Repositories wimsdev

Rev

Rev 8103 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8103 Rev 8195
Line 34... Line 34...
34
    FILE *f;
34
    FILE *f;
35
    int newfont;
35
    int newfont;
36
 
36
 
37
    newfont=0;
37
    newfont=0;
38
    for(cc=fname; isalnum(*cc); cc++);
38
    for(cc=fname; isalnum(*cc); cc++);
39
    if(*cc!=0) error("Bad font name.");
39
    if(*cc!=0) texgif_error("Bad font name.");
40
    snprintf(namebuf,sizeof(namebuf),"%s/%d/%s.font",fontdir,density,fname);
40
    snprintf(namebuf,sizeof(namebuf),"%s/%d/%s.font",fontdir,density,fname);
41
    f=fopen(namebuf,"r"); if(f==NULL) {
41
    f=fopen(namebuf,"r"); if(f==NULL) {
42
        renewfont: mf2font(fname,density);
42
        renewfont: mf2font(fname,density);
43
        f=fopen(namebuf,"r"); newfont=1;
43
        f=fopen(namebuf,"r"); newfont=1;
44
    }
44
    }
45
    if(f==NULL) return NULL;
45
    if(f==NULL) return NULL;
46
    fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
46
    fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
47
    if(l<=0 || l>FILE_LENGTH_LIMIT) return NULL;
47
    if(l<=0 || l>FILE_LENGTH_LIMIT) return NULL;
48
    fcache=xmalloc(l+16);
48
    fcache=xmalloc(l+16);
49
    l2=fread(fcache,1,l,f); if(l2!=l) {
49
    l2=fread(fcache,1,l,f); if(l2!=l) {
50
        error("Error reading font file.");
50
        texgif_error("Error reading font file.");
51
    }
51
    }
52
    memmove(&ft->checksum,fcache,sizeof(int));
52
    memmove(&ft->checksum,fcache,sizeof(int));
53
    memmove(&ft->designsize,fcache+sizeof(int),sizeof(int));
53
    memmove(&ft->designsize,fcache+sizeof(int),sizeof(int));
54
    memmove(&ft->bc,fcache+2*sizeof(int),sizeof(int));
54
    memmove(&ft->bc,fcache+2*sizeof(int),sizeof(int));
55
    memmove(&ft->ec,fcache+3*sizeof(int),sizeof(int));
55
    memmove(&ft->ec,fcache+3*sizeof(int),sizeof(int));
Line 59... Line 59...
59
    ft->cache=fcache;
59
    ft->cache=fcache;
60
    fclose(f);
60
    fclose(f);
61
    if(checksum!=ft->checksum && checksum!=0 && ft->checksum!=0) {
61
    if(checksum!=ft->checksum && checksum!=0 && ft->checksum!=0) {
62
        if(newfont) {
62
        if(newfont) {
63
            fprintf(stderr,"%08X != %08X\n",checksum, ft->checksum);
63
            fprintf(stderr,"%08X != %08X\n",checksum, ft->checksum);
64
            error("Font checksum discord.");
64
            texgif_error("Font checksum discord.");
65
        }
65
        }
66
        free(fcache); unlink(namebuf); goto renewfont;
66
        free(fcache); unlink(namebuf); goto renewfont;
67
    }
67
    }
68
    return ft;
68
    return ft;
69
}
69
}