1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
/* makefont.c */
#include "dvips.h" /* The copyright notice in that file is included too! */
#include <math.h>
/*
* The external declarations:
*/
#include "protos.h"
#ifdef OS2
#include <stdlib.h>
#endif
#if !defined(WIN32)
extern char *getenv();
extern int system();
#endif
#if defined MSDOS || defined OS2
/*
* Write mfjob file
*/
void
mfjobout(char *font, double mag)
{
if (mfjobfile == (FILE *)NULL) {
char pkout[128];
char *p;
int i;
for (p=pkpath, i=0; *p && *p!=PATHSEP && i<127; p++) {
if (*p=='%') {
p++;
switch(*p) { /* convert %x codes to mfjob @y codes */
case 'b':
sprintf(pkout+i,"%d",actualdpi);
break;
case 'd':
strcpy(pkout+i,"@Rr");
break;
case 'f':
strcpy(pkout+i,"@f");
break;
case 'p':
strcpy(pkout+i,"pk");
break;
case 'm':
strcpy(pkout+i, mfmode ? mfmode : "default");
break;
case '%':
strcpy(pkout+i,"%");
break;
default:
sprintf(pkout+i, "%%%c", *p);
fprintf(stderr,"Unknown option %%%c in pk path\n",*p);
}
i += strlen(pkout+i);
}
else
pkout[i++] = *p;
}
/* *p='\0'; Could some DOS person explain to me what this does? */
pkout[i] = 0;
mfjobfile = fopen(mfjobname,"w");
if (mfjobfile == (FILE *)NULL)
return;
fprintf(mfjobfile,"input[dvidrv];\n{\ndriver=dvips;\n");
if (actualdpi == vactualdpi)
fprintf(mfjobfile,"mode=%s[%d];\n",mfmode,actualdpi);
else
fprintf(mfjobfile,"mode=%s[%d %d];\n",mfmode,actualdpi,vactualdpi);
fprintf(mfjobfile,"output=pk[%s];\n",pkout);
}
fprintf(mfjobfile,"{font=%s; mag=%f;}\n",font,mag);
fprintf(stderr,
"Appending {font=%s; mag=%f;} to %s\n",font,mag,mfjobname);
}
#endif
/*
* Calculate magstep values.
*/
static int
magstep(register int n, register int bdpi)
{
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)floor(0.5 + bdpi / t));
else
return((int)floor(0.5 + bdpi * t));
}
#ifdef MAKEPKCMD
static char *defcommand = MAKEPKCMD " %n %d %b %m";
#else
#ifdef OS2
static char *doscommand = "command /c MakeTeXP %n %d %b %m";
static char *os2command = "MakeTeXP %n %d %b %m";
#define defcommand ( _osmode==OS2_MODE ? os2command : doscommand )
#else
#ifdef MSDOS
static char *defcommand = "command /c MakeTeXP %n %d %b %m";
#else
#ifdef VMCMS
static char *defcommand = "EXEC MakeTeXPK %n %d %b %m";
#else
#ifdef ATARIST
static char *defcommand = "maketexp %n %d %b %m";
#else
static char *defcommand = "MakeTeXPK %n %d %b %m";
#endif
#endif
#endif
#endif
#endif
char *command = 0;
/*
* This routine tries to create a font by executing a command, and
* then opening the font again if possible.
*/
static char buf[125];
void
makefont(char *name, int dpi, int bdpi)
{
register char *p, *q;
register int m, n;
int modegiven = 0;
#if defined MSDOS || defined OS2 || defined(ATARIST)
double t;
#endif
if (command == 0)
if (secure == 0 && (command=getenv("MAKETEXPK")))
command = newstring(command);
else
command = defcommand;
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", bdpi);
break;
case 'o' : case 'O' :
sprintf(q, "%s", mfmode ? mfmode : "default");
modegiven = 1;
break;
case 'm' : case 'M' :
/*
* Here we want to return a string. If we can find some integer
* m such that floor(0.5 + bdpi * 1.2 ^ (m/2)) = dpi, we write out
* magstep(m/2)
* where m/2 is a decimal number; else we write out
* dpi/bdpi
* We do this for the very slight improvement in accuracy that
* magstep() gives us over the rounded dpi/bdpi.
*/
m = 0;
if (dpi < bdpi) {
while (1) {
m--;
n = magstep(m, bdpi);
if (n == dpi)
break;
if (n < dpi || m < -40) {
m = 9999;
break;
}
}
} else if (dpi > bdpi) {
while (1) {
m++;
n = magstep(m, bdpi);
if (n == dpi)
break;
if (n > dpi || m > 40) {
m = 9999;
break;
}
}
}
#if defined MSDOS || defined OS2
/* write out magnification as decimal number */
if (m == 9999) {
t = (double)dpi/bdpi;
} else {
if (m < 0)
n = -m;
else
n = m;
if (n & 1) {
n &= ~1;
t = 1.095445115;
} else
t = 1.0;
while (n > 0) {
n -= 2;
t = t * 1.2;
}
if (m < 0)
t = 1 / t;
}
sprintf(q, "%12.9f", t);
#else
#ifndef ATARIST
if (m == 9999) {
#else
{
#endif
sprintf(q, "%d+%d/%d", dpi/bdpi, dpi%bdpi, bdpi);
} 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);
}
#endif
break;
case 0 : *q = 0;
break;
default: *q++ = *p;
*q = 0;
break;
}
q += strlen(q);
}
*q = 0;
if (mfmode && !modegiven) {
strcpy(q, " ");
strcat(q, mfmode);
}
#ifdef OS2
if ((_osmode == OS2_MODE) && filter)
strcat(buf, quiet ? " >nul" : " 1>&2");
#else
#ifndef VMCMS /* no filters and no need to print to stderr */
#ifndef MVSXA
#ifndef MSDOS
#ifndef ATARIST
if (filter)
strcat(buf, quiet ? " >/dev/null" : " 1>&2");
#endif
#endif
#endif
#endif
#endif
#if defined MSDOS || defined OS2
if (! quiet && mfjobname == (char *)NULL)
fprintf(stderr, "- %s\n", buf);
if (dontmakefont == 0) {
if (mfjobname != (char *)NULL)
mfjobout(name,t);
else
system(buf);
}
#else
if (! quiet)
fprintf(stderr, "- %s\n", buf);
if (dontmakefont == 0)
system(buf);
#endif
else {
static FILE *fontlog = 0;
if (fontlog == 0) {
fontlog = fopen("missfont.log", "a");
if (fontlog != 0) {
fprintf(stderr,
#ifndef VMCMS
"Appending font creation commands to missfont.log\n");
#else
"\nMissing font data will be passed to DVIPS EXEC via MISSFONT LOG\n");
#endif
}
}
if (fontlog != 0) {
fprintf(fontlog, "%s\n", buf);
fflush(fontlog);
}
}
}
|