Back to index

tetex-bin  3.0
mag.c
Go to the documentation of this file.
00001 /*
00002  *     .\" e
00003  *     .TH MAG 1 UMFT
00004  *     .SH NAME
00005  *     mag \- computes fontsizes and magsteps
00006  *     
00007  *     .de Ex
00008  *     .sp
00009  *     .RS
00010  *     .nf
00011  *     .ft C
00012  *     ..
00013  *     .de Xe
00014  *     .RE
00015  *     .sp
00016  *     .fi
00017  *     ..
00018  *     .SH SYNOPSIS 
00019  *     .B
00020  *     mag
00021  *     [-\fBR\fIdpi\fP\fP] magstep . . .
00022  *     
00023  *     .B
00024  *     mag
00025  *     [-\fBr\fP] [-\fBR\fP\fIdpi\fP] fontsize . . .
00026  *     
00027  *     .SH DESCRIPTION
00028  *     .EQ
00029  *     delim $$
00030  *     .EN
00031  *     This tool calculates fontsizes given magsteps.  TeXfonts are provided as
00032  *     true sized fonts or as magnifications.  The fontsize of a true sized
00033  *     font equals the resolution of the printer (ex.  300).  The fontsize
00034  *     of a font magnified $n$ \fImagsteps\fP equals:
00035  *     .EQ
00036  *     1.2 sup{n} times 300
00037  *     delim off
00038  *     .EN
00039  *     rounded to its nearest integer value.  Fontnames for TeX fonts normally
00040  *     consists of the name (\fIcmr\fP), pointsize (\fI10\fP), type (\fIpk\fP)
00041  *     and fontsize (\fI360\fP), for example: \fIcmr10.360pk\fP. 
00042  *     
00043  *     .SH EXAMPLES
00044  *     The result of \fImag -R240 -2 0 0.5 1\fP will be: 
00045  *     .Ex 
00046  *     167 240 263 288 
00047  *     .Xe
00048  *     
00049  *     The inverse function is computed with the \fI-r\fP option. The result of
00050  *     \fImag -r -R240 167 240 263 288\fP
00051  *     will be the fontsteps:
00052  *     .Ex
00053  *     -2 0 0.5 1
00054  *     .Xe
00055  *     
00056  *     The UNIX shells allow command substitution. One can write:
00057  *     .Ex
00058  *     mag -r -R240 `mag -R240 -2 0 0.5 1`
00059  *     .Xe
00060  *     
00061  *     .SH DATE
00062  *     August, 1992
00063  *     
00064  *     .SH AUTHOR
00065  *     .nf
00066  *     Piet Tutelaers
00067  *     University of Technology Eindhoven
00068  *     rcpt@urc.tue.nl
00069  */
00070 
00071 #include <ctype.h> 
00072 #include <math.h>
00073 #include <stdarg.h> 
00074 #include <stdio.h> 
00075 #include <stdlib.h> 
00076 #include <string.h>
00077 
00078 #include "basics.h"  /* fatal() */
00079 
00080 int invert = 0;
00081 float DPI = 300.0;
00082 
00083 int main(int argc, char *argv[]) {
00084    float  sz, arg; int c;
00085    char *myname = "mag";
00086    short done;
00087 
00088    /* prototypes */
00089    int fontsize(double);
00090    double stepsize(double);
00091 
00092    while (--argc > 0 && (*++argv)[0] == '-') {
00093       if (isdigit((int)(*argv)[1])) { /* allow negative numbers as arguments */
00094          break;
00095       }
00096       done=0;
00097       while ((!done) && (c = *++argv[0]))  /* allow -bcK like options */
00098         switch (c) {
00099         case 'r':
00100            invert = 1; break;
00101         case 'R':
00102            if (*++argv[0] == '\0') {
00103               argc--; argv++;
00104            }
00105            DPI = atof(argv[0]);
00106            done = 1;
00107            break;
00108         default:
00109            fatal("%s: %c illegal option\n", myname, c);
00110         }
00111       }
00112 
00113    if (argc < 1)
00114       fatal("Usage: %s [-r] [-Rdpi] size . . .\n", myname);
00115    
00116    for ( ; argc; argc--, argv++) {
00117       arg=atof(argv[0]);
00118       switch (invert) {
00119       case 0:
00120          printf("%d%c", fontsize(arg), argc > 1 ? ' ' : '\n');
00121          break;
00122       case 1:
00123          sz=stepsize(arg);
00124          if (((int)(10*sz))%10==0)
00125             printf("%d%c", (int)sz, argc > 1 ? ' ' : '\n');
00126          else 
00127             printf("%f%c", sz, argc > 1 ? ' ' : '\n');
00128       }
00129    }
00130    return 0;
00131 }
00132 
00133 int fontsize(x) double x;
00134 {
00135    return(DPI*pow(1.2, x) + 0.5);
00136 }
00137 
00138 double stepsize(x) double x;
00139 {  double s;
00140    s=(log(x)-log(DPI))/log(1.2);
00141    if (s>=0) return floor(10*s+0.5)/10;
00142    return -floor(10*(-s)+0.5)/10;
00143 }