Back to index

tetex-bin  3.0
vf.c
Go to the documentation of this file.
00001 /* vf.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 
00028 #define VF_ID 202
00029 #define LONG_CHAR 242
00030 
00031 int32_t SetVF(int32_t c) 
00032 {
00033   struct font_entry* currentvf;
00034   unsigned char *command,*end;
00035   struct char_entry* ptr=currentfont->chr[c];
00036 
00037   currentvf=currentfont;
00038   BeginVFMacro(currentvf);
00039   command = ptr->data;
00040   end = command + ptr->length;
00041   while (command < end)  {
00042     DEBUG_PRINT(DEBUG_DVI,("\n  VF MACRO:\t%s ", dvi_commands[*command]));
00043     DrawCommand(command,currentvf);
00044     command += CommandLength(command);
00045   } 
00046   EndVFMacro();
00047   currentfont=currentvf;
00048   return(ptr->tfmw);
00049 }
00050 
00051 
00052 
00053 void InitVF(struct font_entry * tfontp)
00054 {
00055   unsigned char* position;
00056   int length;
00057   struct char_entry *tcharptr;  
00058   uint32_t c=0;
00059   struct font_num *tfontnump;  /* temporary font_num pointer   */
00060   
00061   DEBUG_PRINT((DEBUG_DVI|DEBUG_VF),("\n  OPEN FONT:\t'%s'", tfontp->name));
00062   Message(BE_VERBOSE,"<%s>", tfontp->name);
00063   if (MmapFile(tfontp->name,&(tfontp->fmmap)))
00064     Fatal("font file %s unusable", tfontp->name);
00065   position=(unsigned char*)tfontp->fmmap.mmap;
00066   if (*(position) != PRE) 
00067     Fatal("unknown font format in file <%s> !\n",currentfont->name);
00068   if (*(position+1) != VF_ID) 
00069       Fatal( "wrong version of vf file!  (%d should be 202)\n",
00070             (int)*(position+1));
00071   DEBUG_PRINT(DEBUG_VF,("\n  VF_PRE:\t'%.*s'", 
00072               (int)*(position+2), position+3));
00073   position = position+3 + *(position+2);
00074   c=UNumRead(position, 4);
00075   DEBUG_PRINT(DEBUG_VF,(" %d", c));
00076   CheckChecksum (tfontp->c, c, tfontp->name);
00077   tfontp->designsize = UNumRead(position+4,4);
00078   DEBUG_PRINT(DEBUG_VF,(" %d", tfontp->designsize));
00079   tfontp->type = FONT_TYPE_VF;
00080   tfontp->vffontnump=NULL;
00081   /* Read font definitions */
00082   position += 8;
00083   while(*position >= FNT_DEF1 && *position <= FNT_DEF4) {
00084     DEBUG_PRINT(DEBUG_VF,("\n  @%ld VF:\t%s", 
00085                        (long)position - (long)tfontp->fmmap.mmap, 
00086                        dvi_commands[*position]));
00087     FontDef(position,tfontp);      
00088     length = dvi_commandlength[*position];
00089     position += length + *(position + length-1) + *(position+length-2);
00090   }
00091   /* Default font is the first defined */
00092   tfontnump = tfontp->vffontnump;
00093   while (tfontnump->next != NULL) {
00094     tfontnump = tfontnump->next;
00095   }
00096   tfontp->defaultfont=tfontnump->k;
00097   
00098   /* Read char definitions */
00099   while(*position < FNT_DEF1) {
00100     DEBUG_PRINT(DEBUG_VF,("\n@%ld VF CHAR:\t", 
00101                        (long)position - (long)tfontp->fmmap.mmap));
00102     tcharptr=xmalloc(sizeof(struct char_entry));
00103     switch (*position) {
00104     case LONG_CHAR:
00105       tcharptr->length = UNumRead(position+1,4);
00106       c = UNumRead(position+5,4);
00107       tcharptr->tfmw = UNumRead(position+9,4);
00108       position += 13;
00109       break;
00110     default:
00111       tcharptr->length = UNumRead(position,1);
00112       c = UNumRead(position+1,1);
00113       tcharptr->tfmw = UNumRead(position+2,3);
00114       position += 5;
00115     }
00116     DEBUG_PRINT(DEBUG_VF,("%d %d %d",tcharptr->length,c,tcharptr->tfmw));
00117     tcharptr->tfmw = (int32_t) 
00118       ((int64_t) tcharptr->tfmw * tfontp->s / (1 << 20));
00119     DEBUG_PRINT(DEBUG_VF,(" (%d)",tcharptr->tfmw));
00120     if (c > NFNTCHARS) /* Only positive for now */
00121       Fatal("vf character exceeds numbering limit");
00122     tfontp->chr[c] = tcharptr;
00123     tcharptr->data=position;
00124     position += tcharptr->length;
00125   }
00126 }
00127 
00128 
00129 void DoneVF(struct font_entry *tfontp)
00130 {
00131   int c=FIRSTFNTCHAR;
00132 
00133   UnMmapFile(&(tfontp->fmmap));
00134   while(c<=LASTFNTCHAR) {
00135     if (tfontp->chr[c]!=NULL) {
00136       free(tfontp->chr[c]);
00137       tfontp->chr[c]=NULL;
00138     }
00139     c++;
00140   }
00141   FreeFontNumP(tfontp->vffontnump);
00142   tfontp->vffontnump=NULL;
00143   tfontp->name[0]='\0';
00144 }