home *** CD-ROM | disk | FTP | other *** search
- /*
- * This software is Copyright 1988 by Radical Eye Software.
- * All Rights Reserved.
- */
- #include "structures.h"
- #include <string.h>
- extern void mysystem() ;
- extern void consoletofront() ;
- extern void writeconsole() ;
- extern char *getenv(), *newstring() ;
- extern int actualdpi ;
- Boolean generatefonts = 0 ;
- /*
- * Calculate magstep values.
- */
- static int magstep(n, m)
- register int n ;
- int m ;
- {
- register float t ;
- int neg = 0 ;
-
- if (n < 0) {
- neg = 1 ;
- n = -n ;
- }
- if (n & 1) {
- n &= ~1 ;
- t = 1.095445115 ;
- } else
- t = 1.0 ;
- while (n > 8) {
- n -= 8 ;
- t = t * 2.0736 ;
- }
- while (n > 0) {
- n -= 2 ;
- t = t * 1.2 ;
- }
- if (neg)
- return((int)(0.5 + m / t)) ;
- else
- return((int)(0.5 + m * t)) ;
- }
- char *command ;
- /*
- * This routine tries to create a font by executing a command, and
- * then opening the font again if possible.
- */
- extern void qstatus(), chmod() ;
- static char buf[125] ;
- void makefont(name, dpi)
- char *name ;
- int dpi ;
- {
- register char *p, *q ;
- register int m, n ;
-
- if (dpi < 69)
- return ;
- if (command == 0) {
- if ((command=getenv("MAKETEXPK")))
- command = newstring(command) ;
- else
- command = "MakeTeXPK %n %d %b %m" ;
- }
- for (p=command, q=buf; *p; p++)
- if (*p != '%')
- *q++ = *p ;
- else {
- switch (*++p) {
- case 'n' : case 'N' :
- strcpy(q, name) ;
- break ;
- case 'd' : case 'D' :
- sprintf(q, "%d", dpi) ;
- break ;
- case 'b' : case 'B' :
- sprintf(q, "%d", actualdpi) ;
- break ;
- case 'm' : case 'M' :
- /*
- * Here we want to return a string. If we can find some integer
- * m such that floor(0.5 + actualdpi * 1.2 ^ (m/2)) = dpi, we write out
- * magstep(m/2)
- * where m/2 is a decimal number; else we write out
- * dpi/100
- * We do this for the very slight improvement in accuracy that
- * magstep() gives us over the rounded dpi/100.
- */
- m = 0 ;
- if (dpi < actualdpi) {
- while (1) {
- m-- ;
- n = magstep(m, actualdpi) ;
- if (n == dpi)
- break ;
- if (n < dpi || m < -40) {
- m = 9999 ;
- break ;
- }
- }
- } else if (dpi > actualdpi) {
- while (1) {
- m++ ;
- n = magstep(m, actualdpi) ;
- if (n == dpi)
- break ;
- if (n > dpi || m > 40) {
- m = 9999 ;
- break ;
- }
- }
- }
- if (m == 9999) {
- sprintf(q, "%d+%d/%d", dpi/actualdpi, dpi%actualdpi, actualdpi) ;
- } else if (m >= 0) {
- sprintf(q, "magstep\\(%d.%d\\)", m/2, (m&1)*5) ;
- } else {
- sprintf(q, "magstep\\(-%d.%d\\)", -(m)/2, (m&1)*5) ;
- }
- break ;
- case 0 : *q = 0 ;
- break ;
- default: *q++ = *p ;
- *q = 0 ;
- break ;
- }
- q += strlen(q) ;
- }
- *q = 0 ;
- if (generatefonts) {
- static char *amsg[] = {
- "",
- "Generating a font; to disable font generation, go into Preferences",
- "and select `Generate scripts to make fonts.'", "", 0 } ;
- static char **msg = amsg ;
- if (msg) {
- while (*msg)
- writeconsole(*msg++) ;
- msg = 0 ;
- }
- qstatus(buf) ;
- consoletofront() ;
- mysystem(buf) ;
- } else {
- register FILE *f ;
-
- static char *amsg[] = {
- "",
- "Generating scripts to make fonts. To actually make the fonts,",
- "execute the file /LocalLibrary/Fonts/TeXFonts/pk/NeededFonts",
- "(and then delete it.) To automatically generate fonts,",
- "go into Preferences and select `Generate fonts.", "", 0 } ;
- static char **msg = amsg ;
- if (msg) {
- while (*msg)
- writeconsole(*msg++) ;
- msg = 0 ;
- }
- writeconsole(buf) ;
- f = fopen("/LocalLibrary/Fonts/TeXFonts/pk/NeededFonts", "a") ;
- if (f) {
- fprintf(f, "%s\n", buf) ;
- fclose(f) ;
- chmod("/LocalLibrary/Fonts/TeXFonts/pk/NeededFonts", 0666) ;
- }
- }
- }
-