Back to index

wims  3.65+svn20090927
tfm.c
Go to the documentation of this file.
00001 /*    Copyright (C) 2002-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018 /* dvi 2 gif driver, tfm loader */
00019 
00020 struct tfm {
00021     int bc, ec;
00022     int checksum, designsize;
00023     struct f {
00024        long int w,h,d;
00025     } f[256];
00026 } tfm;
00027 
00028 short int tfmhd[12];
00029 
00030 #define tfmlf tfmhd[0]
00031 #define tfmlh tfmhd[1]
00032 #define tfmbc tfmhd[2]
00033 #define tfmec tfmhd[3]
00034 #define tfmnw tfmhd[4]
00035 #define tfmnh tfmhd[5]
00036 #define tfmnd tfmhd[6]
00037 #define tfmni tfmhd[7]
00038 #define tfmnl tfmhd[8]
00039 #define tfmnk tfmhd[9]
00040 #define tfmne tfmhd[10]
00041 #define tfmnp tfmhd[11]
00042 
00043 void loadtfm(char *fname)
00044 {
00045     int i, k, t, len, charcnt;
00046     char namebuf[1024];
00047     long int *wpbase;
00048     long int *headp, *fp, *fip, *wp, *hp, *dp;
00049     unsigned char *tfmbuf, *ftp;
00050 
00051     memset(&tfm,0,sizeof(tfm));
00052     snprintf(namebuf,sizeof(namebuf),"%s/%s.tfm",tmpdir,fname);
00053     call_sh("cp `kpsewhich %s.tfm` %s",fname,tmpdir);
00054     len=getfile(namebuf,&tfmbuf); unlink(namebuf);
00055     if(len<0) {
00056        error("Error reading tfm file.");
00057     }
00058     for(i=0;i<12;i++) tfmhd[i]=texint(tfmbuf+2*i,2);
00059     tfm.bc=tfmbc; tfm.ec=tfmec;
00060     charcnt=tfmec-tfmbc+1;
00061     if(charcnt<=0) return;
00062     wpbase=(long int *) tfmbuf;
00063     headp=wpbase+6;         /* header */
00064     fp=headp+tfmlh;         /* font info */
00065     wp=fp+charcnt;          /* width table */
00066     hp=wp+tfmnw;            /* height table */
00067     dp=hp+tfmnh;            /* depth table */
00068     tfm.checksum=headp[0];
00069     tfm.designsize=texint(headp+1,4);
00070     for(i=0, t=tfmbc;i<charcnt; i++,t++) {
00071        fip=fp+i; ftp=(unsigned char *) fip;
00072        k=*ftp; tfm.f[t].w=texint(wp+k,4); ftp++;
00073        k=((*ftp)>>4)&15; tfm.f[t].h=texint(hp+k,4);
00074        k=(*ftp)&15; tfm.f[t].d=texint(dp+k,4);
00075     }
00076     free(tfmbuf);
00077 }
00078