Back to index

tetex-bin  3.0
makefont.c
Go to the documentation of this file.
00001 /*
00002  *   This software is Copyright 1988 by Radical Eye Software.
00003  */
00004 #include "dvips.h"
00005 #include <math.h>
00006 #include "protos.h"
00007 extern int quiet ;
00008 extern int filter ;
00009 extern int dontmakefont ;
00010 extern Boolean secure ;
00011 extern char *mfmode ;
00012 #ifdef OS2
00013 #include <stdlib.h>
00014 #endif
00015 #if !defined(WIN32)
00016 extern char *getenv();
00017 extern int system();
00018 #endif
00019 #if defined MSDOS || defined OS2
00020 extern char *mfjobname ;
00021 extern FILE *mfjobfile ;
00022 extern char *pkpath ;
00023 extern int actualdpi ;
00024 extern int vactualdpi ;
00025 /*
00026  *  Write mfjob file
00027  */
00028 void
00029 mfjobout P2C(char *, font, double, mag)
00030 {
00031    if (mfjobfile == (FILE *)NULL) {
00032       char pkout[128];
00033       char *p;
00034       int i;
00035       for (p=pkpath, i=0; *p && *p!=PATHSEP && i<127; p++) {
00036          if (*p=='%') {
00037             p++;
00038             switch(*p) { /* convert %x codes to mfjob @y codes */
00039                case 'b':
00040                   sprintf(pkout+i,"%d",actualdpi);
00041                   break;
00042                case 'd':
00043                   strcpy(pkout+i,"@Rr");
00044                   break;
00045                case 'f':
00046                   strcpy(pkout+i,"@f");
00047                   break;
00048                case 'p':
00049                   strcpy(pkout+i,"pk");
00050                   break;
00051                case 'm':
00052                   strcpy(pkout+i, mfmode ? mfmode : "default");
00053                   break;
00054                case '%':
00055                   strcpy(pkout+i,"%");
00056                   break;
00057                default:
00058                   sprintf(pkout+i, "%%%c", *p) ;
00059                   fprintf(stderr,"Unknown option %%%c in pk path\n",*p);
00060             }
00061             i += strlen(pkout+i);
00062          }
00063          else
00064            pkout[i++] = *p;
00065       }
00066       /* *p='\0'; Could some DOS person explain to me what this does? */
00067       pkout[i] = 0 ;
00068       mfjobfile =  fopen(mfjobname,"w");
00069       if (mfjobfile == (FILE *)NULL)
00070          return;
00071       fprintf(mfjobfile,"input[dvidrv];\n{\ndriver=dvips;\n");
00072       if (actualdpi == vactualdpi)
00073          fprintf(mfjobfile,"mode=%s[%d];\n",mfmode,actualdpi);
00074       else
00075          fprintf(mfjobfile,"mode=%s[%d %d];\n",mfmode,actualdpi,vactualdpi);
00076       fprintf(mfjobfile,"output=pk[%s];\n",pkout);
00077    }
00078    fprintf(mfjobfile,"{font=%s; mag=%f;}\n",font,mag);
00079    (void)fprintf(stderr,
00080         "Appending {font=%s; mag=%f;} to %s\n",font,mag,mfjobname) ;
00081 }
00082 #endif
00083 /*
00084  *   Calculate magstep values.
00085  */
00086 static int
00087 magstep P2C(register int, n, register int, bdpi)
00088 {
00089    register float t ;
00090    int neg = 0 ;
00091 
00092    if (n < 0) {
00093       neg = 1 ;
00094       n = -n ;
00095    }
00096    if (n & 1) {
00097       n &= ~1 ;
00098       t = 1.095445115 ;
00099    } else
00100       t = 1.0 ;
00101    while (n > 8) {
00102       n -= 8 ;
00103       t = t * 2.0736 ;
00104    }
00105    while (n > 0) {
00106       n -= 2 ;
00107       t = t * 1.2 ;
00108    }
00109    if (neg)
00110       return((int)floor(0.5 + bdpi / t)) ;
00111    else
00112       return((int)floor(0.5 + bdpi * t)) ;
00113 }
00114 #ifdef MAKEPKCMD
00115 static char *defcommand = MAKEPKCMD " %n %d %b %m" ;
00116 #else
00117 #ifdef OS2
00118 static char *doscommand = "command /c MakeTeXP %n %d %b %m" ;
00119 static char *os2command = "MakeTeXP %n %d %b %m" ;
00120 #define defcommand ( _osmode==OS2_MODE ? os2command : doscommand )
00121 #else
00122 #ifdef MSDOS
00123 static char *defcommand = "command /c MakeTeXP %n %d %b %m" ;
00124 #else
00125 #ifdef VMCMS
00126 static char *defcommand = "EXEC MakeTeXPK %n %d %b %m" ;
00127 #else
00128 #ifdef ATARIST
00129 static char *defcommand = "maketexp %n %d %b %m" ;
00130 #else
00131 static char *defcommand = "MakeTeXPK %n %d %b %m" ;
00132 #endif
00133 #endif
00134 #endif
00135 #endif
00136 #endif
00137 char *command = 0 ;
00138 /*
00139  *   This routine tries to create a font by executing a command, and
00140  *   then opening the font again if possible.
00141  */
00142 static char buf[125] ;
00143 void
00144 makefont P3C(char *, name, int, dpi, int, bdpi)
00145 {
00146    register char *p, *q ;
00147    register int m, n ;
00148    int modegiven = 0 ;
00149 #if defined MSDOS || defined OS2 || defined(ATARIST)
00150    double t;
00151 #endif
00152 
00153    if (command == 0)
00154       if (secure == 0 && (command=getenv("MAKETEXPK")))
00155          command = newstring(command) ;
00156       else 
00157          command = defcommand ;
00158    for (p=command, q=buf; *p; p++)
00159       if (*p != '%')
00160          *q++ = *p ;
00161       else {
00162          switch (*++p) {
00163 case 'n' : case 'N' :
00164             (void)strcpy(q, name) ;
00165             break ;
00166 case 'd' : case 'D' :
00167             (void)sprintf(q, "%d", dpi) ;
00168             break ;
00169 case 'b' : case 'B' :
00170             (void)sprintf(q, "%d", bdpi) ;
00171             break ;
00172 case 'o' : case 'O' :
00173             (void)sprintf(q, "%s", mfmode ? mfmode : "default") ;
00174             modegiven = 1 ;
00175             break ;
00176 case 'm' : case 'M' :
00177 /*
00178  *   Here we want to return a string.  If we can find some integer
00179  *   m such that floor(0.5 + bdpi * 1.2 ^ (m/2)) = dpi, we write out
00180  *      magstep(m/2)
00181  *   where m/2 is a decimal number; else we write out
00182  *      dpi/bdpi
00183  *   We do this for the very slight improvement in accuracy that
00184  *   magstep() gives us over the rounded dpi/bdpi.
00185  */
00186             m = 0 ;
00187             if (dpi < bdpi) {
00188                while (1) {
00189                   m-- ;
00190                   n = magstep(m, bdpi) ;
00191                   if (n == dpi)
00192                      break ;
00193                   if (n < dpi || m < -40) {
00194                      m = 9999 ;
00195                      break ;
00196                   }
00197                }
00198             } else if (dpi > bdpi) {
00199                while (1) {
00200                   m++ ;
00201                   n = magstep(m, bdpi) ;
00202                   if (n == dpi)
00203                      break ;
00204                   if (n > dpi || m > 40) {
00205                      m = 9999 ;
00206                      break ;
00207                   }
00208                }
00209             }
00210 #if defined MSDOS || defined OS2
00211 /* write out magnification as decimal number */
00212             if (m == 9999) {
00213                t = (double)dpi/bdpi;
00214             } else {
00215                if (m < 0)
00216                     n = -m;
00217                else
00218                     n = m;
00219                if (n & 1) {
00220                     n &= ~1 ;
00221                     t = 1.095445115 ;
00222                } else
00223                     t = 1.0 ;
00224                while (n > 0) {
00225                     n -= 2 ;
00226                     t = t * 1.2 ;
00227                }
00228                if (m < 0)
00229                     t = 1 / t ;
00230             }
00231             (void)sprintf(q, "%12.9f", t) ;
00232 #else
00233 #ifndef ATARIST
00234             if (m == 9999) {
00235 #else
00236             {
00237 #endif
00238                (void)sprintf(q, "%d+%d/%d", dpi/bdpi, dpi%bdpi, bdpi) ;
00239             } else if (m >= 0) {
00240                (void)sprintf(q, "magstep\\(%d.%d\\)", m/2, (m&1)*5) ;
00241             } else {
00242                (void)sprintf(q, "magstep\\(-%d.%d\\)", (-m)/2, (m&1)*5) ;
00243             }
00244 #endif
00245             break ;
00246 case 0 :    *q = 0 ;
00247             break ;
00248 default:    *q++ = *p ;
00249             *q = 0 ;
00250             break ;
00251          }
00252          q += strlen(q) ;
00253       }
00254    *q = 0 ;
00255    if (mfmode && !modegiven) {
00256       strcpy(q, " ") ;
00257       strcat(q, mfmode) ;
00258    }
00259 #ifdef OS2
00260    if ((_osmode == OS2_MODE) && filter)
00261       (void)strcat(buf, quiet ? " >nul" : " 1>&2") ;
00262 #else
00263 #ifndef VMCMS   /* no filters and no need to print to stderr */
00264 #ifndef MVSXA
00265 #ifndef MSDOS
00266 #ifndef ATARIST
00267    if (filter)
00268       (void)strcat(buf, quiet ? " >/dev/null" : " 1>&2") ;
00269 #endif
00270 #endif
00271 #endif
00272 #endif
00273 #endif
00274 
00275 #if defined MSDOS || defined OS2
00276    if (! quiet && mfjobname == (char *)NULL)
00277       (void)fprintf(stderr, "- %s\n", buf) ;
00278    if (dontmakefont == 0) {
00279       if (mfjobname != (char *)NULL)
00280          mfjobout(name,t);
00281       else
00282          (void)system(buf) ;
00283    }
00284 #else
00285    if (! quiet)
00286       (void)fprintf(stderr, "- %s\n", buf) ;
00287    if (dontmakefont == 0)
00288       (void)system(buf) ;
00289 #endif
00290    else {
00291       static FILE *fontlog = 0 ;
00292 
00293       if (fontlog == 0) {
00294          fontlog = fopen("missfont.log", "a") ;
00295          if (fontlog != 0) {
00296             (void)fprintf(stderr,
00297 #ifndef VMCMS
00298                   "Appending font creation commands to missfont.log\n") ;
00299 #else
00300   "\nMissing font data will be passed to DVIPS EXEC via MISSFONT LOG\n");
00301 #endif
00302          }
00303       }
00304       if (fontlog != 0) {
00305          (void)fprintf(fontlog, "%s\n", buf) ;
00306          (void)fflush(fontlog) ;
00307       }
00308    }
00309 }