%% $Id: pst-abspos.tex 135 2009-09-27 12:33:57Z herbert $
%%
%% This is file `pst-abspos.tex',
%%
%% IMPORTANT NOTICE:
%%
%% Package `pst-abspos.tex'
%%
%% Herbert Voss <voss@perce.de>
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   `pst-abspos' is a PSTricks package to put objects at absolute coordinates
%%
%% For a ChangeLog go the the end
%%
\csname PSTabsposLoaded\endcsname
\let\PSTabsposLoaded\endinput
% Requires PSTricks, pst-node
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTnodesLoaded\endinput\else\input pst-node.tex\fi
\ifx\PSTXKeyLoaded\endinput\else\input pst-xkey \fi
%
\def\fileversion{0.2}
\def\filedate{2009/09/27}
\message{`PST-abspos' v\fileversion, \filedate\space (Herbert Voss)}
%
\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
\SpecialCoor
%
\pst@addfams{pst-abspos}
%
\newif\ifpst@lowerleft \pst@lowerleftfalse
\newif\ifpst@notitlepage \pst@notitlepagefalse
\newdimen\pst@xOffset
\newdimen\pst@yOffset
%
\define@key[psset]{pst-abspos}{position}{\edef\psk@abspos@position{#1}}
\psset{position=lb}
%
\let\pst@newpage\newpage
%
\DeclareOption{notitlepage}{\pst@notitlepagetrue}
\DeclareOption{absolute}{%
    \ifpst@notitlepage
        \def\newpage{\pst@newpage\pstSetAbsoluteOrigin}%
        \AtBeginDocument{\pstSetAbsoluteOrigin}
    \fi%
}
\DeclareOption{lowerleft}{\pst@lowerlefttrue}
\DeclareOption{relative}{%
    \ifpst@notitlepage
        \def\newpage{\pst@newpage\pstSetRelativeOrigin(0,0)}%
        \AtBeginDocument{\pstSetRelativeOrigin(0,0)}
    \fi%
}
\DeclareOption{PostScript}{%
    \ifpst@notitlepage
        \def\newpage{\pst@newpage\pstSetPostScriptOrigin}%
        \AtBeginDocument{\pstSetPostScriptOrigin}
    \fi%
}
\ProcessOptions\relax
%
\def\pst@paperheight{\ifpst@lowerleft 1 \else 0 \fi }
%
% save the origin point of the paper plane. This macro must be
% initiated before any other output
%
\def\pstSetRelativeOrigin(#1){\pnode(#1){pst@Origin}}
\def\pstSetAbsoluteOrigin{%
    \pst@xOffset=-\oddsidemargin%
    \advance\pst@xOffset by -\parindent%
    \pst@yOffset=\topmargin%
    \advance\pst@yOffset by \headheight%
    \advance\pst@yOffset by \headsep%
    \advance\pst@yOffset by \topskip%
    \bgroup
        \psset{unit=1pt}
%       \pnode(\strip@pt\pst@xOffset, \strip@pt\pst@yOffset){pstTextOrigin}%
        \pnode(0,0){pstTextOrigin}%
        \advance\pst@xOffset by -1in%
        \advance\pst@yOffset by 1in%
        \ifpst@lowerleft
            \advance\pst@yOffset by -\paperheight
            \advance\pst@yOffset by 1in%
        \fi
        \pnode(\strip@pt\pst@xOffset, \strip@pt\pst@yOffset){pst@Origin}%
    \egroup%
}
\def\pstSetPostScriptOrigin{%
    \pst@xOffset=-\oddsidemargin%
    \advance\pst@xOffset by -\parindent%
    \pst@yOffset=\topmargin%
    \advance\pst@yOffset by \headheight%
    \advance\pst@yOffset by \headsep%
    \advance\pst@yOffset by \topskip%
    \bgroup
        \psset{unit=1pt}
        \pnode(\strip@pt\pst@xOffset, \strip@pt\pst@yOffset){pstTextOrigin}%
        \ifpst@lowerleft
            \advance\pst@yOffset by -\paperheight
            \advance\pst@yOffset by 3in
        \fi
        \pnode(\strip@pt\pst@xOffset, \strip@pt\pst@yOffset){pst@Origin}%
    \egroup}
%
\def\pstPutAbs{\@ifnextchar[{\pst@PutAbs@i}{\pst@PutAbs@i[]}}
\def\pst@PutAbs@i[#1](#2)#3{{%
% #1: options for \rput[#1]{...}
% #2: absolute coordinates relative to the paper (0,0)
% #3: any object to put at (#1)
    \psset{#1}
    \pnode(0,0){pst@tempNodeA}              % the "cursor" position
    \pst@getcoor{pst@Origin}\pst@tempa      % Origin of the paper
    \pst@getcoor{#2}\pst@tempb              % Absolute coordinates
    \pst@getcoor{pst@tempNodeA}\pst@tempc   % relative coordinates
    \pnode(!                                % Special Coor
        /XA \pst@tempa pop \pst@number\psxunit div def
        /YA \pst@tempa exch pop \pst@number\psyunit div def
        /XB \pst@tempb pop \pst@number\psxunit div def
        /YB \pst@tempb exch pop \pst@number\psyunit div def
        /XC \pst@tempc pop \pst@number\psxunit div def
        /YC \pst@tempc exch pop \pst@number\psyunit div def
        XB XC sub XA add
        YB YC sub YA add \pst@paperheight\space sub){pst@tempNodeB}
    \rput[\psk@abspos@position](pst@tempNodeB){#3}%
}}
%
\catcode`\@=\PstAtCode\relax
%
%% END: pst-abspos.tex
\endinput
