summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/misc/settosize.tex
blob: c75cc2ff7cf302957ac1323bc4667cdaa6a29f82 (plain)
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

%%% I need to be able to specify the width for text. I would like to
%%% use the largest size (subject to a user specified maximum and
%%% minimum). If the constraints mean that I cannot fill the width
%%% then the text should be centered at the largest specified size.
%%%
%%% Phil Taylor January 1993

\catcode `\@ = 11

\newcount \r@mainder
\newcount \m@gstepcount
\newcount \m@gsteplimit
\newcount \m@gstepvalue
\newdimen \m@gstepdimen

\def \magsteps {\afterassignment \m@gsteps \m@gsteplimit = }

\def \m@gsteps
    {\let \@r = \or
     \def \or {\noexpand \or}%
     \m@gstepdimen = 0.166667 \maxdimen
     \m@gstepvalue = 1000 
     \m@gstepcount = 0
     \def \magstep {}%
     \loop
     \ifnum     \m@gstepcount < \m@gsteplimit
                \advance \m@gstepcount by 1
                \ifnum \m@gstepvalue > \m@gstepdimen
                        \advance \m@gstepcount by -1
                        \message {Sorry --- integer overflow would occur if
                                        I went any further; stopped at 
                                                \the \m@gstepcount.}
                        \m@gsteplimit = \m@gstepcount 
                \else
                        \multiply \m@gstepvalue by 12
                        \multiply \r@mainder by 12
                        \divide \r@mainder by 10
                        \advance \m@gstepvalue by \r@mainder
                        \r@mainder = \m@gstepvalue
                        \divide \m@gstepvalue by 10
                        \multiply \m@gstepvalue by 10
                        \advance \r@mainder by -\m@gstepvalue
                        \divide \m@gstepvalue by 10
                        \ifnum \r@mainder < 5
                               \edef \magstep {\magstep \or \the \m@gstepvalue}%
                        \else
                               \advance \m@gstepvalue by 1
                               \edef \magstep {\magstep \or \the \m@gstepvalue}%
                               \advance \m@gstepvalue by -1
                        \fi
                \fi
     \repeat
     \edef \magstep ##1%
          {\noexpand \ifcase ##1
                        1000\magstep 
           \noexpand \else 0%
           \noexpand \message 
                {Sorry --- \string \magstep \space ##1
                                is not in range 0 .. \the \m@gsteplimit}%
           \noexpand \fi
           \noexpand \relax
          }%
     \let \or = \@r
    }

\catcode `\@ = 12

\magsteps 63
\newcount \loopcount
\newdimen \thewidth

\def \set #1 \in #2 \to %%% see example at end 
    {\def \thetext {#1}%
     \def \thefont {#2 }%
     \afterassignment \settowidth
     \thewidth =      
    }

\def \settowidth
    {\loopcount = 0
     \loop
       \message {Trying \noexpand \magstep \the \loopcount...}%
       \setbox 0 = \hbox 
		   {\font \tempfont = \thefont scaled \magstep \loopcount
       		    \tempfont \thetext
       		   }%
     \ifdim \wd 0 < \thewidth
       \advance \loopcount by 1
     \repeat
     \advance \loopcount by -1
     \message {The calculated font is \thefont \space 
       		scaled \noexpand \magstep \the \loopcount}%

     \hbox to \thewidth {\font \tempfont = \thefont scaled \magstep \loopcount
       	     \hss \tempfont \thetext \hss}%
    }

\set Now is the time for \in cmr10 \to 50 cm