home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / NextLibrary / TeX / tex / src / texview / makefont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-27  |  4.1 KB  |  170 lines

  1. /*
  2.  *   This software is Copyright 1988 by Radical Eye Software.
  3.  *   All Rights Reserved.
  4.  */
  5. #include "structures.h"
  6. #include <string.h>
  7. extern void mysystem() ;
  8. extern void consoletofront() ;
  9. extern void writeconsole() ;
  10. extern char *getenv(), *newstring() ;
  11. extern int actualdpi ;
  12. Boolean generatefonts = 0 ;
  13. /*
  14.  *   Calculate magstep values.
  15.  */
  16. static int magstep(n, m)
  17. register int n ;
  18. int m ;
  19. {
  20.    register float t ;
  21.    int neg = 0 ;
  22.  
  23.    if (n < 0) {
  24.       neg = 1 ;
  25.       n = -n ;
  26.    }
  27.    if (n & 1) {
  28.       n &= ~1 ;
  29.       t = 1.095445115 ;
  30.    } else
  31.       t = 1.0 ;
  32.    while (n > 8) {
  33.       n -= 8 ;
  34.       t = t * 2.0736 ;
  35.    }
  36.    while (n > 0) {
  37.       n -= 2 ;
  38.       t = t * 1.2 ;
  39.    }
  40.    if (neg)
  41.       return((int)(0.5 + m / t)) ;
  42.    else
  43.       return((int)(0.5 + m * t)) ;
  44. }
  45. char *command ;
  46. /*
  47.  *   This routine tries to create a font by executing a command, and
  48.  *   then opening the font again if possible.
  49.  */
  50. extern void qstatus(), chmod() ;
  51. static char buf[125] ;
  52. void makefont(name, dpi)
  53. char *name ;
  54. int dpi ;
  55. {
  56.    register char *p, *q ;
  57.    register int m, n ;
  58.  
  59.    if (dpi < 69)
  60.       return ;
  61.    if (command == 0) {
  62.       if ((command=getenv("MAKETEXPK")))
  63.          command = newstring(command) ;
  64.       else
  65.          command = "MakeTeXPK %n %d %b %m" ;
  66.    }
  67.    for (p=command, q=buf; *p; p++)
  68.       if (*p != '%')
  69.          *q++ = *p ;
  70.       else {
  71.          switch (*++p) {
  72. case 'n' : case 'N' :
  73.             strcpy(q, name) ;
  74.             break ;
  75. case 'd' : case 'D' :
  76.             sprintf(q, "%d", dpi) ;
  77.             break ;
  78. case 'b' : case 'B' :
  79.             sprintf(q, "%d", actualdpi) ;
  80.             break ;
  81. case 'm' : case 'M' :
  82. /*
  83.  *   Here we want to return a string.  If we can find some integer
  84.  *   m such that floor(0.5 + actualdpi * 1.2 ^ (m/2)) = dpi, we write out
  85.  *      magstep(m/2)
  86.  *   where m/2 is a decimal number; else we write out
  87.  *      dpi/100
  88.  *   We do this for the very slight improvement in accuracy that
  89.  *   magstep() gives us over the rounded dpi/100.
  90.  */
  91.             m = 0 ;
  92.             if (dpi < actualdpi) {
  93.                while (1) {
  94.                   m-- ;
  95.                   n = magstep(m, actualdpi) ;
  96.                   if (n == dpi)
  97.                      break ;
  98.                   if (n < dpi || m < -40) {
  99.                      m = 9999 ;
  100.                      break ;
  101.                   }
  102.                }
  103.             } else if (dpi > actualdpi) {
  104.                while (1) {
  105.               m++ ;
  106.           n = magstep(m, actualdpi) ;
  107.           if (n == dpi)
  108.              break ;
  109.           if (n > dpi || m > 40) {
  110.              m = 9999 ;
  111.              break ;
  112.           }
  113.            }
  114.             }
  115.             if (m == 9999) {
  116.                sprintf(q, "%d+%d/%d", dpi/actualdpi, dpi%actualdpi, actualdpi) ;
  117.             } else if (m >= 0) {
  118.                sprintf(q, "magstep\\(%d.%d\\)", m/2, (m&1)*5) ;
  119.             } else {
  120.                sprintf(q, "magstep\\(-%d.%d\\)", -(m)/2, (m&1)*5) ;
  121.             }
  122.             break ;
  123. case 0 :    *q = 0 ;
  124.             break ;
  125. default:    *q++ = *p ;
  126.             *q = 0 ;
  127.             break ;
  128.          }
  129.          q += strlen(q) ;
  130.       }
  131.    *q = 0 ;
  132.    if (generatefonts) {
  133.       static char *amsg[] = {
  134.  "",
  135.  "Generating a font; to disable font generation, go into Preferences",
  136.  "and select `Generate scripts to make fonts.'", "", 0 } ;
  137.       static char **msg = amsg ;
  138.       if (msg) {
  139.          while (*msg)
  140.             writeconsole(*msg++) ;
  141.          msg = 0 ;
  142.       }
  143.       qstatus(buf) ;
  144.       consoletofront() ;
  145.       mysystem(buf) ;
  146.    } else {
  147.       register FILE *f ;
  148.  
  149.       static char *amsg[] = {
  150.  "",
  151.  "Generating scripts to make fonts.  To actually make the fonts,",
  152.  "execute the file /LocalLibrary/Fonts/TeXFonts/pk/NeededFonts",
  153.  "(and then delete it.)  To automatically generate fonts,",
  154.  "go into Preferences and select `Generate fonts.", "", 0 } ;
  155.       static char **msg = amsg ;
  156.       if (msg) {
  157.          while (*msg)
  158.             writeconsole(*msg++) ;
  159.          msg = 0 ;
  160.       }
  161.       writeconsole(buf) ;
  162.       f = fopen("/LocalLibrary/Fonts/TeXFonts/pk/NeededFonts", "a") ;
  163.       if (f) {
  164.          fprintf(f, "%s\n", buf) ;
  165.          fclose(f) ;
  166.          chmod("/LocalLibrary/Fonts/TeXFonts/pk/NeededFonts", 0666) ;
  167.       }
  168.    }
  169. }
  170.