| 1 |
/* |
| 2 |
* .\" e |
| 3 |
* .TH MAG 1 UMFT |
| 4 |
* .SH NAME |
| 5 |
* mag \- computes fontsizes and magsteps |
| 6 |
* |
| 7 |
* .de Ex |
| 8 |
* .sp |
| 9 |
* .RS |
| 10 |
* .nf |
| 11 |
* .ft C |
| 12 |
* .. |
| 13 |
* .de Xe |
| 14 |
* .RE |
| 15 |
* .sp |
| 16 |
* .fi |
| 17 |
* .. |
| 18 |
* .SH SYNOPSIS |
| 19 |
* .B |
| 20 |
* mag |
| 21 |
* [-\fBR\fIdpi\fP\fP] magstep . . . |
| 22 |
* |
| 23 |
* .B |
| 24 |
* mag |
| 25 |
* [-\fBr\fP] [-\fBR\fP\fIdpi\fP] fontsize . . . |
| 26 |
* |
| 27 |
* .SH DESCRIPTION |
| 28 |
* .EQ |
| 29 |
* delim $$ |
| 30 |
* .EN |
| 31 |
* This tool calculates fontsizes given magsteps. TeXfonts are provided as |
| 32 |
* true sized fonts or as magnifications. The fontsize of a true sized |
| 33 |
* font equals the resolution of the printer (ex. 300). The fontsize |
| 34 |
* of a font magnified $n$ \fImagsteps\fP equals: |
| 35 |
* .EQ |
| 36 |
* 1.2 sup{n} times 300 |
| 37 |
* delim off |
| 38 |
* .EN |
| 39 |
* rounded to its nearest integer value. Fontnames for TeX fonts normally |
| 40 |
* consists of the name (\fIcmr\fP), pointsize (\fI10\fP), type (\fIpk\fP) |
| 41 |
* and fontsize (\fI360\fP), for example: \fIcmr10.360pk\fP. |
| 42 |
* |
| 43 |
* .SH EXAMPLES |
| 44 |
* The result of \fImag -R240 -2 0 0.5 1\fP will be: |
| 45 |
* .Ex |
| 46 |
* 167 240 263 288 |
| 47 |
* .Xe |
| 48 |
* |
| 49 |
* The inverse function is computed with the \fI-r\fP option. The result of |
| 50 |
* \fImag -r -R240 167 240 263 288\fP |
| 51 |
* will be the fontsteps: |
| 52 |
* .Ex |
| 53 |
* -2 0 0.5 1 |
| 54 |
* .Xe |
| 55 |
* |
| 56 |
* The UNIX shells allow command substitution. One can write: |
| 57 |
* .Ex |
| 58 |
* mag -r -R240 `mag -R240 -2 0 0.5 1` |
| 59 |
* .Xe |
| 60 |
* |
| 61 |
* .SH DATE |
| 62 |
* August, 1992 |
| 63 |
* |
| 64 |
* .SH AUTHOR |
| 65 |
* .nf |
| 66 |
* Piet Tutelaers |
| 67 |
* University of Technology Eindhoven |
| 68 |
*/ |
| 69 |
|
| 70 |
#include "basics.h" /* fatal() */ |
| 71 |
|
| 72 |
#include <ctype.h> |
| 73 |
#include <math.h> |
| 74 |
#include <stdarg.h> |
| 75 |
#include <stdio.h> |
| 76 |
#include <stdlib.h> |
| 77 |
#include <string.h> |
| 78 |
#ifdef WIN32 |
| 79 |
#include <fcntl.h> |
| 80 |
#endif |
| 81 |
|
| 82 |
int invert = 0; |
| 83 |
float DPI = 300.0; |
| 84 |
|
| 85 |
/* Prototypes */ |
| 86 |
static int fontsize(double); |
| 87 |
static double stepsize(double); |
| 88 |
|
| 89 |
int main(int argc, char *argv[]) { |
| 90 |
float sz, arg; int c; |
| 91 |
const char *myname = "mag"; |
| 92 |
short done; |
| 93 |
|
| 94 |
while (--argc > 0 && (*++argv)[0] == '-') { |
| 95 |
if (isdigit((int)(*argv)[1])) { /* allow negative numbers as arguments */ |
| 96 |
break; |
| 97 |
} |
| 98 |
done=0; |
| 99 |
while ((!done) && (c = *++argv[0])) /* allow -bcK like options */ |
| 100 |
switch (c) { |
| 101 |
case 'r': |
| 102 |
invert = 1; break; |
| 103 |
case 'R': |
| 104 |
if (*++argv[0] == '\0') { |
| 105 |
argc--; argv++; |
| 106 |
} |
| 107 |
if (argv[0] == NULL) goto invalid; |
| 108 |
DPI = atof(argv[0]); |
| 109 |
done = 1; |
| 110 |
break; |
| 111 |
invalid: |
| 112 |
default: |
| 113 |
fatal("%s: %c invalid option\n", myname, c); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
if (argc < 1) { |
| 118 |
msg ("mag (ps2pk) version " PACKAGE_VERSION " (" TL_VERSION ")\n"); |
| 119 |
msg ("Usage: %s [-r] [-Rdpi] size . . .\n", myname); |
| 120 |
fatal("\nEmail bug reports to %s.\n", PACKAGE_BUGREPORT); |
| 121 |
} |
| 122 |
|
| 123 |
#ifdef WIN32 |
| 124 |
setmode(fileno(stdout), _O_BINARY); |
| 125 |
#endif |
| 126 |
|
| 127 |
for ( ; argc; argc--, argv++) { |
| 128 |
arg=atof(argv[0]); |
| 129 |
switch (invert) { |
| 130 |
case 0: |
| 131 |
printf("%d%c", fontsize(arg), argc > 1 ? ' ' : '\n'); |
| 132 |
break; |
| 133 |
case 1: |
| 134 |
sz=stepsize(arg); |
| 135 |
if (((int)(10*sz))%10==0) |
| 136 |
printf("%d%c", (int)sz, argc > 1 ? ' ' : '\n'); |
| 137 |
else |
| 138 |
printf("%f%c", sz, argc > 1 ? ' ' : '\n'); |
| 139 |
} |
| 140 |
} |
| 141 |
return 0; |
| 142 |
} |
| 143 |
|
| 144 |
static int |
| 145 |
fontsize(double x) |
| 146 |
{ |
| 147 |
return(DPI*pow(1.2, x) + 0.5); |
| 148 |
} |
| 149 |
|
| 150 |
static double |
| 151 |
stepsize(double x) |
| 152 |
{ |
| 153 |
double s; |
| 154 |
s=(log(x)-log(DPI))/log(1.2); |
| 155 |
if (s>=0) return floor(10*s+0.5)/10; |
| 156 |
return -floor(10*(-s)+0.5)/10; |
| 157 |
} |