%
% Macros used in the file links.pdf
% D. P. Story, The University of Akron
%   dpstory@uakron.edu
%   http://www.math.uakron.edu/~dpstory/
%
\newif\ifdvipsone
%
% Set this switch to conform to your system
%
  \dvipsonetrue   % if you use dvipsone (comment out if you use dvips)
% \dvipsonefalse  % uncomment this if you use dvips
%
% Note: If you are using exclusively one driver or the other, it is 
% best to delete all reference to the other driver: E.g., delete
% \newif\ifdvipsone, \ifdvipsone, \else....\fi
% Or delete all reference to dvipsone.
%------------------ Begin Macro Definitions ----------------------%
%
% Boxes and Registers used.  These are used by \htxt defined below.
% 
\newbox\bbox
\newcount\hhght \newcount\hwdth \newcount\hdpth
%
% \htxt#1 : Useage, enclose #1 in \bbox (an hbox) and transfer
%           dimension info to the count registers \hhght,
%           \hwdth, and \hdpth,  To typeset #1 you  must
%           \unhbox\bbox
\def\htxt#1{\setbox\bbox=\hbox{#1}\hhght=\ht\bbox\hwdth=\wd\bbox
   \hdpth=\dp\bbox}
%
% Define some PostScript procedure and store them in the user
%   dictionary for use later.
\ifdvipsone
%
% dvipsone works in TeX's scaled points these two procedures 
% transform scaled points to pdf points (TeXtoPDF) and
% from pdf points to scaled points (PDFtoTeX).
%
\special{!/TeXtoPDF {65536 div mag 1000 div mul} def
   /PDFtoTeX {65536 mul mag 1000 div div} def}
\else
%
% dvips, as I have found out recently, is more complicated than
% dvipsone. dvips makes calculations in "pixels" (dots?). There are
% 72.27 points per inch and Resolution is measured in dots per inch (dpi).
% on my MikTeX system, Resolution is set to 600 (dpi)
% 
% Sometimes horizontal resolution (Resolution) is different from
% vertical resolution (VResolution).
%
% This part was written by David Wilson, Monash University, Australia.
%
\special{!userdict begin
   /TeXtoPDF {65536 div DVImag mul} def         % sp to pts
   /PDFtoDvips {72.27 div Resolution mul} def   % points to dots
   /PDFtoVDvips {72.27 div VResolution mul} def % points to dots
   /DvipstoPDF {72.27 mul Resolution div} def   % dots to points
   /HTeXtoDvips {TeXtoPDF PDFtoDvips} def       % sp to dots
   /VTeXtoDvips {TeXtoPDF PDFtoVDvips} def end} % sp to dots
%
% Here is a procedure I used to show encapsulated graphical objects
%   using the SP operator.  
\special{!userdict begin /cstr {currentpoint translate
   1 PDFtoDvips DVImag mul -1 PDFtoVDvips DVImag mul scale}def end}
\fi
%
% \Rect : This macro calculates the corners of the bounding rectangle
%         of a link or form annotation.  It is used a the value
%         of the /Rect key.  Thus, we type: /Rect \Rect, this will
%         expand to /Rect [ xll yll xur yur ]
%
\ifdvipsone
%
% Dvipsone thinks in \TeX's scaled points. We calculate the coordinates
% of the rectangle, taking its dimensions from \hdpth, \hwdth, \hhght,
% which are the dimensions of \bbox measured in scaled points.
% Dvipsone apparently takes the value of the /Rect key and transforms
% these coordintes to pdf points for us.  Thanks!
%
\def\Rect{[ currentpoint 2 copy \the\hdpth\space add 4 2 roll
  exch \the\hwdth\space add exch \the\hhght\space sub ]}
\else
%
% Dvips thinks in terms of "pixels" or dots (as in dpi). dvips again
% converts the coordintes to pdf points for us (thanks), but expects
% the coordinates to be in "pixels" or dots, whichever terminology
% you prefer.
%
% This bit was written by David Wilson, Monash University, Australia.
%
\def\Rect{% 
  [ currentpoint 2 copy \the\hdpth\space VTeXtoDvips add   % y1 and x1   
    4 2 roll exch \the\hwdth\space HTeXtoDvips add         % x2
    exch \the\hhght \space VTeXtoDvips sub ]}              % y2
