Subversion Repositories wimsdev

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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 */
  19.  
  20. void mf2font(char *fontname, int density)
  21. {
  22.     loadtfm(fontname);
  23.     makegf(fontname,density);
  24.     loadgf(fontname,density);
  25.     gf2font(fontname,density);
  26. }
  27.  
  28. FONT *loadfont(char *fname, int checksum, int density, FONT *ft)
  29. {
  30.     char namebuf[2048];
  31.     char *fcache, *cc;
  32.     long int l,l2;
  33.     FILE *f;
  34.     int newfont;
  35.    
  36.     newfont=0;
  37.     for(cc=fname; isalnum(*cc); cc++);
  38.     if(*cc!=0) error("Bad font name.");
  39.     snprintf(namebuf,sizeof(namebuf),"%s/%d/%s.font",fontdir,density,fname);
  40.     f=fopen(namebuf,"r"); if(f==NULL) {
  41.         renewfont: mf2font(fname,density);
  42.         f=fopen(namebuf,"r"); newfont=1;
  43.     }
  44.     if(f==NULL) return NULL;
  45.     fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
  46.     if(l<=0 || l>FILE_LENGTH_LIMIT) return NULL;
  47.     fcache=xmalloc(l+16);
  48.     l2=fread(fcache,1,l,f); if(l2!=l) {
  49.         error("Error reading font file.");
  50.     }
  51.     memmove(&ft->checksum,fcache,sizeof(int));
  52.     memmove(&ft->designsize,fcache+sizeof(int),sizeof(int));
  53.     memmove(&ft->bc,fcache+2*sizeof(int),sizeof(int));
  54.     memmove(&ft->ec,fcache+3*sizeof(int),sizeof(int));
  55.     ft->cnt=ft->ec-ft->bc+1;
  56.     cc=fcache+4*sizeof(int); ft->fh=(FONTHEADER *) cc;
  57.     ft->data=fcache+4*sizeof(int)+ft->cnt*sizeof(FONTHEADER);
  58.     ft->cache=fcache;
  59.     fclose(f);
  60.     if(checksum!=ft->checksum && checksum!=0 && ft->checksum!=0) {
  61.         if(newfont) {
  62.             fprintf(stderr,"%08X != %08X\n",checksum, ft->checksum);
  63.             error("Font checksum discord.");
  64.         }
  65.         free(fcache); unlink(namebuf); goto renewfont;
  66.     }
  67.     return ft;
  68. }
  69.  
  70.