| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2015 by Oliver Reiche <[email protected]> |
| 4 |
% --------------------------------------------------------------------------- |
| 5 |
% This work may be distributed and/or modified under the |
| 6 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 7 |
% of this license or (at your option) any later version. |
| 8 |
% The latest version of this license is in |
| 9 |
% http://www.latex-project.org/lppl.txt |
| 10 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 11 |
% version 2005/12/01 or later. |
| 12 |
% |
| 13 |
% This work has the LPPL maintenance status `maintained'. |
| 14 |
% |
| 15 |
% The Current Maintainer of this work is Oliver Reiche. |
| 16 |
% |
| 17 |
% This work consists of the files reflectgraphics.dtx and reflectgraphics.ins |
| 18 |
% and the derived filebase reflectgraphics.sty. |
| 19 |
% |
| 20 |
% \fi |
| 21 |
% |
| 22 |
% \iffalse |
| 23 |
%<*driver> |
| 24 |
\ProvidesFile{reflectgraphics.dtx} |
| 25 |
%</driver> |
| 26 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 27 |
%<package>\ProvidesPackage{reflectgraphics} |
| 28 |
%<*package> |
| 29 |
[2015/07/07 v0.2c Fancy reflections for LaTeX graphics] |
| 30 |
%</package> |
| 31 |
% |
| 32 |
%<*driver> |
| 33 |
\IfFileExists{example.jpg}{% |
| 34 |
\documentclass{ltxdoc} |
| 35 |
}{% |
| 36 |
\documentclass[draft]{ltxdoc} |
| 37 |
\overfullrule=0pt |
| 38 |
}% |
| 39 |
\usepackage{xdoc2} |
| 40 |
\usepackage{reflectgraphics}[2015/07/07] |
| 41 |
\usepackage{microtype} |
| 42 |
\usepackage[defaultlines=2,all]{nowidow} |
| 43 |
\usepackage{titlesec} |
| 44 |
\usepackage{needspace} |
| 45 |
|
| 46 |
\titleformat{\section}{% |
| 47 |
\needspace{0.1\textheight}\Large\bfseries}{\thesection}{1em}{} |
| 48 |
\titleformat{\subsection}{% |
| 49 |
\needspace{0.1\textheight}\large\bfseries}{\thesubsection}{1em}{} |
| 50 |
|
| 51 |
\DeclareRobustCommand\package[1]{\textsf{#1}} |
| 52 |
\DeclareRobustCommand\option[1]{\texttt{#1}} |
| 53 |
\newenvironment{key}[2]{% |
| 54 |
\noindent% |
| 55 |
\leavevmode% |
| 56 |
\GenericDescribePrint{\MacroFont#2 \normalfont key}% |
| 57 |
\ignorespaces% |
| 58 |
}{}% |
| 59 |
|
| 60 |
\EnableCrossrefs |
| 61 |
\RecordChanges |
| 62 |
\begin{document} |
| 63 |
\DocInput{reflectgraphics.dtx} |
| 64 |
\PrintChanges |
| 65 |
\end{document} |
| 66 |
%</driver> |
| 67 |
% \fi |
| 68 |
% |
| 69 |
% \CheckSum{309} |
| 70 |
% |
| 71 |
% \CharacterTable |
| 72 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 73 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 74 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 75 |
% Exclamation \! Double quote \" Hash (number) \# |
| 76 |
% Dollar \$ Percent \% Ampersand \& |
| 77 |
% Acute accent \' Left paren \( Right paren \) |
| 78 |
% Asterisk \* Plus \+ Comma \, |
| 79 |
% Minus \- Point \. Solidus \/ |
| 80 |
% Colon \: Semicolon \; Less than \< |
| 81 |
% Equals \= Greater than \> Question mark \? |
| 82 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 83 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 84 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 85 |
% Right brace \} Tilde \~} |
| 86 |
% |
| 87 |
% |
| 88 |
% \changes{v0.1}{2013/10/28}{Initial version} |
| 89 |
% \changes{v0.2}{2013/10/31}{Support for options 'scale' and 'angle'} |
| 90 |
% \changes{v0.2b}{2013/11/25}{Fixed 'angle' for values <0 and >90} |
| 91 |
% \changes{v0.2c}{2015/07/07}{Replaced non-free Lenna image} |
| 92 |
% |
| 93 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 94 |
% |
| 95 |
% \providecommand*{\url}{\texttt} |
| 96 |
% \GetFileInfo{reflectgraphics.dtx} |
| 97 |
% \title{The \textsf{reflectgraphics} package} |
| 98 |
% \author{Oliver Reiche \\ \url{[email protected]}} |
| 99 |
% \date{\fileversion~from \filedate} |
| 100 |
% |
| 101 |
% \maketitle |
| 102 |
% |
| 103 |
% \begin{abstract} |
| 104 |
% This small package provides a new macro, which adds fancy reflections at |
| 105 |
% the bottom of graphics. To keep things simple, this new macro can be used |
| 106 |
% in a similar way to the |\includegraphics| macro of the \package{graphicx} |
| 107 |
% package. |
| 108 |
% \end{abstract} |
| 109 |
% |
| 110 |
% \section{Introduction} |
| 111 |
% \label{sec:introduction} |
| 112 |
% Having a fading reflection or mirroring effect at the bottom of graphics can |
| 113 |
% dramatically increase the fancyness of documents and in particular of |
| 114 |
% presentations. Such an effect can be achieved by creating the reflection |
| 115 |
% beforehand with an image editing software or by using the \package{tikz} |
| 116 |
% package. Using Ti\textit{k}Z can be very tricky and many users might not be |
| 117 |
% familiar with describing graphics by writing code. In particular when |
| 118 |
% applying image manipulation operations (like scaling, rotating, trimming) on |
| 119 |
% graphics, handling Ti\textit{k}Z code and positioning nodes correctly can be |
| 120 |
% challenging. |
| 121 |
% |
| 122 |
% To remove this obstacle for inexperienced users and allow them to easily |
| 123 |
% include graphics with fancy reflections, this package offers a simple |
| 124 |
% alternative. By just specifying a graphics file, the macros provided by this |
| 125 |
% package will render it and its reflection automatically. |
| 126 |
% |
| 127 |
% \section{Usage} |
| 128 |
% \label{sec:usage} |
| 129 |
% No big surprise, the package is loaded using: |
| 130 |
% \begin{quote} |
| 131 |
% |\usepackage|\oarg{options}|{reflectgraphics}| |
| 132 |
% \end{quote} |
| 133 |
% The options specified as \meta{options} are globally set for the whole |
| 134 |
% document and can be obliterated by locally defined options. A description of |
| 135 |
% valid options can be found in subsection~\ref{sec:options}. |
| 136 |
% |
| 137 |
% \subsection{Macros} |
| 138 |
% \label{sec:macros} |
| 139 |
% The only new macro provided by this package is: |
| 140 |
% \begin{quote} |
| 141 |
% \DescribeMacro{\reflectgraphics}|\reflectgraphics|\oarg{options}\marg{path} |
| 142 |
% \end{quote} |
| 143 |
% It can be used to render graphics together with their reflections at the |
| 144 |
% bottom, which are fading from a particular starting opacity to fully |
| 145 |
% transparent. The dimensions of a graphic and the properties of its reflection |
| 146 |
% can be defined by \meta{options} (see subsection~\ref{sec:options}). |
| 147 |
% |
| 148 |
% The mandatory argument \meta{path} must contain a valid path to a graphics |
| 149 |
% file of a supported file type. This package internally uses |
| 150 |
% |\includegraphics|. Therefore, basically every graphics type that is |
| 151 |
% supported by |\includegraphics| is also supported by this package. The file |
| 152 |
% extension may be omitted in \meta{path}. To see some examples have a look at |
| 153 |
% subsection~\ref{sec:examples}. |
| 154 |
% |
| 155 |
% \subsection{Options} |
| 156 |
% \label{sec:options} |
| 157 |
% Options can be specified globally with the |\usepackage| statement or locally |
| 158 |
% for each |\reflectgraphics| statement. Local options override values of |
| 159 |
% global options. There are two types of options: the ones that affect graphics |
| 160 |
% and the ones that affect only the rendering of reflections. |
| 161 |
% |
| 162 |
% \paragraph{graphics} The following options describe the properties of |
| 163 |
% graphics. |
| 164 |
% |
| 165 |
% To set the dimensions of the graphic to render, the options |
| 166 |
% \describeoption{width}\option{width}=\meta{dim} and |
| 167 |
% \describeoption{height}\option{height}=\meta{dim} can be specified. If only |
| 168 |
% one of these options is specified, the original aspect ratio will be left |
| 169 |
% untouched. Values passed to these options must be typical \TeX{} dimensions |
| 170 |
% with units like \texttt{cm}, \texttt{em}, \texttt{pt}, and so on. |
| 171 |
% |
| 172 |
% Instead of a manually defining graphics dimensions, the option |
| 173 |
% \describeoption{scale}\option{scale}=\meta{float} can be set as well. Hereby |
| 174 |
% the original aspect ratio and size will be chosen scaled by the provided |
| 175 |
% floating point value. Valid values are all values that are greater than $0$. |
| 176 |
% If either \option{width} or \option{height} is specified, the \option{scale} |
| 177 |
% option will be ignored. |
| 178 |
% |
| 179 |
% The graphics and corresponding reflections can be rotated by specifying the |
| 180 |
% option \describeoption{angle}\option{angle}=\meta{float}. This floating point |
| 181 |
% value describes the rotation angle in degrees. Valid angle values can be |
| 182 |
% positive as well as negative. |
| 183 |
% |
| 184 |
% Similar to |\includegraphics| trimming and clipping can be applied to render |
| 185 |
% only subregions of graphics. This can be done by defining the option |
| 186 |
% \describeoption{trim}\option{trim}=\meta{dim}\ \meta{dim}\ \meta{dim}\ |
| 187 |
% \meta{dim}. The option takes four dimension arguments that define the trimming |
| 188 |
% in the following order: \emph{left bottom right top}. If the dimension unit |
| 189 |
% is omitted than \texttt{bp} is used by default, which is similar to |
| 190 |
% |\includegraphics|. Unlike |\includegraphics| the \option{clip} option does |
| 191 |
% not have to be specified. |
| 192 |
% |
| 193 |
% \paragraph{reflections} The following options describe the properties of |
| 194 |
% graphics reflections. |
| 195 |
% |
| 196 |
% The distance between the actual graphic and its reflection can be defined by |
| 197 |
% setting the option \describeoption{distance}\option{distance}=\meta{dim}. If |
| 198 |
% it is not set, a default value of $3.0$\,\texttt{pt} will be used. The |
| 199 |
% specified value must be a \TeX{} dimension. |
| 200 |
% |
| 201 |
% To set the size of the graphics reflection, specify the option |
| 202 |
% \describeoption{length}\option{length}=\meta{float}. This option defines a |
| 203 |
% percentage value, which represents the length (i.\,e.\ the height) of the |
| 204 |
% reflection with respect to the height of the corresponding graphic. Its value |
| 205 |
% is a floating point number and must lie within the interval $[0,1]$. The |
| 206 |
% default value is set to $0.5$, which results in a reflection height that is |
| 207 |
% equal to $50$\,\% of the graphics height. |
| 208 |
% |
| 209 |
% Changing the starting opacity for the fading of the reflection influences the |
| 210 |
% impression how \emph{strong} the reflection is. The opacity can be modified |
| 211 |
% by setting the \describeoption{opacity}\option{opacity}=\meta{float} option. |
| 212 |
% Its value is a floating point number within the interval $[0,1]$. The default |
| 213 |
% value is $0.5$, which equates to $50$\,\% opacity. |
| 214 |
% |
| 215 |
% \subsection{Examples} |
| 216 |
% \label{sec:examples} |
| 217 |
% The simplest way to use |\reflectgraphics| is to omit all optional arguments |
| 218 |
% and let the underlaying |\includegraphics| macro choose the dimensions of the |
| 219 |
% graphic:\\ |
| 220 |
% \begin{minipage}[t]{\textwidth} |
| 221 |
% \begin{verbatim} |
| 222 |
% \reflectgraphics{example.jpg} |
| 223 |
% \end{verbatim} |
| 224 |
% \end{minipage} |
| 225 |
% |
| 226 |
% To change the graphics size in a way whereat the aspect ratio should be kept |
| 227 |
% as it is, define either \option{width}, \option{height} or use the |
| 228 |
% \option{scale} option:\\ |
| 229 |
% \begin{minipage}[t]{\textwidth} |
| 230 |
% \begin{verbatim} |
| 231 |
% \reflectgraphics[width=4cm]{example.jpg} |
| 232 |
% \reflectgraphics[height=4cm]{example.jpg} |
| 233 |
% \reflectgraphics[scale=0.25]{example.jpg} |
| 234 |
% \end{verbatim} |
| 235 |
% \begin{center} |
| 236 |
% \reflectgraphics[width=4cm, height=4cm]{example.jpg} |
| 237 |
% \end{center} |
| 238 |
% \end{minipage}\bigskip |
| 239 |
% |
| 240 |
% If a specific aspect ratio should be forced, both dimensions have to be |
| 241 |
% specified explicitly:\\ |
| 242 |
% \begin{minipage}[t]{\textwidth} |
| 243 |
% \begin{verbatim} |
| 244 |
% \reflectgraphics[width=4cm, height=2cm]{example.jpg} |
| 245 |
% \end{verbatim} |
| 246 |
% \begin{center} |
| 247 |
% \reflectgraphics[width=4cm, height=2cm]{example.jpg} |
| 248 |
% \end{center} |
| 249 |
% \end{minipage}\bigskip |
| 250 |
% |
| 251 |
% Rotating graphics can be enabled by specifying the \option{angle} option. |
| 252 |
% Note that rotation will increase the rectangular space (bounding box) that is |
| 253 |
% taken by the graphic and its reflection. In particular the overall height can |
| 254 |
% expand drastically, because the increased height of both the graphic and the |
| 255 |
% reflection add up.\\ |
| 256 |
% \begin{minipage}[t]{\textwidth} |
| 257 |
% \begin{verbatim} |
| 258 |
% \reflectgraphics[width=1.5cm, angle=45]{example.jpg} |
| 259 |
% \end{verbatim} |
| 260 |
% \begin{center} |
| 261 |
% \reflectgraphics[width=1.5cm, height=1.5cm, angle=15]{example.jpg} |
| 262 |
% \reflectgraphics[width=1.5cm, height=1.5cm, angle=30]{example.jpg} |
| 263 |
% \reflectgraphics[width=1.5cm, height=1.5cm, angle=45]{example.jpg} |
| 264 |
% \reflectgraphics[width=1.5cm, height=1.5cm, angle=60]{example.jpg} |
| 265 |
% \reflectgraphics[width=1.5cm, height=1.5cm, angle=75]{example.jpg} |
| 266 |
% \end{center} |
| 267 |
% \end{minipage}\bigskip |
| 268 |
% |
| 269 |
% To trim and clip graphics together with the corresponding reflection (e.\,g.\ |
| 270 |
% to highlight the olives only), one can straightforward proceed the same way as |
| 271 |
% using |\includegraphics|, except that the \option{clip} option can be |
| 272 |
% omitted:\\ |
| 273 |
% \begin{minipage}[t]{\textwidth} |
| 274 |
% \begin{verbatim} |
| 275 |
% \reflectgraphics[trim=115 60 80 100]{example.jpg} |
| 276 |
% \end{verbatim} |
| 277 |
% \begin{center} |
| 278 |
% \reflectgraphics[width=1.55cm, height=2cm, trim=115 60 80 100]{example.jpg} |
| 279 |
% \end{center} |
| 280 |
% \end{minipage}\bigskip |
| 281 |
% |
| 282 |
% In order to get a stronger and more crisp reflection, the options |
| 283 |
% \option{opacity} and \option{length} can be set. For instance, to get a |
| 284 |
% stronger starting opacity of $75$\,\% and a much shorter reflection length of |
| 285 |
% only $20$\,\% of the graphics height, set the following values:\\ |
| 286 |
% \begin{minipage}[t]{\textwidth} |
| 287 |
% \begin{verbatim} |
| 288 |
% \reflectgraphics[opacity=0.75, length=0.2]{example.jpg} |
| 289 |
% \end{verbatim} |
| 290 |
% \begin{center} |
| 291 |
% \reflectgraphics[width=4cm, height=4cm, opacity=0.75, length=0.2]{example.jpg} |
| 292 |
% \end{center} |
| 293 |
% \end{minipage}\bigskip |
| 294 |
% |
| 295 |
% To automatically modify the distance between a graphic and its reflection |
| 296 |
% when dimensions change, the distance and the graphics height can be set in |
| 297 |
% relation to each other. The following code renders graphics with a height of |
| 298 |
% $4$\,\texttt{cm} and sets the distance of the reflection to $10$\,\% of the |
| 299 |
% graphics height ($0.4$\,\texttt{cm}$\null=0.1\cdot4$\,\texttt{cm}):\\ |
| 300 |
% \begin{minipage}[t]{\textwidth} |
| 301 |
% \begin{verbatim} |
| 302 |
% \newlength{\len} |
| 303 |
% \setlength{\len}{4cm} |
| 304 |
% \reflectgraphics[height=\len, distance=0.1\len]{example.jpg} |
| 305 |
% \end{verbatim} |
| 306 |
% \begin{center} |
| 307 |
% \reflectgraphics[width=4cm, height=4cm, distance=0.4cm]{example.jpg} |
| 308 |
% \end{center} |
| 309 |
% \end{minipage}\bigskip |
| 310 |
% |
| 311 |
% \StopEventually{} |
| 312 |
% |
| 313 |
% \section{Implementation} |
| 314 |
% |
| 315 |
% \iffalse |
| 316 |
%<*package> |
| 317 |
% \fi |
| 318 |
% |
| 319 |
% \begin{macrocode} |
| 320 |
\RequirePackage{kvoptions, keyval, graphicx, calc, tikz} |
| 321 |
\usetikzlibrary{fadings} |
| 322 |
\makeatletter |
| 323 |
% \end{macrocode} |
| 324 |
% Holds the debug condition provided by option \option{debug}. |
| 325 |
% \begin{macrocode} |
| 326 |
\newif\ifrg@debug |
| 327 |
% \end{macrocode} |
| 328 |
% Holds the width length provided by option \option{width}. |
| 329 |
% \begin{macrocode} |
| 330 |
\newlength\rg@width |
| 331 |
% \end{macrocode} |
| 332 |
% Holds the height length provided by option \option{height}. |
| 333 |
% \begin{macrocode} |
| 334 |
\newlength\rg@height |
| 335 |
% \end{macrocode} |
| 336 |
% Holds the distance length provided by option \option{distance}. |
| 337 |
% \begin{macrocode} |
| 338 |
\newlength\rg@distance |
| 339 |
% \end{macrocode} |
| 340 |
% |
| 341 |
% \begin{macro}{\rg@scale} |
| 342 |
% Holds the scale factor provided by option \option{scale}. |
| 343 |
% \begin{macrocode} |
| 344 |
\def\rg@scale{} |
| 345 |
% \end{macrocode} |
| 346 |
% \end{macro} |
| 347 |
% |
| 348 |
% |
| 349 |
% \begin{macro}{\rg@angle} |
| 350 |
% Holds the angle value provided by option \option{angle}. |
| 351 |
% \begin{macrocode} |
| 352 |
\def\rg@angle{} |
| 353 |
% \end{macrocode} |
| 354 |
% \end{macro} |
| 355 |
% |
| 356 |
% |
| 357 |
% \begin{macro}{\rg@length} |
| 358 |
% Holds the length factor for the reflection provided by option \option{length}. |
| 359 |
% \begin{macrocode} |
| 360 |
\def\rg@length{} |
| 361 |
% \end{macrocode} |
| 362 |
% \end{macro} |
| 363 |
% |
| 364 |
% |
| 365 |
% \begin{macro}{\rg@opacity} |
| 366 |
% Holds the opacity factor for starting the reflection provided by option |
| 367 |
% \option{opacity}. |
| 368 |
% \begin{macrocode} |
| 369 |
\def\rg@opacity{} |
| 370 |
% \end{macrocode} |
| 371 |
% \end{macro} |
| 372 |
% |
| 373 |
% \noindent Hold the trim lengths provided by option \option{trim}: |
| 374 |
% |
| 375 |
% Left trim length |
| 376 |
% \begin{macrocode} |
| 377 |
\newlength\rg@triml |
| 378 |
% \end{macrocode} |
| 379 |
% Bottom trim length |
| 380 |
% \begin{macrocode} |
| 381 |
\newlength\rg@trimb |
| 382 |
% \end{macrocode} |
| 383 |
% Right trim length |
| 384 |
% \begin{macrocode} |
| 385 |
\newlength\rg@trimr |
| 386 |
% \end{macrocode} |
| 387 |
% Top trim length |
| 388 |
% \begin{macrocode} |
| 389 |
\newlength\rg@trimt |
| 390 |
% \end{macrocode} |
| 391 |
% Dimension holding the default unit for converting dimensions. |
| 392 |
% \begin{macrocode} |
| 393 |
\newdimen\rg@unit \rg@unit=1bp% |
| 394 |
% \end{macrocode} |
| 395 |
% Dimension temporarily used for storing converted dimensions. |
| 396 |
% \begin{macrocode} |
| 397 |
\newdimen\rg@trim@dim% |
| 398 |
% \end{macrocode} |
| 399 |
% |
| 400 |
% \begin{macro}{\rg@convtodim} |
| 401 |
% Macro for converting an argument without unit to dimension with default unit. |
| 402 |
% \begin{macrocode} |
| 403 |
\def\rg@convtodim#1#2{% |
| 404 |
% \end{macrocode} |
| 405 |
% Set unit variable to default unit. |
| 406 |
% \begin{macrocode} |
| 407 |
\let\rg@unit@cur\rg@unit% |
| 408 |
% \end{macrocode} |
| 409 |
% Macro for clearing the unit variable. |
| 410 |
% \begin{macrocode} |
| 411 |
\def\rg@unit@off{\let\rg@unit@cur\relax}% |
| 412 |
% \end{macrocode} |
| 413 |
% Clear unit variable after next assignment. |
| 414 |
% \begin{macrocode} |
| 415 |
\afterassignment\rg@unit@off% |
| 416 |
% \end{macrocode} |
| 417 |
% Assign argument |#2| to dimension. |
| 418 |
% \begin{macrocode} |
| 419 |
\rg@trim@dim#2\rg@unit@cur% |
| 420 |
% \end{macrocode} |
| 421 |
% Copy resulting dimension to argument |#1|. |
| 422 |
% \begin{macrocode} |
| 423 |
\setlength#1{\the\rg@trim@dim}% |
| 424 |
} |
| 425 |
% \end{macrocode} |
| 426 |
% \end{macro} |
| 427 |
% |
| 428 |
% |
| 429 |
% \begin{macro}{\rg@trim@parse} |
| 430 |
% Macro for parsing trim values from single argument to |\rg@trim[lbrt]| and |
| 431 |
% convert to dimension if no unit is specified. |
| 432 |
% \begin{macrocode} |
| 433 |
\def\rg@trim@parse#1 #2 #3 #4 #5\\{% |
| 434 |
\rg@convtodim{\rg@triml}{#1}% |
| 435 |
\rg@convtodim{\rg@trimb}{#2}% |
| 436 |
\rg@convtodim{\rg@trimr}{#3}% |
| 437 |
\rg@convtodim{\rg@trimt}{#4}% |
| 438 |
} |
| 439 |
% \end{macrocode} |
| 440 |
% \end{macro} |
| 441 |
% |
| 442 |
% |
| 443 |
% \begin{macro}{\rg@checkval} |
| 444 |
% Macro for checking whether value is in range or not. |
| 445 |
% \begin{macrocode} |
| 446 |
\def\rg@checkval#1#2#3#4{% |
| 447 |
\ifdim#1pt<#3pt% |
| 448 |
\PackageError{reflectgraphics}{% |
| 449 |
The specified #2 value '#1' is less than #3% |
| 450 |
}{% |
| 451 |
Specify the #2 value within the interval [#3,#4].% |
| 452 |
}% |
| 453 |
\else\ifdim#1pt>#4pt% |
| 454 |
\PackageError{reflectgraphics}{% |
| 455 |
The specified #2 value '#1' is greater than #4% |
| 456 |
}{% |
| 457 |
Specify the #2 value within the interval [#3,#4].% |
| 458 |
}% |
| 459 |
\fi\fi% |
| 460 |
} |
| 461 |
% \end{macrocode} |
| 462 |
% \end{macro} |
| 463 |
% |
| 464 |
% |
| 465 |
% \begin{key}{reflectgraphics}{debug} |
| 466 |
% Sets debug condition. |
| 467 |
% \begin{macrocode} |
| 468 |
\define@key{reflectgraphics}{debug}[true]{% |
| 469 |
\csname rg@debug\ifx\relax#1\relax true\else#1\fi\endcsname} |
| 470 |
% \end{macrocode} |
| 471 |
% \end{key} |
| 472 |
% |
| 473 |
% |
| 474 |
% \begin{key}{reflectgraphics}{width} |
| 475 |
% Sets width length. |
| 476 |
% \begin{macrocode} |
| 477 |
\define@key{reflectgraphics}{width}{% |
| 478 |
\setlength\rg@width{#1}} |
| 479 |
% \end{macrocode} |
| 480 |
% \end{key} |
| 481 |
% |
| 482 |
% |
| 483 |
% \begin{key}{reflectgraphics}{height} |
| 484 |
% Sets height length. |
| 485 |
% \begin{macrocode} |
| 486 |
\define@key{reflectgraphics}{height}{% |
| 487 |
\setlength\rg@height{#1}} |
| 488 |
% \end{macrocode} |
| 489 |
% \end{key} |
| 490 |
% |
| 491 |
% |
| 492 |
% \begin{key}{reflectgraphics}{scale} |
| 493 |
% Sets scale factor. |
| 494 |
% \begin{macrocode} |
| 495 |
\define@key{reflectgraphics}{scale}{% |
| 496 |
\def\rg@scale{#1}} |
| 497 |
% \end{macrocode} |
| 498 |
% \end{key} |
| 499 |
% |
| 500 |
% |
| 501 |
% \begin{key}{reflectgraphics}{angle} |
| 502 |
% Sets angle factor. |
| 503 |
% \begin{macrocode} |
| 504 |
\define@key{reflectgraphics}{angle}{% |
| 505 |
\def\rg@angle{#1}} |
| 506 |
% \end{macrocode} |
| 507 |
% \end{key} |
| 508 |
% |
| 509 |
% |
| 510 |
% \begin{key}{reflectgraphics}{trim} |
| 511 |
% Sets trim lengths. |
| 512 |
% \begin{macrocode} |
| 513 |
\define@key{reflectgraphics}{trim}{% |
| 514 |
\rg@trim@parse#1 \\} |
| 515 |
% \end{macrocode} |
| 516 |
% \end{key} |
| 517 |
% |
| 518 |
% |
| 519 |
% \begin{key}{reflectgraphics}{clip} |
| 520 |
% Accept but ignore option \option{clip}. |
| 521 |
% \begin{macrocode} |
| 522 |
\define@key{reflectgraphics}{clip}[true]{} |
| 523 |
% \end{macrocode} |
| 524 |
% \end{key} |
| 525 |
% |
| 526 |
% |
| 527 |
% \begin{key}{reflectgraphics}{distance} |
| 528 |
% Sets reflection distance length. |
| 529 |
% \begin{macrocode} |
| 530 |
\define@key{reflectgraphics}{distance}{% |
| 531 |
\setlength\rg@distance{#1}} |
| 532 |
% \end{macrocode} |
| 533 |
% \end{key} |
| 534 |
% |
| 535 |
% |
| 536 |
% \begin{key}{reflectgraphics}{length} |
| 537 |
% Sets reflection length factor after checking that value is in range. |
| 538 |
% \begin{macrocode} |
| 539 |
\define@key{reflectgraphics}{length}{% |
| 540 |
\rg@checkval{#1}{length}{0}{1}% |
| 541 |
\def\rg@length{#1}} |
| 542 |
% \end{macrocode} |
| 543 |
% \end{key} |
| 544 |
% |
| 545 |
% |
| 546 |
% \begin{key}{reflectgraphics}{opacity} |
| 547 |
% Sets reflection starting opacity after checking that value is in range. |
| 548 |
% \begin{macrocode} |
| 549 |
\define@key{reflectgraphics}{opacity}{% |
| 550 |
\rg@checkval{#1}{opacity}{0}{1}% |
| 551 |
\def\rg@opacity{#1}} |
| 552 |
% \end{macrocode} |
| 553 |
% \noindent Set default values. |
| 554 |
% \begin{macrocode} |
| 555 |
\setkeys{reflectgraphics}{% |
| 556 |
debug=false,% |
| 557 |
width=0pt,% |
| 558 |
height=0pt,% |
| 559 |
scale=1.0,% |
| 560 |
angle=0,% |
| 561 |
trim=0 0 0 0,% |
| 562 |
distance=3pt,% |
| 563 |
length=0.5,% |
| 564 |
opacity=0.5% |
| 565 |
} |
| 566 |
% \end{macrocode} |
| 567 |
% \end{key} |
| 568 |
% |
| 569 |
% Process package options by defined keys. |
| 570 |
% \begin{macrocode} |
| 571 |
\ProcessKeyvalOptions* |
| 572 |
% \end{macrocode} |
| 573 |
% Holds width of the graphic including extra space when rotated. |
| 574 |
% \begin{macrocode} |
| 575 |
\newlength{\rg@grp@width} |
| 576 |
% \end{macrocode} |
| 577 |
% Holds height of the graphic including extra space when rotated. |
| 578 |
% \begin{macrocode} |
| 579 |
\newlength{\rg@grp@height} |
| 580 |
% \end{macrocode} |
| 581 |
% Holds height of the reflection including extra space when rotated. |
| 582 |
% \begin{macrocode} |
| 583 |
\newlength{\rg@ref@height} |
| 584 |
% \end{macrocode} |
| 585 |
% Holds overall height, which is used for clipping. |
| 586 |
% \begin{macrocode} |
| 587 |
\newlength{\rg@clp@height} |
| 588 |
% \end{macrocode} |
| 589 |
% Hold $y$ offset of graphics node, which is used for positioning. |
| 590 |
% \begin{macrocode} |
| 591 |
\newlength{\rg@grp@offset} |
| 592 |
% \end{macrocode} |
| 593 |
% Hold $y$ offset of reflections node, which is used for positioning. |
| 594 |
% \begin{macrocode} |
| 595 |
\newlength{\rg@ref@offset} |
| 596 |
% \end{macrocode} |
| 597 |
% |
| 598 |
% \begin{macro}{\reflectgraphics} |
| 599 |
% This is the actual macro doing all the work. |
| 600 |
% \begin{macrocode} |
| 601 |
\newcommand{\reflectgraphics}[2][]{% |
| 602 |
% \end{macrocode} |
| 603 |
% Open new group so global options will not be overridden. |
| 604 |
% \begin{macrocode} |
| 605 |
\begingroup% |
| 606 |
% \end{macrocode} |
| 607 |
% Load local options from first argument. |
| 608 |
% \begin{macrocode} |
| 609 |
\setkeys{reflectgraphics}{#1}% |
| 610 |
% \end{macrocode} |
| 611 |
% Determine graphics dimensions. Use |\includegraphics| in \option{draft} mode |
| 612 |
% to do that. If both the \option{width} and \option{height} options are |
| 613 |
% specified, there is nothing that needs to be done here. |
| 614 |
% \begin{macrocode} |
| 615 |
\ifdim\rg@width=0pt\ifdim\rg@height=0pt |
| 616 |
\settowidth{\rg@width}{% |
| 617 |
\includegraphics[% |
| 618 |
draft,% |
| 619 |
scale=\rg@scale,% |
| 620 |
trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt}]{#2}}% |
| 621 |
\settoheight{\rg@height}{% |
| 622 |
\includegraphics[% |
| 623 |
draft,% |
| 624 |
scale=\rg@scale,% |
| 625 |
trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt}]{#2}}% |
| 626 |
\else% if width=0 && height!=0 |
| 627 |
\settowidth{\rg@width}{% |
| 628 |
\includegraphics[% |
| 629 |
draft,% |
| 630 |
height=\rg@height,% |
| 631 |
trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt}]{#2}}% |
| 632 |
\fi\else\ifdim\rg@height=0pt% && width!=0 |
| 633 |
\settoheight{\rg@height}{% |
| 634 |
\includegraphics[% |
| 635 |
draft,% |
| 636 |
width=\rg@width,% |
| 637 |
trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt}]{#2}}% |
| 638 |
\fi\fi% |
| 639 |
% \end{macrocode} |
| 640 |
% Determine dimensions of the graphics bounding box if rotation is enabled. |
| 641 |
% Again, |\includegraphics| in \option{draft} mode could be used to calculate |
| 642 |
% the boundary size, but calling |\heightof| results in strange values for |
| 643 |
% $\textrm{\option{angle}}<0$ and $\textrm{\option{angle}}>90$. Therefore, |
| 644 |
% computing the boundary size is done manually using \package{pgfmath}, which |
| 645 |
% turns out to be a little bit slower. |
| 646 |
% \begin{macrocode} |
| 647 |
\ifdim\rg@angle pt=0pt% |
| 648 |
\setlength{\rg@grp@width}{\rg@width}% |
| 649 |
\setlength{\rg@grp@height}{\rg@height}% |
| 650 |
\else% |
| 651 |
% \end{macrocode} |
| 652 |
% This is totally strange: A simple division gets completely messed up if |
| 653 |
% dividing a length by a larger length. So I need to take care to divide |
| 654 |
% lengths only by smaller ones. |
| 655 |
% \begin{macrocode} |
| 656 |
\ifdim\rg@height>\rg@width% |
| 657 |
\pgfmathsetmacro{\rg@alpha}{atan(\rg@height/\rg@width)}% |
| 658 |
\else% |
| 659 |
\pgfmathsetmacro{\rg@alpha}{atan(1/(\rg@width/\rg@height)}% |
| 660 |
\fi% |
| 661 |
\pgfmathsetmacro{\rg@corner}{abs(cos(\rg@alpha))}% |
| 662 |
\pgfmathsetmacro{\rg@cornera}{abs(cos(\rg@alpha+\rg@angle))}% |
| 663 |
\pgfmathsetmacro{\rg@cornerb}{abs(cos(180-\rg@alpha+\rg@angle))}% |
| 664 |
\pgfmathsetmacro{\rg@scale@x}{% |
| 665 |
max(\rg@cornera/\rg@corner,\rg@cornerb/\rg@corner)}% |
| 666 |
\pgfmathsetmacro{\rg@corner}{abs(sin(\rg@alpha))}% |
| 667 |
\pgfmathsetmacro{\rg@cornera}{abs(sin(\rg@alpha+\rg@angle))}% |
| 668 |
\pgfmathsetmacro{\rg@cornerb}{abs(sin(180-\rg@alpha+\rg@angle))}% |
| 669 |
\pgfmathsetmacro{\rg@scale@y}{% |
| 670 |
max(\rg@cornera/\rg@corner,\rg@cornerb/\rg@corner)}% |
| 671 |
\setlength{\rg@grp@width}{\rg@scale@x\rg@width}% |
| 672 |
\setlength{\rg@grp@height}{\rg@scale@y\rg@height}% |
| 673 |
\fi% |
| 674 |
% \end{macrocode} |
| 675 |
% Compute height of reflection. |
| 676 |
% \begin{macrocode} |
| 677 |
\setlength{\rg@ref@height}{% |
| 678 |
\rg@length\rg@grp@height}% |
| 679 |
% \end{macrocode} |
| 680 |
% Compute $y$ offset of the reflection that is used for node positioning. The |
| 681 |
% center of the reflection node is moved to the origin of the coordinate |
| 682 |
% system. This is done, because it seems that fading with a specific size can |
| 683 |
% only be applied in a reasonable way at the origin (with option \option{fit |
| 684 |
% fading} set to \emph{false}). |
| 685 |
% \begin{macrocode} |
| 686 |
\setlength{\rg@ref@offset}{% |
| 687 |
0.5\rg@[email protected]\rg@ref@height}% |
| 688 |
% \end{macrocode} |
| 689 |
% Compute $y$ offset of the graphics node. |
| 690 |
% \begin{macrocode} |
| 691 |
\setlength{\rg@grp@offset}{% |
| 692 |
0.5\rg@ref@height+\rg@distance+0.5\rg@grp@height}% |
| 693 |
% \end{macrocode} |
| 694 |
% Compute overall height, which is used for clipping. |
| 695 |
% \begin{macrocode} |
| 696 |
\setlength{\rg@clp@height}{% |
| 697 |
\rg@grp@height+\rg@distance+\rg@ref@height}% |
| 698 |
% \end{macrocode} |
| 699 |
% The following |\tikzfadingfrompicture| macro does not work with |
| 700 |
% Ti\textit{k}Z externalize. Therefore, if the Ti\textit{k}Z library |
| 701 |
% \package{external} is loaded it must be disabled for the whole rendering. |
| 702 |
% \begin{macrocode} |
| 703 |
\ifdefined\tikzexternaldisable% |
| 704 |
\tikzexternaldisable% |
| 705 |
\fi% |
| 706 |
% \end{macrocode} |
| 707 |
% Define custom fading \option{fade south}, which starts at $0$\,\% |
| 708 |
% transparency and ends at $100$\,\%. The height of this fading equates to the |
| 709 |
% height of the reflection. |\tikzfadingfrompicture| is used instead of |
| 710 |
% |\tikzfading| because of its possibility to define shades with specific |
| 711 |
% sizes. By doing so, this fading is not stretched across the whole node and |
| 712 |
% therefore it can be used to hide a specific part of the reflection node. |
| 713 |
% \begin{macrocode} |
| 714 |
\begin{tikzfadingfrompicture}[name=fade south]% |
| 715 |
\shade[top color=transparent!0, bottom color=transparent!100]% |
| 716 |
(0,0) rectangle (\rg@grp@width,\rg@ref@height);% |
| 717 |
\end{tikzfadingfrompicture}% |
| 718 |
% \end{macrocode} |
| 719 |
% Start the actual rendering. |
| 720 |
% \begin{macrocode} |
| 721 |
\begin{tikzpicture}% |
| 722 |
% \end{macrocode} |
| 723 |
% Draw help lines if \option{debug} option is specified. |
| 724 |
% \begin{macrocode} |
| 725 |
\ifrg@debug% |
| 726 |
\def\rg@padding{0.25\rg@grp@height}% |
| 727 |
\draw[help lines]% |
| 728 |
(-0.5\rg@grp@width-\rg@padding,% |
| 729 |
-0.5\rg@ref@height-\rg@distance-\rg@grp@height-\rg@padding)% |
| 730 |
grid (0.5\rg@grp@width+\rg@padding,% |
| 731 |
0.5\rg@ref@height+\rg@distance+\rg@grp@height+\rg@padding);% |
| 732 |
\fi% |
| 733 |
% \end{macrocode} |
| 734 |
% Clip the following nodes to graphics width |\rg@grp@width| and clipping |
| 735 |
% height |\rg@clp@height|. This is necessary to get rid of the remaining |
| 736 |
% transparent part of the reflection node, which still consumes much space, |
| 737 |
% even though nothing is visible. |
| 738 |
% \begin{macrocode} |
| 739 |
\clip {(-0.5\rg@grp@width,\rg@[email protected]\rg@ref@height)% |
| 740 |
rectangle ++(\rg@grp@width,-\rg@clp@height)};% |
| 741 |
% \end{macrocode} |
| 742 |
% Draw the graphics node. |
| 743 |
% \begin{macrocode} |
| 744 |
\node at (0,\rg@grp@offset) {% |
| 745 |
% \end{macrocode} |
| 746 |
% Draw graphics using |\includegraphics|. |
| 747 |
% \begin{macrocode} |
| 748 |
\includegraphics[% |
| 749 |
width=\rg@width,% |
| 750 |
height=\rg@height,% |
| 751 |
angle=\rg@angle,% |
| 752 |
trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt},% |
| 753 |
clip]{#2}% |
| 754 |
};% |
| 755 |
% \end{macrocode} |
| 756 |
% Draw the reflection node with previously defined custom fading |
| 757 |
% \option{fade south} and with the opacity value specified by option |
| 758 |
% \option{opacity}. |
| 759 |
% \begin{macrocode} |
| 760 |
\node at (0,-\rg@ref@offset) [% |
| 761 |
opacity=\rg@opacity,% |
| 762 |
scope fading=fade south,% |
| 763 |
fit fading=false% |
| 764 |
] {% |
| 765 |
% \end{macrocode} |
| 766 |
% Flip reflection node content vertically. |
| 767 |
% \begin{macrocode} |
| 768 |
\scalebox{1}[-1]{% |
| 769 |
% \end{macrocode} |
| 770 |
% Draw graphics using |\includegraphics|. |
| 771 |
% \begin{macrocode} |
| 772 |
\includegraphics[% |
| 773 |
width=\rg@width,% |
| 774 |
height=\rg@height,% |
| 775 |
angle=\rg@angle,% |
| 776 |
trim={\rg@triml} {\rg@trimb} {\rg@trimr} {\rg@trimt},% |
| 777 |
clip]{#2}% |
| 778 |
}% |
| 779 |
};% |
| 780 |
\end{tikzpicture}% |
| 781 |
% \end{macrocode} |
| 782 |
% Close group. |
| 783 |
% \begin{macrocode} |
| 784 |
\endgroup% |
| 785 |
} |
| 786 |
% \end{macrocode} |
| 787 |
% \end{macro} |
| 788 |
% |
| 789 |
% \begin{macrocode} |
| 790 |
\makeatother |
| 791 |
% \end{macrocode} |
| 792 |
|
| 793 |
% |
| 794 |
% \iffalse |
| 795 |
%</package> |
| 796 |
% \fi |
| 797 |
% |
| 798 |
% \Finale |
| 799 |
\endinput |