~reviczky/luatex/texlive-bin-git

« back to all changes in this revision

Viewing changes to texk/ps2pkm/mag.c

  • Committer: Adam Reviczky
  • Date: 2015-04-26 22:40:47 UTC
  • Revision ID: adam.reviczky@kclalumni.net-20150426224047-i2p26n3wqphupq6z
TeX Live 2015 import (rev. 37052)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 *      rcpt@urc.tue.nl
69
 
 */
70
 
 
71
 
#include "basics.h"     /* fatal() */
72
 
 
73
 
#include <ctype.h> 
74
 
#include <math.h>
75
 
#include <stdarg.h> 
76
 
#include <stdio.h> 
77
 
#include <stdlib.h> 
78
 
#include <string.h>
79
 
#ifdef WIN32
80
 
#include <fcntl.h>
81
 
#endif
82
 
 
83
 
int invert = 0;
84
 
float DPI = 300.0;
85
 
 
86
 
/* Prototypes */
87
 
static int fontsize(double);
88
 
static double stepsize(double);
89
 
 
90
 
int main(int argc, char *argv[]) {
91
 
   float  sz, arg; int c;
92
 
   char *myname = "mag";
93
 
   short done;
94
 
 
95
 
   while (--argc > 0 && (*++argv)[0] == '-') {
96
 
      if (isdigit((int)(*argv)[1])) { /* allow negative numbers as arguments */
97
 
         break;
98
 
      }
99
 
      done=0;
100
 
      while ((!done) && (c = *++argv[0]))  /* allow -bcK like options */
101
 
         switch (c) {
102
 
         case 'r':
103
 
            invert = 1; break;
104
 
         case 'R':
105
 
            if (*++argv[0] == '\0') {
106
 
               argc--; argv++;
107
 
            }
108
 
            DPI = atof(argv[0]);
109
 
            done = 1;
110
 
            break;
111
 
         default:
112
 
            fatal("%s: %c illegal option\n", myname, c);
113
 
         }
114
 
      }
115
 
 
116
 
   if (argc < 1)
117
 
      fatal("Usage: %s [-r] [-Rdpi] size . . .\n", myname);
118
 
   
119
 
#ifdef WIN32
120
 
   setmode(fileno(stdout), _O_BINARY);
121
 
#endif
122
 
 
123
 
   for ( ; argc; argc--, argv++) {
124
 
      arg=atof(argv[0]);
125
 
      switch (invert) {
126
 
      case 0:
127
 
         printf("%d%c", fontsize(arg), argc > 1 ? ' ' : '\n');
128
 
         break;
129
 
      case 1:
130
 
         sz=stepsize(arg);
131
 
         if (((int)(10*sz))%10==0)
132
 
            printf("%d%c", (int)sz, argc > 1 ? ' ' : '\n');
133
 
         else 
134
 
            printf("%f%c", sz, argc > 1 ? ' ' : '\n');
135
 
      }
136
 
   }
137
 
   return 0;
138
 
}
139
 
 
140
 
static int
141
 
fontsize(double x)
142
 
{
143
 
   return(DPI*pow(1.2, x) + 0.5);
144
 
}
145
 
 
146
 
static double
147
 
stepsize(double x)
148
 
{
149
 
   double s;
150
 
   s=(log(x)-log(DPI))/log(1.2);
151
 
   if (s>=0) return floor(10*s+0.5)/10;
152
 
   return -floor(10*(-s)+0.5)/10;
153
 
}