| 1 |
%NAME: texpictex.tex |
| 2 |
% texpictex.tex -- The following macros over-ride certain definitions in the |
| 3 |
% PiCTeX macro package. The net effect is that line-drawing is done using |
| 4 |
% the \special's used by texpic (tpic). Several DVI printers understand |
| 5 |
% and handle these specials. |
| 6 |
% |
| 7 |
% Currently, only straight lines are translated. Recently, I added a |
| 8 |
% clipping routine to clip to the bounding box. |
| 9 |
% |
| 10 |
% If people extend this to included elliptic circles and quadratics, |
| 11 |
% please forward the extensions to me (quads are used in the \arrow |
| 12 |
% macro, making them very slow). |
| 13 |
% |
| 14 |
% Dirk Grunwald |
| 15 |
% Univ. of Illinois |
| 16 |
% [email protected] |
| 17 |
% |
| 18 |
\def\makebangletter{\catcode`\!=11\relax} |
| 19 |
\def\makebangother{\catcode`\!=12\relax} |
| 20 |
% |
| 21 |
\makebangletter |
| 22 |
% |
| 23 |
% The units that texpic deals in. You should define it this way instead |
| 24 |
% of simply saying ``0.001in'' because the difference in resolution |
| 25 |
% actually makes a big difference |
| 26 |
% |
| 27 |
\newdimen\!tpu |
| 28 |
\!tpu=1in |
| 29 |
\divide\!tpu by 1000 |
| 30 |
%%% |
| 31 |
%% \!maptpus -- map a PiCTeX dimension to a TeXPiC dimension |
| 32 |
%% using the \!tpu conversion factor. |
| 33 |
%% |
| 34 |
%% uses: dimen0 |
| 35 |
%% |
| 36 |
\def\!maptpus#1#2 {\dimen0=#1\divide \dimen0 by \!tpu #2=\dimen0} |
| 37 |
% |
| 38 |
% ** \setplotsymbol ({PLOTSYMBOL} [ ] < , >) |
| 39 |
% ** Save PLOTSYMBOL away in an hbox for use with curve plotting routines |
| 40 |
% ** See Subsection 5.2 of the manual. |
| 41 |
\def\setplotsymbol(#1#2){% |
| 42 |
\!setputobject{#1}{#2} |
| 43 |
\setbox\!plotsymbol=\box\!putobject% |
| 44 |
\!plotsymbolxshift=\!xshift |
| 45 |
\!plotsymbolyshift=\!yshift |
| 46 |
% |
| 47 |
% Additions: compute size of dot, convert to TPUs and issue a pensize |
| 48 |
% |
| 49 |
\!dimenB=\wd\!plotsymbol |
| 50 |
\!dimenC=\ht\!plotsymbol |
| 51 |
\advance\!dimenC by \dp\!plotsymbol |
| 52 |
\ifdim\!dimenB<\!dimenC \!dimenF=\!dimenC \else \!dimenF=\!dimenB\fi |
| 53 |
\!maptpus{\!dimenF}{\!countC} |
| 54 |
\special{pn \the\!countC} |
| 55 |
\ignorespaces} |
| 56 |
|
| 57 |
\setplotsymbol({\fiverm .})% ** initialize plotsymbol |
| 58 |
|
| 59 |
% ** The following routine is used to draw a "solid" line between (xS,yS) |
| 60 |
% ** and (xE,yE). Points are spaced nearly every \plotsymbolspacing length |
| 61 |
% ** along the line. |
| 62 |
% |
| 63 |
% Note: this is a replacement for PicTeX \!linearsolid. |
| 64 |
% If line clipping is enabled, the line to be drawn is |
| 65 |
% clipped using \!clipline. If there's anything left |
| 66 |
% to draw after clipping, it's drawn. If clipping is off, |
| 67 |
% the line is simply drawn. In either case, line drawing |
| 68 |
% is done by \!texpicline. |
| 69 |
% |
| 70 |
\def\!linearsolid{% |
| 71 |
\let\!nextLinearAct=\!texpicline |
| 72 |
\expandafter\ifx \!initinboundscheck \relax |
| 73 |
\else \!clipline \if!InBounds \else \let\!nextLinearAct=\relax \fi \fi% |
| 74 |
\!nextLinearAct% |
| 75 |
} |
| 76 |
% |
| 77 |
% Texpic has increasing origin in the upper left corner, while |
| 78 |
% pictex has origin in bottom left corner. Ergo, we flip the signs |
| 79 |
% for y-coordinates. |
| 80 |
% |
| 81 |
\def\!texpicline{% |
| 82 |
\advance\!xS by -\!xorigin |
| 83 |
\advance\!xE by -\!xorigin |
| 84 |
\advance\!yS by -\!yorigin |
| 85 |
\advance\!yE by -\!yorigin |
| 86 |
\!maptpus{\!xS}{\!countC} \!maptpus{\!yS}{\!countD} \!countD=-\!countD% |
| 87 |
\special{pa \the\!countC \space \the\!countD}% |
| 88 |
\!maptpus{\!xE}{\!countC} \!maptpus{\!yE}{\!countD} \!countD=-\!countD% |
| 89 |
\special{pa \the\!countC \space \the\!countD}\special{fp}% |
| 90 |
\ignorespaces} |
| 91 |
% |
| 92 |
%%% |
| 93 |
% Code to support line clipping |
| 94 |
% |
| 95 |
% Line clipping routine. Clips to bounding box specified |
| 96 |
% by (!checkleft, !checkbot) and (!checkright, !checktop). |
| 97 |
% Note that this box is only defined if \initboundscheckon |
| 98 |
% has been called. |
| 99 |
% |
| 100 |
% The clipping algorithm was published in ACM TOG Vol 3 No 1 |
| 101 |
% by people at Berkeley, but I've forgotten the complete reference. |
| 102 |
% This was translated from a version I wrote in C. |
| 103 |
% |
| 104 |
%% |
| 105 |
% After calling \!cliplines, !InBounds tells you if the line contains |
| 106 |
% any points within the clipping window. |
| 107 |
% |
| 108 |
\newif\if!InBounds |
| 109 |
% |
| 110 |
%% |
| 111 |
% \!clipt -- this corresponds to the routine by the same name |
| 112 |
% in the published algorithm. |
| 113 |
% |
| 114 |
% Dimens used are descibed below. All are grouped and know that |
| 115 |
% PiCTeX doesn't use dimen0..9. Variable names are taken from |
| 116 |
% the TOG article. The junk on the r.h.s. is indenting information |
| 117 |
% |
| 118 |
% Globals: dimen8 corresponds to t0 |
| 119 |
% dimen9 corresponds to t1 |
| 120 |
% |
| 121 |
% clipt dimen0 corresponds to p |
| 122 |
% dimen1 corresponds to q |
| 123 |
% dimen2 corresponds to r |
| 124 |
% |
| 125 |
% !fastclip Uses bounding boxes |
| 126 |
% |
| 127 |
% !clipline passes dimen3 to clipt as p |
| 128 |
% passes dimen4 to clipt as q |
| 129 |
% uses dimen0, dimen2 |
| 130 |
% |
| 131 |
% |
| 132 |
\def\!clipt#1#2{% |
| 133 |
\dimen0=#1 \relax \dimen1=#2 \relax |
| 134 |
\ifdim \dimen0 < \!zpt% >0 |
| 135 |
\!divide{\dimen1}{\dimen0}{\dimen2}% |
| 136 |
\ifdim \dimen2 > \dimen9% >1 |
| 137 |
\global\!InBoundsfalse |
| 138 |
\else% =1 |
| 139 |
\ifdim \dimen2 > \dimen8 \dimen8=\dimen2 \fi |
| 140 |
\fi% <1 |
| 141 |
\else \ifdim \dimen0 > \!zpt% =0>1 |
| 142 |
\!divide{\dimen1}{\dimen0}{\dimen2}% |
| 143 |
\ifdim \dimen2 < \dimen8% >2 |
| 144 |
\global\!InBoundsfalse |
| 145 |
\else% =2 |
| 146 |
\ifdim \dimen2 < \dimen9 \dimen9=\dimen2 \fi |
| 147 |
\fi% <2 |
| 148 |
\else% =1 |
| 149 |
\ifdim \dimen1 < \!zpt \global\!InBoundsfalse \fi |
| 150 |
\fi% <1 |
| 151 |
\fi% <0 |
| 152 |
} |
| 153 |
% |
| 154 |
% fastclipcheck |
| 155 |
% |
| 156 |
\def\!fastclip#1#2{% |
| 157 |
\ifdim #1<\!checkleft \global\!InBoundsfalse \else |
| 158 |
\ifdim #1>\!checkright \global\!InBoundsfalse \else |
| 159 |
\ifdim #2<\!checkbot \global\!InBoundsfalse \else |
| 160 |
\ifdim #2>\!checktop \global\!InBoundsfalse \else |
| 161 |
\fi |
| 162 |
\fi |
| 163 |
\fi |
| 164 |
\fi} |
| 165 |
% |
| 166 |
% clipline - clip a line to the current bounding box. |
| 167 |
% assumes line is in (!xS, !yS) and extends to (!xE,!yE) and that |
| 168 |
% \!xdiff and \!ydiff has been set up. This is normally done |
| 169 |
% in \!lstart. |
| 170 |
% |
| 171 |
% \!clipline first checks to see if the start & end points are |
| 172 |
% conainted in the clipping box. If the simple compare works, |
| 173 |
% then no clipping is done, else \!doclip is called to |
| 174 |
% do the actually clipping computations. |
| 175 |
% |
| 176 |
\def\!clipline{% |
| 177 |
\!!initinboundscheck |
| 178 |
\!InBoundstrue |
| 179 |
\!fastclip{\!xS}{\!yS}% |
| 180 |
\!fastclip{\!xE}{\!yE}% |
| 181 |
\if!InBounds\else\!doclip\fi} |
| 182 |
% |
| 183 |
\def\!doclip{% |
| 184 |
\begingroup% |
| 185 |
\global\!InBoundstrue% |
| 186 |
\dimen8=0pt |
| 187 |
\dimen9=1pt |
| 188 |
% |
| 189 |
\dimen3=-\!xdiff |
| 190 |
\dimen4=\!xS \advance\dimen4 by -\!checkleft% fromX-minX |
| 191 |
\!clipt{\dimen3}{\dimen4}% |
| 192 |
% |
| 193 |
\if!InBounds% 0 |
| 194 |
\dimen3=\!xdiff |
| 195 |
\dimen4=\!checkright \advance\dimen4 by -\!xS% maxX - fromX |
| 196 |
\!clipt{\dimen3}{\dimen4}% |
| 197 |
% |
| 198 |
\if!InBounds% 1 |
| 199 |
% |
| 200 |
\dimen3=-\!ydiff |
| 201 |
\dimen4=\!yS \advance\dimen4 by -\!checkbot% fromY-minY |
| 202 |
\!clipt{\dimen3}{\dimen4}% |
| 203 |
% |
| 204 |
\if!InBounds% 2 |
| 205 |
% |
| 206 |
\dimen3=\!ydiff |
| 207 |
\dimen4=\!checktop \advance\dimen4 by -\!yS% maxY-fromY |
| 208 |
\!clipt{\dimen3}{\dimen4}% |
| 209 |
% |
| 210 |
\if!InBounds% 3 |
| 211 |
\dimen0=1pt |
| 212 |
% |
| 213 |
% The following \if's truncate the line based on the solution |
| 214 |
% to the parametric solution to the bounding box. |
| 215 |
% |
| 216 |
% Note that we don't have a \!multiply, the equivilent to \!divide. |
| 217 |
% The code below compute X * Y as (x / ( 1/ Y)), which is far |
| 218 |
% from optimal. |
| 219 |
% |
| 220 |
\ifdim\dimen9 < \dimen0% 4 |
| 221 |
\!divide{\dimen0}{\dimen9}{\dimen2}% |
| 222 |
% |
| 223 |
\dimen3=\!xdiff \!divide{\dimen3}{\dimen2}{\dimen4}% |
| 224 |
\global\!xE=\dimen4 \global\advance\!xE by \!xS |
| 225 |
% |
| 226 |
\dimen3=\!ydiff \!divide{\dimen3}{\dimen2}{\dimen4}% |
| 227 |
\global\!yE=\dimen4 \global\advance\!yE by \!yS |
| 228 |
\fi% 4 |
| 229 |
\ifdim\dimen8 > \!zpt% 4 |
| 230 |
\!divide{\dimen0}{\dimen8}{\dimen2}% |
| 231 |
% |
| 232 |
\dimen3=\!xdiff \!divide{\dimen3}{\dimen2}{\dimen4}% |
| 233 |
\global\advance\!xS by \dimen4 |
| 234 |
% |
| 235 |
\dimen3=\!ydiff \!divide{\dimen3}{\dimen2}{\dimen4}% |
| 236 |
\global\advance\!yS by \dimen4 |
| 237 |
\fi% 4 |
| 238 |
\fi% 3 |
| 239 |
\fi% 2 |
| 240 |
\fi% 1 |
| 241 |
\fi% 0 |
| 242 |
\endgroup} |
| 243 |
% |
| 244 |
\makebangother |