\fi
%
% \FitRbboxB#1 : Performs the same tasks as \Rect, but with several
% twists. There is not automatic conversion to the pdf coordinate
% system. 
%
\ifdvipsone
\def\FitRbboxB#1{ % Uses \bbox
   currentpoint 2 copy \the\hdpth\space add TeXtoPDF
   neg PageHeight add 72 sub #1\space sub      % y1
   exch TeXtoPDF 72 add #1\space sub exch      % x1
   4 2 roll exch \the\hwdth\space add  
   TeXtoPDF 72 add #1\space add exch           % x2
   \the\hhght\space sub TeXtoPDF neg  
   PageHeight add 72 sub #1\space add}         % y2
\else
\def\FitRbboxB#1{% Uses \bbox
  currentpoint 2 copy DvipstoPDF \the\hdpth\space TeXtoPDF add 
  neg vsize add 72 sub #1\space sub exch          % y1
  DvipstoPDF 72 add #1\space sub exch             % x1
  4 2 roll exch DvipstoPDF \the\hwdth\space
  TeXtoPDF add 72 add #1\space add exch           % x2
  DvipstoPDF \the\hhght \space TeXtoPDF sub
  neg vsize add 72 sub #1\space add}              % y2
\fi
%
% \surroundit[#1,#2,#3,#4]#5 : a boxing type macro. This takes #5
% and surrounds it with an "invisible" rectangle: 
%
\def\surroundit[#1,#2,#3,#4]#5{%
   \vbox{\hbox{\kern#1pt\vbox{\kern#2pt#5\kern#3pt}\kern#4pt}}}
%
% \Bbox[#1,#2] : constructs an invisible rectangle #1pt by #2 pt
%                used quite a bit in forms.pdf
\def\Bbox[#1,#2]{\surroundit[#1,#2,0,0]\null}   
%
% Color Macros.  Keep it short and simple.
% Use other color macros of your choice.
%
\def\pushcolor#1{\special{color push rgb #1}}
\def\popcolor{\special{color pop}}
\def\green{0 0.5 0} \def\blue{0 0 1}      % a limited number of
\def\red{1 0 0} \def\brown{.6 0 0}        %   basic colors
\def\hb#1{\pushcolor\blue{#1}\popcolor}   % blue text
\def\hg#1{\pushcolor\green{#1}\popcolor}  % green text
\def\hr#1{\pushcolor\red{#1}\popcolor}    % red text
\def\hbr#1{\pushcolor\brown{#1}\popcolor} % brown text
   
\endinput
%
%  \htxt[#1,#2,#3]#4 : typeset #4
%  increase \ht\bbox by #1, increase \wd\bbox by #2,
%  and increase \dp\bbox by #3.  Without the optional parameters,
%  \htxt behaves exactly link \htxt defined above.
%
%  Usage: \htxt{Click Here}...\unhbox\bbox
%  or     \htxt[3,3,3]{Click Here}...\unhbox\bbox
%
\newdimen\tmpdimen  % additional scratch dimension register needed
%
% Define a new \htxt with thee new arguments
\def\htxt{\futurelet\next\htxti}
\def\htxti{\ifx\next[\expandafter\htxtii\else\expandafter\htxtiii\fi}
\def\htxtii[#1,#2,#3]#4{\setbox\bbox=\hbox{\kern#2#4\kern#2}%
   \adjustbbox[#1,#3]\hhght=\ht\bbox\hwdth=\wd\bbox\hdpth=\dp\bbox}
\def\htxtiii#1{\setbox\bbox=\hbox{#1}\hhght=\ht\bbox
   \hwdth=\wd\bbox\hdpth=\dp\bbox}
\def\adjustbbox[#1,#2]{\tmpdimen=\ht\bbox\advance\tmpdimen#1
   \ht\bbox=\tmpdimen\tmpdimen=\dp\bbox\advance\tmpdimen#2
   \dp\bbox=\tmpdimen}
  
   


