| 1 |
% --------------------------------------------------------------------------- |
| 2 |
% TeX macros implementing a standard set of PostScript transformations |
| 3 |
% made in BOP (1993--2001), Gda\'nsk, Poland -- public domain software |
| 4 |
% authors: Bogus\l{}aw Jackowski, Piotr Pianowski, Piotr Strzelczyk |
| 5 |
% e-mail contact: [email protected] |
| 6 |
% --------------------------------------------------------------------------- |
| 7 |
% S Y N O P S I S |
| 8 |
% |
| 9 |
% In the sequel, `box' means \hbox, \vbox, \box, or \copy, `dimen' means |
| 10 |
% a sequence of dimens to be summed up; all macros mentioned below expand |
| 11 |
% to \hbox{...}, they can therefore be used wherever \hbox can be. |
| 12 |
% |
| 13 |
% 1) |
| 14 |
% x_scale and y_scale are given in percents (>0) |
| 15 |
% \zscale changes uniformly x_size and y_size (x_scale=y_scale=scale) |
| 16 |
% \xscale changes only x_size (y_scale=100) |
| 17 |
% \yscale changes only y_size (x_scale=100) |
| 18 |
% |
| 19 |
% \zscale{scale} followed by a box |
| 20 |
% \xyscale{x_scale}{y_scale} followed by a box |
| 21 |
% \yxscale{y_scale}{x_scale} followed by a box |
| 22 |
% \xscale{x_scale} followed by a box |
| 23 |
% \yscale{y_scale} followed by a box |
| 24 |
% |
| 25 |
% 2) |
| 26 |
% \xyscaleto resizes a box uniformly such that the resulting wd=dimen |
| 27 |
% \yxscaleto resizes a box uniformly such that the resulting ht=dimen |
| 28 |
% \xscaleto resizes a box horizontally such that the resulting wd=dimen |
| 29 |
% \yscaleto resizes a box verically such that the resulting ht=dimen |
| 30 |
% |
| 31 |
% \xyscaleto{dimen} followed by a box |
| 32 |
% \yxscaleto{dimen} followed by a box |
| 33 |
% \xscaleto{dimen} followed by a box |
| 34 |
% \yscaleto{dimen} followed by a box |
| 35 |
% |
| 36 |
% 3) |
| 37 |
% \revolve rotates anticlockwise the box (either \hbox or \vbox |
| 38 |
% following the command) by 90 degree; for the resulting box |
| 39 |
% width=height+depth of the original box, height=width |
| 40 |
% of the original box, and the reference point is the left top corner |
| 41 |
% of the original box; this means that revolving a box four times |
| 42 |
% yields the original box if and only if its depth is zero; |
| 43 |
% \revolvedir- is equivalent to \revolve, \revolvedir+ rotates |
| 44 |
% the box clockwise |
| 45 |
% |
| 46 |
% \revolve followed by a box |
| 47 |
% \revolvedir+ followed by a box |
| 48 |
% \revolvedir- followed by a box |
| 49 |
% \revolveleft followed by a box (equivalent to \revolvedir-) |
| 50 |
% \revolveright followed by a box (equivalent to \revolvedir+) |
| 51 |
% \revolvepi followed by a box (equivalent to \xflip\yflip |
| 52 |
% but not to \revolve\revolve) |
| 53 |
% \rotatepi followed by a box (equivalent to \revolvepi; |
| 54 |
% cf. also plain METAFONT rotatedaround and rotatedabout macros) |
| 55 |
% 4) |
| 56 |
% \rotate rotates a box by an arbitrary angle, clockwise for angle>0, |
| 57 |
% width=height=depth=0pt for the resulting box |
| 58 |
% |
| 59 |
% \rotate{angle} followed by a box |
| 60 |
% |
| 61 |
% \rotatebb rotates a box by an arbitrary angle, clockwise for angle>0; |
| 62 |
% the result is placed in a box having the dimensions of the resulting |
| 63 |
% bounding box, protrusion to the left is compensated by appropriate |
| 64 |
% shifting (see the macro \put_into_bb) |
| 65 |
% |
| 66 |
% \rotatebb{angle} followed by a box |
| 67 |
% |
| 68 |
% 5) |
| 69 |
% \xflip and \yflip flip the box horizontally and vertically, |
| 70 |
% respectively, i.e., with respect to the vertical and horizontal |
| 71 |
% axis of the box, without changing the dimensions of the \box |
| 72 |
% |
| 73 |
% \xflip followed by a box |
| 74 |
% \yflip followed by a box |
| 75 |
% |
| 76 |
% 6) |
| 77 |
% \slant slopes a box by an angle alpha such that tan(alpha)=slant, |
| 78 |
% without changing dimensions of the \box; |
| 79 |
% |
| 80 |
% \slant{slant} followed a box |
| 81 |
% |
| 82 |
% (negative argument value means slanting to the left) |
| 83 |
% |
| 84 |
% \slantbb slopes a box by an angle alpha such that tan(alpha)=slant, |
| 85 |
% the result is placed in a box having the dimensions of the resulting |
| 86 |
% bounding box, protrusion to the left is compensated by appropriate |
| 87 |
% shifting (see the macro \put_into_bb) |
| 88 |
% |
| 89 |
% \slantbb{slant} followed a box |
| 90 |
% |
| 91 |
% 7) |
| 92 |
% \clipbox clips the contents of a box that follows the command; |
| 93 |
% the macro expects three dimen parameters: the width, the height |
| 94 |
% and the depth of the resulting box |
| 95 |
% |
| 96 |
% \clipbox{width}{height}{depth} followed a box |
| 97 |
% |
| 98 |
% Any parameter can be empty; in such a case, the respective dimension |
| 99 |
% of the original box is used |
| 100 |
% --------------------------------------------------------------------------- |
| 101 |
% HISTORY: |
| 102 |
% 18 VIII 1993 ver. 0.1 |
| 103 |
% * first release |
| 104 |
% 30--31 VIII 1993 ver. 0.2 |
| 105 |
% * third parameter eliminated from \scale (via \afterassignment |
| 106 |
% and \aftergroup hackery) |
| 107 |
% * added \zscale, \xyscale, \yxscale, \xscale, and \yscale |
| 108 |
% with scaling given in percents |
| 109 |
% * added \scaleto, \xyscaleto, \yxscaleto, \xscaleto, and \yscaleto |
| 110 |
% 3 IX 1993 ver. 0.21 |
| 111 |
% * \the_scale renamed to \lastscale and made global, thus it became |
| 112 |
% available to a user |
| 113 |
% 8 IX 1993 ver. 0.22 |
| 114 |
% * all transformations return \hbox, because of currentpoint |
| 115 |
% positioning |
| 116 |
% * the old version of \scale is become undefined |
| 117 |
% * \slant and \rotate fit the new convention of parameter's |
| 118 |
% hackery -- they are assumed to be followed by an \hbox |
| 119 |
% or a \vbox |
| 120 |
% 6 XII 1993 ver. 0.23 |
| 121 |
% * \revolve added |
| 122 |
% * \rotate with \vbox patched |
| 123 |
% 10 II 1994 ver. 0.24 |
| 124 |
% * \revolvedir+, \revolvedir-, \xflip, and \yflip added |
| 125 |
% 20 III 2000 ver. 0.5 (pre-release) |
| 126 |
% * total reconstruction: |
| 127 |
% -- all macros expand to \hbox, so that it is possible to |
| 128 |
% superpose them, e.g., \xscale{200}\yscale{50}\hbox{...}; |
| 129 |
% one must remeber, however, that \rotate yields a box having |
| 130 |
% null dimensions, so an attempt to scale the result |
| 131 |
% to a given dimen will produce erroneous PostScript code |
| 132 |
% -- the possibility of changing \ht and \dp of a \vbox abolished; |
| 133 |
% such an operation yields hardly intuitive results; try, e.g.: |
| 134 |
% \hrule width\hsize |
| 135 |
% \hbox{\setbox0\hbox{\vrule height1cmwidth1cm}\ht0 0mm \box0} |
| 136 |
% \kern20mm |
| 137 |
% \hrule width\hsize |
| 138 |
% \hbox{\setbox0\vbox{\hrule height1cmwidth1cm}\ht0 0mm \box0} |
| 139 |
% -- the box expected by all macros can be a TeX box expression: |
| 140 |
% \hbox, \vbox, \box, and \copy |
| 141 |
% -- scaling height or width to a given dimension yields exact value |
| 142 |
% of the height or width, respectively (or both); this change is |
| 143 |
% backward incompatible (but reasonable, one should think) |
| 144 |
% -- all transformations store information about the position of the |
| 145 |
% lower left corner and the upper right corner of the resulting |
| 146 |
% bounding box (with respect to the base point of the transformed |
| 147 |
% box) in four globally defined macros: |
| 148 |
% \transllx, \translly, \transurx, \transury |
| 149 |
% (a piece of funny code for vector rotation was added) |
| 150 |
% -- \rotatebb and \slantbb added |
| 151 |
% 25 III 2000 ver. 0.51 |
| 152 |
% * fraction multiplication improved (speedup in trigonometric |
| 153 |
% calculations ca 30%) |
| 154 |
% * trigonometry calculations are performed in a group (otherwise using |
| 155 |
% them within another \loop ... \repeat would be inconvenient); |
| 156 |
% the result is a pair of globally defined macros (instead of dimen |
| 157 |
% registers); they expand to a series of digits (i.e., they contain |
| 158 |
% a count representation of the resulting dimen) |
| 159 |
% * \unhbox (introduced in order to reduce the level of box nesting) |
| 160 |
% should be used only in \rotatebb |
| 161 |
% * internal macro naming changed |
| 162 |
% 27 III 2000 ver. 0.52 |
| 163 |
% * a dimen parameter can be a sequence of dimens to be summed up |
| 164 |
% * \clipbox added |
| 165 |
% 7--10 X 2000 ver. 0.53 |
| 166 |
% * a bug in \slant[bb] fixed: \ht and \dp were interchanged due to |
| 167 |
% a fallacious interpretation of a slant sign (recall that in dvips |
| 168 |
% PostScript, unlike in METAFONT, `-' denotes slanting to the right, |
| 169 |
% `+' -- to the left, because the y-axis is directed downwards); |
| 170 |
% actually, the problem is much more complex: relying (unconsciously) |
| 171 |
% on dvips coordinates means, in this case, that for non-square pixels |
| 172 |
% both rotate and slant will not work -- need to be fixed! |
| 173 |
% 13 XI 2000 ver. 0.54 |
| 174 |
% * @ is a letter during reading trans macros (AMSTeX uses active @) |
| 175 |
% * local macro \undtranscode renamed to \transundcode |
| 176 |
% 9 VI 2001 ver 0.55 |
| 177 |
% * ``mnemonic'' macros added: \revolveleft, \revolveright, \revolvepi |
| 178 |
% and \rotatepi |
| 179 |
% --------------------------------------------------------------------------- |
| 180 |
\def\transspecial#1{\special{ps:#1}}% driver-oriented; default is dvips |
| 181 |
% --- |
| 182 |
\edef\transundcode{\the\catcode`\_}\catcode`\_11 |
| 183 |
\edef\transatcode{\the\catcode`\@}\catcode`\@11 |
| 184 |
% \z@ (0pt) and \p@ (1pt) are borrowed from plain |
| 185 |
% --- |
| 186 |
% a pretty general macro |
| 187 |
\def\sumto#1{\def\sum_to_what{#1}\sum_to_what=\z@\relax \sumto_} |
| 188 |
\def\sumto_{\futurelet\sum_tok\sumto__} |
| 189 |
\def\sumto__{\ifx\sum_tok\relax\else\expandafter\sumto___\fi} |
| 190 |
\def\sumto___{\afterassignment\sumto_\advance\sum_to_what} |
| 191 |
% --- |
| 192 |
\newbox\tmp_box % temporary box register |
| 193 |
\newdimen\tmp_dim % temporary dimen registers |
| 194 |
\newdimen\tmp_dim_a |
| 195 |
\newdimen\tmp_dim_b |
| 196 |
\newdimen\tmp_dim_c |
| 197 |
\newdimen\tmp_dim_d |
| 198 |
\newcount\tmp_count_a % temporary count registers |
| 199 |
\newcount\tmp_count_b |
| 200 |
\newcount\tmp_count_c |
| 201 |
\newif\ifput_into_bb |
| 202 |
% --- |
| 203 |
\def\jump_setbox{\ifvoid\tmp_box % every box is initially void |
| 204 |
\aftergroup\after_setbox \else \after_setbox \fi}% a general trick |
| 205 |
% --- |
| 206 |
\def\set_std_bb{% |
| 207 |
\xdef\transllx{\the\z@}% |
| 208 |
\xdef\translly{\ifdim\dp\tmp_box>\z@ -\fi\the\dp\tmp_box}% |
| 209 |
\xdef\transurx{\the\wd\tmp_box}% |
| 210 |
\xdef\transury{\the\ht\tmp_box}% |
| 211 |
} |
| 212 |
\def\put_into_bb#1{% #1 = operation: \unhbox for rotation, \box for slanting |
| 213 |
\setbox\tmp_box\hbox{\kern-\transllx\rlap{#1\tmp_box}\kern\transurx}% |
| 214 |
\ht\tmp_box\transury \dp\tmp_box-\translly \relax |
| 215 |
} |
| 216 |
% --- |
| 217 |
\def\perc_scale#1#2{% #1 -- xscale, #2 -- yscale, in percents, |
| 218 |
% to be followed by an \hbox or a \vbox |
| 219 |
\def\after_setbox{% |
| 220 |
\setbox\tmp_box\hbox{% |
| 221 |
\transspecial{gsave |
| 222 |
currentpoint #2 100 div div exch #1 100 div div exch |
| 223 |
currentpoint neg #2 100 div mul exch neg #1 100 div mul exch |
| 224 |
translate #1 100 div #2 100 div scale translate}% |
| 225 |
\box\tmp_box \transspecial{grestore}}% |
| 226 |
\ifdim#1\p@=100\p@ \else % special treatment of special case (100%) |
| 227 |
\tmp_dim\wd\tmp_box |
| 228 |
\advance\tmp_dim50sp \divide\tmp_dim100 % rounding rather than floor |
| 229 |
\wd\tmp_box#1\tmp_dim |
| 230 |
\fi |
| 231 |
\ifdim#2\p@=100\p@ \else % ditto |
| 232 |
\tmp_dim\ht\tmp_box |
| 233 |
\advance\tmp_dim50sp \divide\tmp_dim100 % ditto |
| 234 |
\ht\tmp_box#2\tmp_dim |
| 235 |
\tmp_dim\dp\tmp_box |
| 236 |
\advance\tmp_dim50sp \divide\tmp_dim100 % ditto |
| 237 |
\dp\tmp_box#2\tmp_dim |
| 238 |
\fi |
| 239 |
\set_std_bb |
| 240 |
\box\tmp_box\egroup}% |
| 241 |
\afterassignment\jump_setbox\setbox\tmp_box = |
| 242 |
}% |
| 243 |
% --- |
| 244 |
\def\xyscale#1#2{\hbox\bgroup\perc_scale{#1}{#2}} |
| 245 |
\def\zscale#1{\xyscale{#1}{#1}} |
| 246 |
\def\yxscale#1#2{\xyscale{#2}{#1}} |
| 247 |
\def\xscale#1{\xyscale{#1}{100}} |
| 248 |
\def\yscale#1{\xyscale{100}{#1}} |
| 249 |
% --- |
| 250 |
{\catcode`\p12 \catcode`\t12 \gdef\PT_{pt}} |
| 251 |
\def\hull_num{\expandafter\hull_num_} |
| 252 |
\expandafter\def\expandafter\hull_num_\expandafter#\expandafter1\PT_{#1} |
| 253 |
% --- |
| 254 |
\def\find_scale#1#2{% #1 -- size after rescaling, #2 -- \wd or \ht |
| 255 |
% Finds a scale (\lastscale macro) such that the box following the macro |
| 256 |
% call would have the respective dimen (i.e., #2) equal to #1 after rescaling |
| 257 |
% NOTE: it is assumed that prior to calling \find_scale a macro |
| 258 |
% \extra_complete is defined |
| 259 |
\def\after_setbox{% |
| 260 |
\resize\tmp_dim{100\p@}{#1}{#2\tmp_box}% |
| 261 |
\xdef\lastscale{\hull_num\the\tmp_dim}\extra_complete}% |
| 262 |
\afterassignment\jump_setbox\setbox\tmp_box = |
| 263 |
} |
| 264 |
% --- |
| 265 |
\def\scaleto#1#2#3#4{% #1 -- size of dimen #2 (\wd or \ht) after scaling |
| 266 |
% #3 -- actual x-size, #4 -- actual y-size |
| 267 |
\hbox\bgroup % `initial' hbox |
| 268 |
\sumto\tmp_dim#1\relax % freeze the argument; must not be empty |
| 269 |
\setbox\tmp_box\hbox\bgroup % one more setbox in order to control |
| 270 |
% the specified dimen |
| 271 |
\def\extra_complete{% |
| 272 |
\perc_scale{#3}{#4}\box\tmp_box % finish setbox above |
| 273 |
#2\tmp_box=\tmp_dim % force the exactness of the specified dimension |
| 274 |
\set_std_bb |
| 275 |
\box\tmp_box |
| 276 |
\egroup % close `initial' hbox |
| 277 |
}% |
| 278 |
\find_scale{\tmp_dim}#2} |
| 279 |
% |
| 280 |
\def\xyscaleto#1{\scaleto{#1}\wd\lastscale\lastscale} |
| 281 |
\def\yxscaleto#1{\scaleto{#1}\ht\lastscale\lastscale} |
| 282 |
\def\xscaleto#1{\scaleto{#1}\wd\lastscale{100}} |
| 283 |
\def\yscaleto#1{\scaleto{#1}\ht{100}\lastscale} |
| 284 |
% --- |
| 285 |
\def\slant{\hbox\bgroup \put_into_bbfalse \slant_} |
| 286 |
\def\slantbb{\hbox\bgroup \put_into_bbtrue \slant_} |
| 287 |
\def\slant_#1{% #1 (slant) = tan(alpha), where alpha is the slant angle, |
| 288 |
% to be followed by a box |
| 289 |
\def\after_setbox{% |
| 290 |
\transspecial{gsave 0 currentpoint neg exch pop 0 currentpoint exch pop |
| 291 |
translate [1 0 #1 1 0 0] concat translate}% |
| 292 |
% set bounding box |
| 293 |
\dim_x\wd\tmp_box |
| 294 |
\ifdim#1\p@>\z@ \dim_t-#1\ht\tmp_box \advance\dim_x#1\dp\tmp_box |
| 295 |
\else \dim_t#1\dp\tmp_box \advance\dim_x-#1\ht\tmp_box |
| 296 |
\fi |
| 297 |
\xdef\transllx{\the\dim_t}% |
| 298 |
\xdef\translly{\ifdim\dp\tmp_box>\z@ -\fi\the\dp\tmp_box}% |
| 299 |
\xdef\transurx{\the\dim_x}% |
| 300 |
\xdef\transury{\the\ht\tmp_box}% |
| 301 |
\ifput_into_bb \put_into_bb\box \fi |
| 302 |
\box\tmp_box \transspecial{grestore}\egroup}% |
| 303 |
\afterassignment\jump_setbox\setbox\tmp_box = |
| 304 |
}% |
| 305 |
% --- |
| 306 |
\def\update_bb#1#2#3{% used in \rotate |
| 307 |
\trigcompute{-#1}{#2}{#3}% clockwise vs anti-clockwise |
| 308 |
\ifdim\transllx>\trigxresult sp\xdef\transllx{\trigxresult sp}\fi |
| 309 |
\ifdim\translly>\trigyresult sp\xdef\translly{\trigyresult sp}\fi |
| 310 |
\ifdim\transurx<\trigxresult sp\xdef\transurx{\trigxresult sp}\fi |
| 311 |
\ifdim\transury<\trigyresult sp\xdef\transury{\trigyresult sp}\fi |
| 312 |
} |
| 313 |
\def\rotate{\hbox\bgroup \put_into_bbfalse \rotate_} |
| 314 |
\def\rotatebb{\hbox\bgroup \put_into_bbtrue \rotate_} |
| 315 |
\def\rotate_#1{% #1 -- angle, |
| 316 |
% to be followed by a box |
| 317 |
\def\after_setbox{% |
| 318 |
\setbox\tmp_box\hbox{% otherwise does not work with \vbox |
| 319 |
\transspecial{gsave currentpoint currentpoint translate |
| 320 |
#1 rotate neg exch neg exch translate}% |
| 321 |
\box\tmp_box \transspecial{grestore}}% |
| 322 |
% set bounding box |
| 323 |
\xdef\transllx{\the\z@}\xdef\translly{\the\z@}% |
| 324 |
\xdef\transurx{\the\z@}\xdef\transury{\the\z@}% |
| 325 |
\update_bb{#1}{\z@}{\ht\tmp_box}% |
| 326 |
\update_bb{#1}{\z@}{-\dp\tmp_box}% |
| 327 |
\update_bb{#1}{\wd\tmp_box}{\ht\tmp_box}% |
| 328 |
\update_bb{#1}{\wd\tmp_box}{-\dp\tmp_box}% |
| 329 |
% |
| 330 |
\wd\tmp_box\z@ \ht\tmp_box\z@ \dp\tmp_box\z@ |
| 331 |
\ifput_into_bb \put_into_bb\unhbox \fi |
| 332 |
\box\tmp_box\egroup}% |
| 333 |
\afterassignment\jump_setbox\setbox\tmp_box = |
| 334 |
}% |
| 335 |
% --- |
| 336 |
\def\plus_{+} |
| 337 |
\def\minus_{-} |
| 338 |
\def\revolvedir#1{% to be followed by a box |
| 339 |
\hbox\bgroup |
| 340 |
% check parameter: |
| 341 |
\def\param_{#1}% |
| 342 |
\ifx\param_\plus_ \else \ifx\param_\minus_ |
| 343 |
\else |
| 344 |
\errhelp{I would rather suggest to stop immediately.}% |
| 345 |
\errmessage{Argument to \noexpand\revolvedir should be either + or -}% |
| 346 |
\fi\fi |
| 347 |
\def\after_setbox{% |
| 348 |
\tmp_dim_a\wd\tmp_box |
| 349 |
% prepare to revolving: |
| 350 |
\setbox\tmp_box\hbox{% |
| 351 |
\ifx\param_\plus_\kern-\tmp_dim_a\fi |
| 352 |
\box\tmp_box |
| 353 |
\ifx\param_\plus_\kern\tmp_dim_a\fi}% |
| 354 |
% compute dimensions of the box to be revolved: |
| 355 |
\tmp_dim_a\ht\tmp_box \advance\tmp_dim_a\dp\tmp_box |
| 356 |
\tmp_dim_b\ht\tmp_box \tmp_dim_c\dp\tmp_box |
| 357 |
\dp\tmp_box\z@ \ht\tmp_box\wd\tmp_box \wd\tmp_box\tmp_dim_a |
| 358 |
% revolve: |
| 359 |
\kern \ifx\param_\plus_ \tmp_dim_c \else \tmp_dim_b \fi |
| 360 |
\transspecial{gsave currentpoint currentpoint translate |
| 361 |
#190 rotate neg exch neg exch translate}% |
| 362 |
\set_std_bb |
| 363 |
\box\tmp_box |
| 364 |
\transspecial{grestore}% |
| 365 |
\kern -\ifx\param_\plus_ \tmp_dim_c \else \tmp_dim_b \fi |
| 366 |
\egroup}% |
| 367 |
\afterassignment\jump_setbox\setbox\tmp_box = |
| 368 |
}% |
| 369 |
\def\revolveleft{\revolvedir-} |
| 370 |
\def\revolveright{\revolvedir+} |
| 371 |
\def\revolvepi{\xflip\yflip} |
| 372 |
\let\revolve\revolveleft |
| 373 |
\let\rotatepi\revolvepi |
| 374 |
% --- |
| 375 |
\def\xflip{% to be followed by a box |
| 376 |
\hbox\bgroup |
| 377 |
\def\after_setbox{% |
| 378 |
\tmp_dim_a.5\wd\tmp_box |
| 379 |
% prepare to flipping: |
| 380 |
\setbox\tmp_box |
| 381 |
\hbox{\kern-\tmp_dim_a \box\tmp_box \kern\tmp_dim_a}% |
| 382 |
% flip: |
| 383 |
\kern\tmp_dim_a |
| 384 |
\transspecial{gsave currentpoint currentpoint translate |
| 385 |
[-1 0 0 1 0 0] concat neg exch neg exch translate}% |
| 386 |
\set_std_bb |
| 387 |
\box\tmp_box |
| 388 |
\transspecial{grestore}% |
| 389 |
\kern-\tmp_dim_a |
| 390 |
\egroup}% |
| 391 |
\afterassignment\jump_setbox\setbox\tmp_box = |
| 392 |
}% |
| 393 |
% --- |
| 394 |
\def\yflip{% to be followed by a box |
| 395 |
\hbox\bgroup |
| 396 |
\def\after_setbox{% |
| 397 |
\tmp_dim_a\ht\tmp_box \tmp_dim_b\dp\tmp_box |
| 398 |
\tmp_dim_c\tmp_dim_a \advance\tmp_dim_c\tmp_dim_b |
| 399 |
\tmp_dim_c.5\tmp_dim_c |
| 400 |
% prepare to flipping: |
| 401 |
\setbox\tmp_box\vbox{% |
| 402 |
\kern\tmp_dim_c\box\tmp_box\kern-\tmp_dim_c}% |
| 403 |
% flip: |
| 404 |
\advance\tmp_dim_c-\tmp_dim_b |
| 405 |
\setbox\tmp_box\hbox{% |
| 406 |
\transspecial{gsave currentpoint currentpoint translate |
| 407 |
[1 0 0 -1 0 0] concat neg exch neg exch translate}% |
| 408 |
\lower\tmp_dim_c\box\tmp_box |
| 409 |
\transspecial{grestore}}% |
| 410 |
% restore dimensions of the flipped box: |
| 411 |
\ht\tmp_box\tmp_dim_a \dp\tmp_box\tmp_dim_b |
| 412 |
\set_std_bb |
| 413 |
\box\tmp_box |
| 414 |
\egroup}% |
| 415 |
\afterassignment\jump_setbox\setbox\tmp_box = |
| 416 |
}% |
| 417 |
% --- |
| 418 |
% save TeX registers: |
| 419 |
\let\clip_wd\tmp_dim_a |
| 420 |
\let\clip_ht\tmp_dim_b |
| 421 |
\let\clip_dp\tmp_dim_c |
| 422 |
% --- |
| 423 |
\def\tracingclipcmyk{1 0 0 0} |
| 424 |
\def\clip_fix_pos#1{\transspecial{% |
| 425 |
currentpoint /clip_#1_y exch def /clip_#1_x exch def% |
| 426 |
}} |
| 427 |
\def\clip_use_pos#1{clip_#1_x clip_#1_y} |
| 428 |
\def\clip_delta#1#2{#1 #2 3 -1 roll exch sub 3 1 roll sub exch} |
| 429 |
% |
| 430 |
\def\do_clip{\transspecial{% |
| 431 |
newpath |
| 432 |
\clip_use_pos{LL} moveto |
| 433 |
\clip_delta{\clip_use_pos{UR}}{\clip_use_pos{UL}} rlineto |
| 434 |
\clip_delta{\clip_use_pos{UR}}{\clip_use_pos{LR}} rlineto |
| 435 |
\clip_delta{\clip_use_pos{LL}}{\clip_use_pos{LR}} rlineto |
| 436 |
closepath |
| 437 |
\ifx\tracingclip\unknown \else |
| 438 |
gsave \tracingclipcmyk\space setcmykcolor fill grestore |
| 439 |
\fi |
| 440 |
clip newpath% |
| 441 |
}} |
| 442 |
% |
| 443 |
\def\clip_use_dim#1{% #1 = wd, ht, or dp |
| 444 |
\ifdim\csname clip_#1\endcsname=\maxdimen \csname#1\endcsname\tmp_box |
| 445 |
\else \csname clip_#1\endcsname\fi |
| 446 |
} |
| 447 |
% |
| 448 |
\def\clip_fix_dim#1#2{% |
| 449 |
\edef\clip_use_dim_param{#2}% |
| 450 |
\ifx\clip_use_dim_param\empty #1\maxdimen\else |
| 451 |
\ifx\clip_use_dim_param\space #1\maxdimen\else \sumto#1#2\relax \fi\fi |
| 452 |
} |
| 453 |
% |
| 454 |
\def\clipbox#1#2#3{% desired height, width and depth to be followed by a box |
| 455 |
\hbox\bgroup |
| 456 |
\clip_fix_dim\clip_wd{#1}% |
| 457 |
\clip_fix_dim\clip_ht{#2}% |
| 458 |
\clip_fix_dim\clip_dp{#3}% |
| 459 |
\clipbox_ |
| 460 |
} |
| 461 |
\def\clipbox_{% |
| 462 |
\def\after_setbox{% |
| 463 |
\setbox\tmp_box\hbox{\box\tmp_box}% |
| 464 |
\clip_wd\clip_use_dim{wd}% freeze dimen |
| 465 |
\clip_ht\clip_use_dim{ht}% ditto |
| 466 |
\clip_dp\clip_use_dim{dp}% ditto |
| 467 |
\transspecial{gsave}% |
| 468 |
\rlap{% |
| 469 |
\lower \clip_dp \vbox{% |
| 470 |
\hbox to\clip_wd{\clip_fix_pos{UL}\hss\clip_fix_pos{UR}} |
| 471 |
\kern\clip_ht \kern\clip_dp \nointerlineskip |
| 472 |
\hbox to\clip_wd{\clip_fix_pos{LL}\hss\clip_fix_pos{LR}} |
| 473 |
\do_clip |
| 474 |
}% |
| 475 |
}% |
| 476 |
\wd\tmp_box=\clip_wd \ht\tmp_box=\clip_ht \dp\tmp_box=\clip_dp |
| 477 |
\set_std_bb \box\tmp_box \transspecial{grestore}\egroup}% |
| 478 |
\afterassignment\jump_setbox\setbox\tmp_box = |
| 479 |
} |
| 480 |
% --------------------------------------------------------------------------- |
| 481 |
% ``floating point arithmetic'' (excerpted from T. Rokicki): |
| 482 |
% r y |
| 483 |
% |
| 484 |
% ^ |
| 485 |
% | |
| 486 |
% | |
| 487 |
% | |
| 488 |
% | |
| 489 |
% | |
| 490 |
% 0--------------> t x |
| 491 |
% |
| 492 |
% save TeX registers: |
| 493 |
\let\dim_x\tmp_dim_a % horizontal size after scaling |
| 494 |
\let\dim_y\tmp_dim_b % vertical size after scaling |
| 495 |
\let\dim_t\tmp_dim_c % horizontal size before scaling |
| 496 |
\let\dim_r\tmp_dim_d % vertical size before scaling |
| 497 |
%\tmp_dim % register for arithmetic manipulation (already declared) |
| 498 |
% --- |
| 499 |
\def\resize |
| 500 |
% dimen registers: |
| 501 |
#1% y make y such that y/r=x/t |
| 502 |
#2% r |
| 503 |
#3% x |
| 504 |
#4% t |
| 505 |
% We have a sticky problem here: TeX doesn't do floating point arithmetic! |
| 506 |
% Our goal is to compute y = rx/t. The following loop does this reasonably |
| 507 |
% fast, with an error of at most about 16 sp (about 1/4000 pt). |
| 508 |
{% |
| 509 |
% save parameters to the internal variables: |
| 510 |
\dim_r#2\relax \dim_x#3\relax \dim_t#4\relax |
| 511 |
\tmp_dim=\dim_r \divide\tmp_dim\dim_t |
| 512 |
\dim_y=\dim_x \multiply\dim_y\tmp_dim |
| 513 |
\multiply\tmp_dim\dim_t \advance\dim_r-\tmp_dim |
| 514 |
\tmp_dim=\dim_x |
| 515 |
\loop \advance\dim_r\dim_r \divide\tmp_dim 2 |
| 516 |
\ifnum\tmp_dim>0 |
| 517 |
\ifnum\dim_r<\dim_t\else |
| 518 |
\advance\dim_r-\dim_t \advance\dim_y\tmp_dim \fi |
| 519 |
\repeat |
| 520 |
% assign result: |
| 521 |
#1\dim_y\relax |
| 522 |
} |
| 523 |
% --------------------------------------------------------------------------- |
| 524 |
% ``fixed point arithmetic'' -- fractions and trigometry, inspired by mf.web: |
| 525 |
% |
| 526 |
% save TeX registers: |
| 527 |
\let\fracint\tmp_dim |
| 528 |
\let\fracfrac\tmp_count_a |
| 529 |
\let\fracprod\tmp_count_b |
| 530 |
\def\fracpowlimit{30}% |
| 531 |
\def\fracone{1073741824}% = 2^\fracpowlimit |
| 532 |
% --- |
| 533 |
\def\fracproduct#1#2{% #1 = fraction * 2^\fracpowlimit, #2 = integer |
| 534 |
% result: macro \fracresult = floor(#1 * #2 / 2^\fracpowlimit + 1/2) |
| 535 |
% expanding to the count equivalent of the respective dimen |
| 536 |
\begingroup |
| 537 |
\fracfrac#1\relax % \fracfrac <= 2^30 |
| 538 |
\fracint#2\relax % \fracint <= \maxdimen |
| 539 |
\ifdim\fracint<0pt \fracint-\fracint\def\fracsign{-}\else\def\fracsign{}\fi |
| 540 |
\ifnum\fracone=\fracfrac \fracprod\fracint \else |
| 541 |
\advance\fracfrac\fracone % \fracfrac < 2^31 |
| 542 |
\fracprod\fracone % if \fracprod were dimen, this would yield error |
| 543 |
\divide\fracprod2 % \fracprod = 2^29 (representation of 1/2) |
| 544 |
\loop |
| 545 |
\ifodd\fracfrac \advance \fracprod\fracint \fi |
| 546 |
\divide\fracprod2 \divide\fracfrac2 |
| 547 |
\ifnum \fracfrac>1 \repeat |
| 548 |
\fi |
| 549 |
\xdef\fracresult{\fracsign\number\fracprod}% |
| 550 |
\endgroup |
| 551 |
} |
| 552 |
% --- |
| 553 |
\newdimen\onedegree |
| 554 |
\onedegree16pt % this must be consistent with the table below |
| 555 |
% save TeX registers: |
| 556 |
\let\trigangle\tmp_dim_a |
| 557 |
\let\trigxpart\tmp_dim_b |
| 558 |
\let\trigypart\tmp_dim_c |
| 559 |
\let\trigxtmp\tmp_dim |
| 560 |
\let\trigiter\tmp_count_a |
| 561 |
\def\triglimit{28}% |
| 562 |
% --- |
| 563 |
\def\trigvalarg#1{\csname argscaled:\number#1\endcsname} |
| 564 |
\def\trigvalcos#1{\csname cosscaled:\number#1\endcsname} |
| 565 |
\def\trigvalsin#1{\csname sinscaled:\number#1\endcsname} |
| 566 |
\def\defspectrig#1#2#3#4{% |
| 567 |
% #1 -- ordering number (index) |
| 568 |
% #2 -- angle in degrees * \onedegree expressed in sp; alpha=#1*2^(-20) |
| 569 |
% #3 -- floor(cosd(alpha)*2^30+1/2) (30=\fracpowlimit) |
| 570 |
% #4 -- floor(sind(alpha)*2^30+1/2) |
| 571 |
\expandafter\def\csname argscaled:#1\endcsname{#2}% |
| 572 |
\expandafter\def\csname cosscaled:#1\endcsname{#3}% |
| 573 |
\expandafter\def\csname sinscaled:#1\endcsname{#4}% |
| 574 |
} |
| 575 |
\defspectrig{1}{62914560}{536870912}{929887697} % alpha=60 |
| 576 |
\defspectrig{2}{47185920}{759250125}{759250125} % 45 |
| 577 |
\defspectrig{3}{31457280}{929887697}{536870912} % 30 |
| 578 |
\defspectrig{4}{16777216}{1032146887}{295963357} % 2^4 |
| 579 |
\defspectrig{5}{8388608}{1063292242}{149435979} % 2^3 |
| 580 |
\defspectrig{6}{4194304}{1071126243}{74900443} % 2^2 |
| 581 |
\defspectrig{7}{2097152}{1073087729}{37473049} % 2^1 |
| 582 |
\defspectrig{8}{1048576}{1073578288}{18739379} % 2^0 |
| 583 |
\defspectrig{9}{524288}{1073700939}{9370046} % 2^-1 |
| 584 |
\defspectrig{10}{262144}{1073731603}{4685068} % 2^-2 |
| 585 |
\defspectrig{11}{131072}{1073739269}{2342539} % 2^-3 |
| 586 |
\defspectrig{12}{65536}{1073741185}{1171270} % 2^-4 |
| 587 |
\defspectrig{13}{32768}{1073741664}{585635} % 2^-5 |
| 588 |
\defspectrig{14}{16384}{1073741784}{292818} % 2^-6 |
| 589 |
\defspectrig{15}{8192}{1073741814}{146409} % 2^-7 |
| 590 |
\defspectrig{16}{4096}{1073741822}{73204} % 2^-8 |
| 591 |
\defspectrig{17}{2048}{1073741823}{36602} % 2^-9 |
| 592 |
\defspectrig{18}{1024}{1073741824}{18301} % 2^-10 |
| 593 |
\defspectrig{19}{512}{1073741824}{9151} % 2^-11 |
| 594 |
\defspectrig{20}{256}{1073741824}{4575} % 2^-12 |
| 595 |
\defspectrig{21}{128}{1073741824}{2288} % 2^-13 |
| 596 |
\defspectrig{22}{64}{1073741824}{1144} % 2^-14 |
| 597 |
\defspectrig{23}{32}{1073741824}{572} % 2^-15 |
| 598 |
\defspectrig{24}{16}{1073741824}{286} % 2^-16 |
| 599 |
\defspectrig{25}{8}{1073741824}{143} % 2^-17 |
| 600 |
\defspectrig{26}{4}{1073741824}{71} % 2^-18 |
| 601 |
\defspectrig{27}{2}{1073741824}{36} % 2^-19 |
| 602 |
\defspectrig{28}{1}{1073741824}{18} % 2^-20 |
| 603 |
% --- |
| 604 |
\def\trigcompute#1#2#3{% |
| 605 |
% #1 angle in degrees (a) |
| 606 |
% #2 initial xpart (x) |
| 607 |
% #3 initial ypart (y) |
| 608 |
% result: (x',y')=(x,y) rotated a; the pair of macros |
| 609 |
% \trigxresult and \trigyresult contain x' and y', respectively; |
| 610 |
% both expand to the count equivalent of the respective dimen |
| 611 |
\begingroup |
| 612 |
\trigangle#1\onedegree \trigxpart#2\relax \trigypart#3\relax |
| 613 |
\loop \ifdim\trigangle<0sp \advance\trigangle360\onedegree \repeat |
| 614 |
\loop \ifdim\trigangle>360\onedegree \advance\trigangle-360\onedegree \repeat |
| 615 |
\ifdim\trigangle=360\onedegree \trigangle0sp \fi |
| 616 |
\ifdim\trigangle<180\onedegree \else % >= |
| 617 |
\trigxpart-\trigxpart \trigypart-\trigypart |
| 618 |
\advance\trigangle-180\onedegree |
| 619 |
\fi |
| 620 |
\ifdim\trigangle<90\onedegree \else % >= |
| 621 |
\trigxtmp\trigxpart \trigxpart-\trigypart \trigypart\trigxtmp |
| 622 |
\advance\trigangle-90\onedegree |
| 623 |
\fi |
| 624 |
\trigiter1\relax |
| 625 |
\loop |
| 626 |
\ifnum\trigvalarg\trigiter>\trigangle \else % <= |
| 627 |
\advance\trigangle-\trigvalarg\trigiter sp |
| 628 |
\trigxtmp\trigxpart |
| 629 |
% x=x*cos[i]-y*sin[i] : |
| 630 |
\fracproduct{\trigvalcos\trigiter}\trigxpart |
| 631 |
\trigxpart\fracresult sp |
| 632 |
\fracproduct{\trigvalsin\trigiter}\trigypart |
| 633 |
\advance\trigxpart-\fracresult sp |
| 634 |
% y=y*cos[i]+x*sin[i] : |
| 635 |
\fracproduct{\trigvalcos\trigiter}\trigypart |
| 636 |
\trigypart\fracresult sp |
| 637 |
\fracproduct{\trigvalsin\trigiter}\trigxtmp |
| 638 |
\advance\trigypart\fracresult sp |
| 639 |
\fi |
| 640 |
\advance\trigiter1 |
| 641 |
\ifnum\trigangle>0 \repeat |
| 642 |
% result in dimen registers: \trigxpart and \trigypart |
| 643 |
\xdef\trigxresult{\number\trigxpart}% |
| 644 |
\xdef\trigyresult{\number\trigypart}% |
| 645 |
\endgroup |
| 646 |
} |
| 647 |
% --------------------------------------------------------------------------- |
| 648 |
% restore original catcodes: |
| 649 |
\catcode`\@\transatcode |
| 650 |
\catcode`\_\transundcode |
| 651 |
% --------------------------------------------------------------------------- |
| 652 |
\endinput |
| 653 |
|