Back to index

wims  3.65+svn20090927
mathfonts.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-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        /* fonts which should have align=middle */
00019 char *middle_fonts=",y,beta,eta,mu,phi,rho,varphi,psi,\
00020 le,leq,ge,geq,pm,ne,neq,\
00021 subseteq,supseteq,wp,\
00022 int,oint,Vert,\
00023 QQ,\
00024 eufQ,eufz,\
00025 leftpar2,leftpar3,leftpar4,leftpar5,leftpar6,\
00026 leftpar7,leftpar8,leftpar9,leftpar10,leftpar11,leftpar12,\
00027 rightpar2,rightpar3,rightpar4,rightpar5,rightpar6,\
00028 rightpar7,rightpar8,rightpar9,rightpar10,rightpar11,rightpar12,\
00029 leftbrace2,leftbrace3,leftbrace4,leftbrace5,leftbrace6,\
00030 leftbrace7,leftbrace8,leftbrace9,leftbrace10,leftbrace11,leftbrace12,\
00031 rightbrace2,rightbrace3,rightbrace4,rightbrace5,rightbrace6,\
00032 rightbrace7,rightbrace8,rightbrace9,rightbrace10,rightbrace11,rightbrace12,";
00033 
00034        /* These are temporary definitions. */
00035 char *mathfont_dir="mathfonts";
00036 
00037   /* tex font size list */
00038 int texsize_list[]={63,69,76,83,91,100,109,120,131,144,158,173};
00039 int texbasesize=6; /* defaults to 109 */
00040 int usertexsize=-1; /* non-negative if defined */
00041 #define texsize_no (sizeof(texsize_list)/sizeof(texsize_list[0]))
00042 
00043 int current_tex_size;
00044 
00045 void fix_tex_size(void)
00046 {
00047     char buf[64],*p; int i,ts;
00048     ts=texbasesize;
00049     if(usertexsize>=0) ts=usertexsize+1;
00050     if(getwimstexsize) p=getvar("wims_texsize"); else p=NULL;
00051     if(p!=NULL && *p!=0) {
00052        i=evalue(p);
00053        if(i>=-5 && i<=5) ts+=i;
00054     }
00055     if(ts<0) ts=0;
00056     if(ts>=texsize_no) ts=texsize_no-1;    
00057     current_tex_size=texsize_list[ts];
00058     snprintf(buf,sizeof(buf),"%d",current_tex_size);
00059     setenv("texgif_density",buf,1);
00060 }
00061 
00062   /* takes math font image file string */
00063 char *mathfont(char *fontname)
00064 {
00065     char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1];
00066     struct stat st;
00067 
00068     if(fontname[0]=='\\') fontname++;
00069     else if(strncmp(fontname,mathfont_prefix,strlen(mathfont_prefix))==0) 
00070       fontname+=strlen(mathfont_prefix);
00071     if(strlen(fontname)==1 /* && strchr("xyz",fontname[0])==NULL */) {
00072        char c=fontname[0];
00073        if(!isalpha(c)) {
00074            buf2[0]=c;buf2[1]=0;
00075        }
00076        else {
00077            char *pp;
00078            if(c=='f') pp="&nbsp;"; else pp="";
00079            snprintf(buf2,sizeof(buf2),"<i>%c</i>%s",c,pp);
00080        }
00081     }
00082     else {
00083 #ifdef CASE_INSENSITIVE_FS
00084        char *underscore;
00085        fix_tex_size(); underscore="";
00086            {
00087               char *p, *p2;
00088               for(p=fontname; *p && !isupper(*p); p++);
00089               /* verify positionning of capital letter */
00090               if(*p && p>fontname && *(p+1)!=0) return NULL;
00091               if(p==fontname && (fontname[1]!=*p || strlen(fontname)!=2)) {
00092                   for(p2=p+1; *p2 && !isupper(*p2); p2++);
00093                   if(*p2) return NULL;
00094               }
00095               if(*p) underscore="_";
00096            }
00097        snprintf(buf1,sizeof(buf1),"%s/%d/%s%s.gif",
00098                mathfont_dir,current_tex_size,fontname,underscore);
00099        if(*underscore && stat(buf1,&st)!=0)
00100          snprintf(buf1,sizeof(buf1),"%s/%d/%s.gif",
00101                  mathfont_dir,current_tex_size,fontname);
00102 #else
00103        fix_tex_size();
00104        snprintf(buf1,sizeof(buf1),"%s/%d/%s.gif",
00105                mathfont_dir,current_tex_size,fontname);
00106 #endif
00107        if(stat(buf1,&st)!=0) return NULL;
00108        snprintf(buf2,sizeof(buf2),",%s,",fontname);
00109        if(strstr(middle_fonts,buf2)!=NULL) 
00110          snprintf(buf2,sizeof(buf2),
00111                  "%s<img src=\"%s%s\" align=middle border=0 \
00112 alt=\"%s\">%s",
00113                  mathalign_sup1,ref_base,buf1,fontname,mathalign_sup2);
00114        else
00115          snprintf(buf2,sizeof(buf2),"<img src=\"%s%s\" vspace=0 border=0 \
00116 alt=\"%s\">",
00117                  ref_base,buf1,fontname);
00118     }
00119     force_setvar("wims_mathfont_",buf2); return getvar("wims_mathfont_");
00120 }
00121