home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d7xx / d795 / pstools.lha / PSTools / PSTools1.lha / source / makefont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-14  |  3.5 KB  |  157 lines

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