Back to index

tetex-bin  3.0
tfm.c
Go to the documentation of this file.
00001 /* tfm.c */
00002 
00003 /************************************************************************
00004 
00005   Part of the dvipng distribution
00006 
00007   This program is free software; you can redistribute it and/or modify
00008   it under the terms of the GNU General Public License as published by
00009   the Free Software Foundation; either version 2 of the License, or
00010   (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful, but
00013   WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; if not, write to the Free Software
00019   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020   02111-1307, USA.
00021 
00022   Copyright (C) 2002-2005 Jan-Åke Larsson
00023 
00024 ************************************************************************/
00025 
00026 #include "dvipng.h"
00027 #if HAVE_ALLOCA_H
00028 # include <alloca.h>
00029 #endif
00030 
00031 bool ReadTFM(struct font_entry * tfontp, char* tfmname)
00032 {
00033   struct filemmap fmmap;
00034   struct char_entry *tcharptr;  
00035   unsigned char *position; 
00036   int lh,bc,ec,nw, c;
00037   dviunits* width;
00038 
00039   DEBUG_PRINT((DEBUG_DVI|DEBUG_FT|DEBUG_TFM),
00040              ("\n  OPEN METRICS:\t'%s'", tfmname));
00041   if (MmapFile(tfmname,&fmmap)) return(false);
00042   position=(unsigned char*)fmmap.mmap;
00043   lh = UNumRead(position+2,2);
00044   bc = UNumRead(position+4,2);
00045   ec = UNumRead(position+6,2);
00046   nw = UNumRead(position+8,2);
00047   DEBUG_PRINT(DEBUG_TFM,(" %d %d %d %d",lh,bc,ec,nw));
00048   width=alloca(nw*sizeof(dviunits));  
00049   c=0;
00050   position=position+24+(lh+ec-bc+1)*4;
00051   while( c < nw ) {
00052     width[c] = SNumRead(position,4);
00053     c++;
00054     position += 4; 
00055   }
00056   
00057   /* Read char widths */
00058   c=bc;
00059   position=(unsigned char*)fmmap.mmap+24+lh*4;
00060   while(c <= ec) {
00061     DEBUG_PRINT(DEBUG_TFM,("\n@%ld TFM METRICS:\t", 
00062                         (long)position - (long)fmmap.mmap));
00063     tcharptr=xmalloc(sizeof(struct char_entry));
00064     tcharptr->data=NULL;
00065     tcharptr->tfmw=width[*position];
00066     DEBUG_PRINT(DEBUG_TFM,("%d [%d] %d",c,*position,tcharptr->tfmw));
00067     tcharptr->tfmw = (dviunits) 
00068       ((int64_t) tcharptr->tfmw * tfontp->s / (1 << 20));
00069     DEBUG_PRINT(DEBUG_TFM,(" (%d)",tcharptr->tfmw));
00070     if (c > NFNTCHARS) /* Only positive for now */
00071       Fatal("tfm character exceeds numbering limit");
00072     tfontp->chr[c] = tcharptr;
00073     c++;
00074     position += 4;
00075   }
00076   UnMmapFile(&fmmap);
00077   return(true);
00078 }
00079   
00080