Rev 10 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 1 | /* Copyright (C) 2002-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
2 | * |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
17 | |||
18 | /* tex 2 gif translator, font loader */ |
||
8103 | bpr | 19 | #include "texgif.h" |
10 | reyssat | 20 | |
21 | void mf2font(char *fontname, int density) |
||
22 | { |
||
23 | loadtfm(fontname); |
||
24 | makegf(fontname,density); |
||
25 | loadgf(fontname,density); |
||
26 | gf2font(fontname,density); |
||
27 | } |
||
28 | |||
29 | FONT *loadfont(char *fname, int checksum, int density, FONT *ft) |
||
30 | { |
||
31 | char namebuf[2048]; |
||
32 | char *fcache, *cc; |
||
33 | long int l,l2; |
||
34 | FILE *f; |
||
35 | int newfont; |
||
8103 | bpr | 36 | |
10 | reyssat | 37 | newfont=0; |
8103 | bpr | 38 | for(cc=fname; isalnum(*cc); cc++); |
10 | reyssat | 39 | if(*cc!=0) error("Bad font name."); |
40 | snprintf(namebuf,sizeof(namebuf),"%s/%d/%s.font",fontdir,density,fname); |
||
41 | f=fopen(namebuf,"r"); if(f==NULL) { |
||
42 | renewfont: mf2font(fname,density); |
||
43 | f=fopen(namebuf,"r"); newfont=1; |
||
44 | } |
||
45 | if(f==NULL) return NULL; |
||
46 | fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET); |
||
47 | if(l<=0 || l>FILE_LENGTH_LIMIT) return NULL; |
||
48 | fcache=xmalloc(l+16); |
||
49 | l2=fread(fcache,1,l,f); if(l2!=l) { |
||
50 | error("Error reading font file."); |
||
51 | } |
||
52 | memmove(&ft->checksum,fcache,sizeof(int)); |
||
53 | memmove(&ft->designsize,fcache+sizeof(int),sizeof(int)); |
||
54 | memmove(&ft->bc,fcache+2*sizeof(int),sizeof(int)); |
||
55 | memmove(&ft->ec,fcache+3*sizeof(int),sizeof(int)); |
||
56 | ft->cnt=ft->ec-ft->bc+1; |
||
57 | cc=fcache+4*sizeof(int); ft->fh=(FONTHEADER *) cc; |
||
58 | ft->data=fcache+4*sizeof(int)+ft->cnt*sizeof(FONTHEADER); |
||
59 | ft->cache=fcache; |
||
60 | fclose(f); |
||
61 | if(checksum!=ft->checksum && checksum!=0 && ft->checksum!=0) { |
||
62 | if(newfont) { |
||
63 | fprintf(stderr,"%08X != %08X\n",checksum, ft->checksum); |
||
64 | error("Font checksum discord."); |
||
65 | } |
||
66 | free(fcache); unlink(namebuf); goto renewfont; |
||
67 | } |
||
68 | return ft; |
||
69 | } |
||
70 |