%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.

\csname PSTANAMORPHOSISLoaded\endcsname
\let\PSTANAMORPHOSISLoaded\endinput
% Requires some packages
\ifx\PSTricksLoaded\endinput\else \input pstricks \fi
\ifx\PSTXKeyLoaded\endinput\else  \input pst-xkey \fi
\def\fileversion{0.21}
\def\filedate{2011/10/14}
\message{`PSTANAMORPHOSIS' v\fileversion, \filedate}

\pstheader{anamorphosis.pro}

\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
\SpecialCoor
\psset{dimen=middle}

\pst@addfams{pst-anamorphosis}

\define@key[psset]{pst-anamorphosis}{Rmirror}{\edef\psk@Anamorphose@Rmirror{#1 }}%
\psset[pst-anamorphosis]{Rmirror=3}
%
%% === Options spécifiques à l'anamorphose cylindrique -------------------------
\define@key[psset]{pst-anamorphosis}{Xv}{\edef\psk@Anamorphose@Xv{#1 }}%
\define@key[psset]{pst-anamorphosis}{Yv}{\edef\psk@Anamorphose@Yv{#1 }}%
\psset[pst-anamorphosis]{Xv=0,Yv=-10}
%
%% === Options spécifiques à l'anamorphose conique -----------------------------
\define@key[psset]{pst-anamorphosis}{Zs}{\edef\psk@Anamorphose@Zs{#1 }}%
\define@key[psset]{pst-anamorphosis}{Zv}{\edef\psk@Anamorphose@Zv{#1 }}%
\psset[pst-anamorphosis]{Zs=10,Zv=50}
%
%% === Options spécifiques à l'anamorphose spherique -----------------------------
\define@key[psset]{pst-anamorphosis}{Zv}{\edef\psk@Anamorphose@Zv{#1 }}%
\psset[pst-anamorphosis]{Zv=10}
%
%% === Options spécifiques à la perspective -----------------------------
\define@key[psset]{pst-anamorphosis}{ua}{\edef\psk@Anamorphose@ua{#1 }}%
\define@key[psset]{pst-anamorphosis}{F}{\edef\psk@Anamorphose@H{#1 }}%
\define@key[psset]{pst-anamorphosis}{D}{\edef\psk@Anamorphose@D{#1 }}%
\psset[pst-anamorphosis]{ua=2,F=10,D=4}
%
%% === Options scale pour placer une image EPS ---------------------
\define@key[psset]{pst-anamorphosis}{scale}{\edef\psk@Anamorphose@scale{#1 }}%
\psset[pst-anamorphosis]{scale=1 1}
%
%% === Options translate pour placer une image PST---------------------
\define@key[psset]{pst-anamorphosis}{translate}{\edef\psk@Anamorphose@translate{#1 }}%
\psset[pst-anamorphosis]{translate=0 0}
%
%% === Option pour ne pas dessiner l'image anamorphosée---------------------
\newif\ifPst@Anamorphose@draw
\define@key[psset]{pst-anamorphosis}{drawanamorphosis}[true]{\@nameuse{Pst@Anamorphose@draw#1}}
\psset[pst-anamorphosis]{drawanamorphosis=true}
%
%% === Chemin pour les dessins ---------------------------------------------
\define@key[psset]{pst-anamorphosis}{path}{\edef\psk@Anamorphose@Path{#1}} % chemin des dessins
\psset{path=}

%% Reservation des noms de macros
% adaptation de la macro de pst-solides3d
% #1=type de reservation associee a une liste qui
% doit forcement etre du type pst@anamorphosis@list@#1
\def\pst@anamorphosis@reservednames#1{%
\edef\@tempa{\csname pst@anamorphosis@list@#1\endcsname}
\@for \name:=\@tempa\do{%
  \expandafter\def\csname pst@anamorphosis@#1@\name\endcsname{}%
}}
% nature de l'anamorphose
\def\pst@anamorphosis@list@type{%
  cylindrical,conical,spherical,perspective,inverseperspective}
%
%% Reservation de macros correspondants aux types
\pst@anamorphosis@reservednames{type}
\define@key[psset]{pst-anamorphosis}{type}{%
 \ifcsname pst@anamorphosis@type@#1\endcsname
   \def\psk@anamorphosis@type{pst-#1}%
 \else
    \@pstrickserr{The anamorphosis #1 is not defined, the anamorphosis by default is
    drawn}{}%
 \fi}
% anamorphose par defaut
\psset[pst-anamorphosis]{type=cylindrical}%
%
\pst@def{optionsanamorphosis}<%
/unit {\pst@number\psunit mul } def
/Xv \psk@Anamorphose@Xv unit def
/Yv \psk@Anamorphose@Yv unit def
/Zv \psk@Anamorphose@Zv unit def
/Zs \psk@Anamorphose@Zs unit def
/Rmirror \psk@Anamorphose@Rmirror unit def
/R Rmirror dup mul def
/ua \psk@Anamorphose@ua unit def
/yH \psk@Anamorphose@H unit def
/xD \psk@Anamorphose@D unit def
/Anamorphose  {\psk@anamorphosis@type} def
\psk@Anamorphose@scale
% pour tenir d'un changement d'échelle global
 /s@@y exch \pst@number\psyunit mul 28.45274 div def
 /s@@x exch \pst@number\psxunit mul 28.45274 div def
>

\def\psanamorphosis{\def\pst@par{}\pst@object{psanamorphosis}}
\def\psanamorphosis@i{\@ifnextchar({\psanamorphosis@do}{\psanamorphosis@do(0,0)}}
\def\psanamorphosis@do(#1)#2{%  #1 = fichier.eps à transformer
\begingroup%
\use@par%
  \begin@SpecialObj%
  \pst@@getcoor{#1}%
    \addto@pscode{
      \pst@coor /t@@y ED /t@@x ED % Translate
      /fichier (\psk@Anamorphose@Path#2) def
    \tx@optionsanamorphosis
     Image
\ifPst@Anamorphose@draw
   tx@anamorphosisPathDict begin
      gsave
      /showpage {} def
       fichier run
      grestore
    end
\fi
    }%
  \end@SpecialObj%
\endgroup%
} 