%%
%% This is file `reflectgraphics.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% reflectgraphics.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2013 by Oliver Reiche <oliver.reiche@gmail.com>
%% --------------------------------------------------------------------------
%% 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 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{reflectgraphics}
    [2013/11/17 v0.2 Fancy reflections for LaTeX graphics]
\RequirePackage{kvoptions, keyval, graphicx, calc, tikz}
\usetikzlibrary{fadings}
\makeatletter
\newif\ifrg@debug
\newlength\rg@width
\newlength\rg@height
\newlength\rg@distance
\def\rg@scale{}
\def\rg@angle{}
\def\rg@length{}
\def\rg@opacity{}
\newlength\rg@triml
\newlength\rg@trimb
\newlength\rg@trimr
\newlength\rg@trimt
\newdimen\rg@unit \rg@unit=1bp%
\newdimen\rg@trim@dim%
\def\rg@convtodim#1#2{%
  \let\rg@unit@cur\rg@unit%
  \def\rg@unit@off{\let\rg@unit@cur\relax}%
  \afterassignment\rg@unit@off%
  \rg@trim@dim#2\rg@unit@cur%
  \setlength#1{\the\rg@trim@dim}%
}
\def\rg@trim@parse#1 #2 #3 #4 #5\\{%
  \rg@convtodim{\rg@triml}{#1}%
  \rg@convtodim{\rg@trimb}{#2}%
  \rg@convtodim{\rg@trimr}{#3}%
  \rg@convtodim{\rg@trimt}{#4}%
}
\def\rg@checkval#1#2#3#4{%
  \ifdim#1pt<#3pt%
    \PackageError{reflectgraphics}{%
      The specified #2 value '#1' is less than #3%
    }{%
      Specify the #2 value within the interval [#3,#4].%
    }%
  \else\ifdim#1pt>#4pt%
    \PackageError{reflectgraphics}{%
      The specified #2 value '#1' is greater than #4%
    }{%
      Specify the #2 value within the interval [#3,#4].%
    }%
  \fi\fi%
}
\define@key{reflectgraphics}{debug}[true]{%
  \csname rg@debug\ifx\relax#1\relax true\else#1\fi\endcsname}
\define@key{reflectgraphics}{width}{%
  \setlength\rg@width{#1}}
\define@key{reflectgraphics}{height}{%
  \setlength\rg@height{#1}}
\define@key{reflectgraphics}{scale}{%
  \def\rg@scale{#1}}
\define@key{reflectgraphics}{angle}{%
  \def\rg@angle{#1}}
\define@key{reflectgraphics}{trim}{%
  \rg@trim@parse#1 \\}
\define@key{reflectgraphics}{clip}[true]{}
\define@key{reflectgraphics}{distance}{%
  \setlength\rg@distance{#1}}
\define@key{reflectgraphics}{length}{%
  \rg@checkval{#1}{length}{0}{1}%
  \def\rg@length{#1}}
\define@key{reflectgraphics}{opacity}{%
  \rg@checkval{#1}{opacity}{0}{1}%
  \def\rg@opacity{#1}}
\setkeys{reflectgraphics}{%
  debug=false,%
  width=0pt,%
  height=0pt,%
  scale=1.0,%
  angle=0,%
  trim=0 0 0 0,%
  distance=3pt,%
  length=0.5,%
  opacity=0.5%
}
\ProcessKeyvalOptions*
\newlength{\rg@grp@width}
\newlength{\rg@grp@height}
\newlength{\rg@ref@height}
\newlength{\rg@clp@height}
\newlength{\rg@grp@offset}
\newlength{\rg@ref@offset}
\newcommand{\reflectgraphics}[2][]{%
  \begingroup%
  \setkeys{reflectgraphics}{#1}%
  \ifdim\rg@width=0pt\ifdim\rg@height=0pt
    \settowidth{\rg@width}{%
      \includegraphics[%
        draft,%
        scale=\rg@scale,%
        trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt}]{#2}}%
    \settoheight{\rg@height}{%
      \includegraphics[%
        draft,%
        scale=\rg@scale,%
        trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt}]{#2}}%
  \else% if width=0 && height!=0
    \settowidth{\rg@width}{%
      \includegraphics[%
        draft,%
        height=\rg@height,%
        trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt}]{#2}}%
  \fi\else\ifdim\rg@height=0pt% && width!=0
    \settoheight{\rg@height}{%
      \includegraphics[%
        draft,%
        width=\rg@width,%
        trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt}]{#2}}%
  \fi\fi%
  \ifdim\rg@angle pt=0pt%
    \setlength{\rg@grp@width}{\rg@width}%
    \setlength{\rg@grp@height}{\rg@height}%
  \else%
    \settowidth{\rg@grp@width}{%
      \includegraphics[%
        draft,%
        width=\rg@width,%
        height=\rg@height,%
        angle=\rg@angle]{#2}}%
    \settoheight{\rg@grp@height}{%
      \includegraphics[%
        draft,%
        width=\rg@width,%
        height=\rg@height,%
        angle=\rg@angle]{#2}}%
  \fi%
  \setlength{\rg@ref@height}{%
    \rg@length\rg@grp@height}%
  \setlength{\rg@ref@offset}{%
    0.5\rg@grp@height-0.5\rg@ref@height}%
  \setlength{\rg@grp@offset}{%
    0.5\rg@ref@height+\rg@distance+0.5\rg@grp@height}%
  \setlength{\rg@clp@height}{%
    \rg@grp@height+\rg@distance+\rg@ref@height}%
  \ifdefined\tikzexternaldisable%
    \tikzexternaldisable%
  \fi%
  \begin{tikzfadingfrompicture}[name=fade south]%
    \shade[top color=transparent!0, bottom color=transparent!100]%
      (0,0) rectangle (\rg@grp@width,\rg@ref@height);%
  \end{tikzfadingfrompicture}%
  \begin{tikzpicture}%
    \ifrg@debug%
      \def\rg@padding{0.25\rg@grp@height}%
      \draw[help lines]%
        (-0.5\rg@grp@width-\rg@padding,%
          -0.5\rg@ref@height-\rg@distance-\rg@grp@height-\rg@padding)%
        grid (0.5\rg@grp@width+\rg@padding,%
          0.5\rg@ref@height+\rg@distance+\rg@grp@height+\rg@padding);%
    \fi%
    \clip {(-0.5\rg@grp@width,\rg@clp@height-0.5\rg@ref@height)%
      rectangle ++(\rg@grp@width,-\rg@clp@height)};%
    \node at (0,\rg@grp@offset) {%
      \includegraphics[%
        width=\rg@width,%
        height=\rg@height,%
        angle=\rg@angle,%
        trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt},%
        clip]{#2}%
    };%
    \node at (0,-\rg@ref@offset) [%
      opacity=\rg@opacity,%
      scope fading=fade south,%
      fit fading=false%
    ] {%
      \scalebox{1}[-1]{%
        \includegraphics[%
          width=\rg@width,%
          height=\rg@height,%
          angle=\rg@angle,%
          trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt},%
          clip]{#2}%
      }%
    };%
  \end{tikzpicture}%
  \endgroup%
}
\makeatother

\endinput
%%
%% End of file `reflectgraphics.sty'.
