Subversion Repositories wimsdev

Rev

Rev 10 | 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. /* dvi 2 gif driver, tfm loader */
  19.  
  20. struct tfm {
  21.     int bc, ec;
  22.     int checksum, designsize;
  23.     struct f {
  24.         int32_t w,h,d;
  25.     } f[256];
  26. } tfm;
  27.  
  28. short int tfmhd[12];
  29.  
  30. #define tfmlf tfmhd[0]
  31. #define tfmlh tfmhd[1]
  32. #define tfmbc tfmhd[2]
  33. #define tfmec tfmhd[3]
  34. #define tfmnw tfmhd[4]
  35. #define tfmnh tfmhd[5]
  36. #define tfmnd tfmhd[6]
  37. #define tfmni tfmhd[7]
  38. #define tfmnl tfmhd[8]
  39. #define tfmnk tfmhd[9]
  40. #define tfmne tfmhd[10]
  41. #define tfmnp tfmhd[11]
  42.  
  43. void loadtfm(char *fname)
  44. {
  45.     int i, k, t, len, charcnt;
  46.     char namebuf[1024];
  47.     int32_t *wpbase;
  48.     int32_t *headp, *fp, *fip, *wp, *hp, *dp;
  49.     unsigned char *tfmbuf, *ftp;
  50.  
  51.     memset(&tfm,0,sizeof(tfm));
  52.     snprintf(namebuf,sizeof(namebuf),"%s/%s.tfm",tmpdir,fname);
  53.     call_sh("cp `kpsewhich %s.tfm` %s",fname,tmpdir);
  54.     len=getfile(namebuf,&tfmbuf); unlink(namebuf);
  55.     if(len<0) {
  56.         error("Error reading tfm file.");
  57.     }
  58.     for(i=0;i<12;i++) tfmhd[i]=texint(tfmbuf+2*i,2);
  59.     tfm.bc=tfmbc; tfm.ec=tfmec;
  60.     charcnt=tfmec-tfmbc+1;
  61.     if(charcnt<=0) return;
  62.     wpbase=(int32_t *) tfmbuf;
  63.     headp=wpbase+6;             /* header */
  64.     fp=headp+tfmlh;             /* font info */
  65.     wp=fp+charcnt;              /* width table */
  66.     hp=wp+tfmnw;                /* height table */
  67.     dp=hp+tfmnh;                /* depth table */
  68.     tfm.checksum=headp[0];
  69.     tfm.designsize=texint(headp+1,4);
  70.     for(i=0, t=tfmbc;i<charcnt; i++,t++) {
  71.         fip=fp+i; ftp=(unsigned char *) fip;
  72.         k=*ftp; tfm.f[t].w=texint(wp+k,4); ftp++;
  73.         k=((*ftp)>>4)&15; tfm.f[t].h=texint(hp+k,4);
  74.         k=(*ftp)&15; tfm.f[t].d=texint(dp+k,4);
  75.     }
  76.     free(tfmbuf);
  77. }
  78.  
  79.