Debian Codegraph @

texmf-dist/source/latex/pgf-blur/pgf-blur.dtx

raw
1 % \iffalse meta-comment -*-mode:Latex;tex-command:"pdflatex"-*-
2 %<*internal>
3 \def\nameofplainTeX{plain}
4 \ifx\fmtname\nameofplainTeX\else
5 \expandafter\begingroup
6 \fi
7 %</internal>
8 %<*install>
9 \input docstrip.tex
10 \keepsilent
11 \askforoverwritefalse
12 \preamble
13 Copyright 2012 Martin Giese, [email protected]
14 Copyright 2012 Andrew Stacey
15 Copyright 2018 Norbert Preining, [email protected]
16
17 This file is under the LaTeX Project Public License
18 See CTAN archives in directory macros/latex/base/lppl.txt.
19
20 DESCRIPTION:
21 `pgf-blur' adds blurred/faded/fuzzy shadows to TikZ/PGF
22
23 \endpreamble
24 \generate{\file{tikzlibraryshadows.blur.code.tex}{\from{pgf-blur.dtx}{texfile}}}
25 \Msg{************************************************************}
26 \Msg{ }
27 \Msg{ To finish the installation you have to move the file}
28 \Msg{ `tikzlibraryshadows.blur.code.tex' into a directory}
29 \Msg{ searched by TeX.}
30 \Msg{ }
31 \Msg{ To type-set the documentation, including instructions,}
32 \Msg{ run the file `pgf-blur.dtx' through LaTeX.}
33 \Msg{ }
34 \Msg{***********************************************************}
35 %</install>
36 %<install>\endbatchfile
37 %<*internal>
38 \generate{
39 \file{\jobname.ins}{\from{\jobname.dtx}{install}}
40 }
41 \ifx\fmtname\nameofplainTeX
42 \expandafter\endbatchfile
43 \else
44 \expandafter\endgroup
45 \fi
46 %</internal>
47 %<*driver>
48 \NeedsTeXFormat{LaTeX2e}
49 \documentclass{ltxdoc}
50 \usepackage{tikz}
51 \usepackage{textcomp}
52 \usepackage{url}
53 \usetikzlibrary{shadows.blur}
54 \usetikzlibrary{shapes.symbols}
55 \usetikzlibrary{shapes.multipart}
56 \AtBeginDocument{
57 % \OnlyDescription % comment out for implementation details
58 \EnableCrossrefs
59 \RecordChanges
60 \CodelineIndex}
61 %\AtEndDocument{
62 % \PrintChanges
63 % \PrintIndex}
64 \MakeShortVerb{\|}
65 \newcommand\file[1]{\texttt{#1}}
66 \begin{document}
67 \DocInput{pgf-blur.dtx}
68 \end{document}
69 %</driver>
70 %\fi
71 %
72 % \CheckSum{475}
73 %
74 % \CharacterTable
75 % {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
76 % 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
77 % Digits \0\1\2\3\4\5\6\7\8\9
78 % Exclamation \! Double quote \" Hash (number) \#
79 % Dollar \$ Percent \% Ampersand \&
80 % Acute accent \' Left paren \( Right paren \)
81 % Asterisk \* Plus \+ Comma \,
82 % Minus \- Point \. Solidus \/
83 % Colon \: Semicolon \; Less than \<
84 % Equals \= Greater than \> Question mark \?
85 % Commercial at \@ Left bracket \[ Backslash \\
86 % Right bracket \] Circumflex \^ Underscore \_
87 % Grave accent \` Left brace \{ Vertical bar \|
88 % Right brace \} Tilde \~}
89 %
90 %
91 % \changes{v1.00}{2012/04/20}{First public release. (mg)}
92 % \changes{v1.01}{2012/04/24}{Remove antialiasing/clipping artefacts (mg)}
93 % \changes{v1.02}{2018/08/21}{Fix multiple shadows, support inversion (as), changed maintainer (np)}
94 %
95 % \DoNotIndex{\!,\",\#,\$,\%,\&,\',\(,\+,\*,\,,\-,\.,\/,\:,\;,\<,\=,\>,\?}
96 % \setcounter{IndexColumns}{2}
97 %
98 % \title{\textsf{pgf-blur} package \\ version \fileversion}
99 % \author{Martin Giese}
100 % \date{\filedate}
101 % \maketitle
102 %
103 %\def\tikzname{Ti\emph{k}Z}
104 %
105 %\begin{center}
106 % Currently maintained by Norbert Preining\footnote{\protect\url{https://github.com/norbusan/pgf-blur}}
107 %\end{center}
108 %
109 %\begin{center}
110 % \small \textbf{Acknowledgement}\\ This package evolved from a discussion
111 % on \url{http://tex.stackexchange.com/}. In particular, the author received
112 % invaluable help from Andrew Stacey.
113 %\end{center}
114 %
115 %\section{Introduction}
116 % The ability to paint shadows on arbitrary shapes is a standard
117 % feature of TikZ/PGF. However, these shadows are usually `sharp':
118 %
119 %\newcommand\examplepath{
120 % (0,0) -- (0,1) -- (1.5,1) -- (1,0.5) [rounded corners=2mm] -- (1,0) [sharp corners]-- cycle
121 % (0.5,0.5) circle (0.3)
122 % }
123 %
124 %\begin{center}
125 % \begin{tikzpicture}
126 % \filldraw[drop shadow,draw=black,fill=white] \examplepath ;
127 % \node[starburst,very thick,rounded corners=2pt,fill=white,draw=red,
128 % drop shadow] at (5,0.5)
129 % {\sffamily\bfseries SPLAT!};
130 % \end{tikzpicture}
131 %\end{center}
132 %
133 % Such shadows are often optically too intrusive. A more pleasing effect
134 % is achieved if the edges of the shadow are `blurred,' i.e., getting
135 % gradually lighter and more transparent toward the outside.
136 % This effect can be achieved in TikZ/PGF with the |circular drop shadow|
137 % key, but that works only with ellipses and circles.
138 %
139 % The |pgf-blur| package provides blurred shadows that can be
140 % added to any closed path, including node borders:
141 %
142 %\begin{center}
143 % \begin{tikzpicture}
144 % \filldraw[blur shadow={shadow blur steps=8,shadow blur extra rounding},draw=black,fill=white] \examplepath ;
145 % \node[starburst,very thick,rounded corners=2pt,fill=white,draw=red,
146 % blur shadow={shadow blur steps=8,shadow blur extra rounding}] at (5,0.5)
147 % {\sffamily\bfseries SPLAT!};
148 % \end{tikzpicture}
149 %\end{center}
150 %
151 % \medskip
152 %
153 % The new TikZ options provided by the package
154 % are described in section 2 of this document. Section 3, if present, documents the
155 % implementation consisting of a generic \TeX\ file.
156 %
157 %\section{Package Usage}
158 %
159 % To use the package, the document needs to say |\usepackage{tikz}| and
160 % \begin{verbatim}
161 % \usetikzlibrary{shadows.blur}
162 % \end{verbatim}
163 % in the preamble.
164 %
165 % \DescribeMacro{blur shadow}
166 % \noindent A blurred shadow is added to a path or node by the option
167 % |blur shadow|, e.g.
168 %\begin{verbatim}
169 % \begin{tikzpicture}
170 % \filldraw[fill=white, draw=black, blur shadow] (0,0) circle (1);
171 % \node[fill=white, draw=black, blur shadow] at (4,0.5) {\Large Node};
172 % \end{tikzpicture}
173 %\end{verbatim}
174 % which gives
175 %\begin{center}
176 % \begin{tikzpicture}
177 % \filldraw[fill=white, draw=black, blur shadow] (0,0) circle (0.5);
178 % \node[fill=white, draw=black, blur shadow] at (2,0) {\Large Node};
179 % \end{tikzpicture}
180 %\end{center}
181 % Note that this usually makes sense only with closed paths that are filled
182 % (otherwise the shadow is visible through the path, and one wonders
183 % what is throwing the shadow) and often looks best if used with
184 % a drawn outline.
185 %
186 % The appearance of the shadow can be fine-tuned by giving arguments
187 % to the |blur shadow| options. These options do not have any effect
188 % if given outside of the argument of either |blur shadow| or |every shadow|
189 % (described later)
190 %
191 % \DescribeMacro{shadow xshift}
192 % \DescribeMacro{shadow yshift}
193 % \DescribeMacro{shadow scale}
194 % \noindent The shadow is based on a shifted, and possibly scaled copy of the original path.
195 % These options are described in the \tikzname/PGF user manual, and they work in
196 % the same way for blurred shadows. See also Fig.~\ref{fig:geometry}. The default
197 % values are 3ex for |shadow xshift|, \textminus3ex for |shadow yshift|, and
198 % 1 for |shadow scale|.
199 %
200 %\begin{figure}
201 %\begin{center}
202 % \begin{tikzpicture}
203 %\begin{scope}
204 % \clip (0,1) rectangle (8,5);
205 %
206 % \filldraw[fill=white, draw=black, ultra thick,
207 % blur shadow={
208 % shadow xshift=2cm,shadow yshift=-1cm,
209 % shadow blur radius=0.75cm, shadow blur steps=10}] (-4,3) rectangle (4,9);
210 % \draw[xshift=2cm,yshift=-1cm,thin,dotted,red]
211 % (4,3) circle (0.75)
212 % (-4,3) rectangle (4,9)
213 % (-4.75,3.75) rectangle (3.25,9.75)
214 % [rounded corners=0.75cm] (-3.25,2.25) rectangle (4.75,8.25);
215 %\end{scope}
216 %
217 % \draw[-stealth, thin] (4,3) -- (6,2)
218 % node[pos=0.6,left=0.7em] {\footnotesize (|shadow xshift|,\,|shadow yshift|)};
219 %
220 % \draw[stealth-stealth, thin] (6,2) -- + (-60:0.75)
221 % node[pos=0.4,right=0.4em] {\footnotesize |shadow blur radius|};
222 % \end{tikzpicture}
223 %\end{center}
224 % \caption{Shadow geometry}
225 % \label{fig:geometry}
226 %\end{figure}
227 %
228 % Here is an example for the usage of these options:
229 %\begin{verbatim}
230 % \begin{tikzpicture}
231 % \filldraw[fill=white, draw=black,
232 % blur shadow={shadow xshift=1ex,
233 % shadow yshift=1ex,
234 % shadow scale=1.2}]
235 % (0,0) circle (0.5);
236 % \end{tikzpicture}
237 %\end{verbatim}
238 % Which gives:
239 %\begin{center}
240 % \begin{tikzpicture}
241 % \filldraw[fill=white, draw=black,
242 % blur shadow={shadow xshift=1ex,
243 % shadow yshift=1ex,
244 % shadow scale=1.2}]
245 % (0,0) circle (0.5);
246 % \end{tikzpicture}
247 %\end{center}
248 %
249 % \DescribeMacro{shadow blur radius}
250 % \noindent Fig.~\ref{fig:geometry} shows how the blur shadow spreads out
251 % the boundary of the path over a circular region. The intent is
252 % to mimic the effect of a circular light source over the shape.
253 % the radius of the ``blurring'' can be set with the
254 % |shadow blur radius| option, which has a default value of
255 % \csname pgfbs@radius\endcsname.
256 %
257 % Here is an example of a drastically enlarged blur radius:
258 %\begin{verbatim}
259 % \begin{tikzpicture}
260 % \filldraw[fill=white, draw=black,
261 % blur shadow={shadow blur radius=1.5ex}]
262 % (0,0) circle (0.5);
263 % \end{tikzpicture}
264 %\end{verbatim}
265 % Which gives:
266 %\begin{center}
267 % \begin{tikzpicture}
268 % \filldraw[fill=white, draw=black,
269 % blur shadow={shadow blur radius=1.5ex}]
270 % (0,0) circle (0.5);
271 % \end{tikzpicture}
272 %\end{center}
273 %
274 % \DescribeMacro{shadow opacity}
275 % \noindent Shadows are transparent. They are always black since a shadow is the
276 % absence of light. The opacity of the interior of the shadow, i.e.~the
277 % darkest region can be controlled with the |shadow opacity| option. It
278 % is given as a percentage, i.e.~a number between 0 and 100. The default
279 % is \csname pgfbs@opacity\endcsname.
280 %
281 % Here are examples of lighter and darker shadows:
282 %\begin{verbatim}
283 % \begin{tikzpicture}
284 % \draw[help lines,step=0.5] (-1,-1) grid (3,1);
285 % \filldraw[fill=white, draw=black,
286 % blur shadow={shadow opacity=20}]
287 % (0,0) circle (0.5);
288 % \filldraw[fill=white, draw=black,
289 % blur shadow={shadow opacity=60}]
290 % (2,0) circle (0.5);
291 % \end{tikzpicture}
292 %\end{verbatim}
293 % Which gives:
294 %\begin{center}
295 % \begin{tikzpicture}
296 % \draw[help lines,step=0.5] (-1,-1) grid (3,1);
297 % \filldraw[fill=white, draw=black,
298 % blur shadow={shadow opacity=20}]
299 % (0,0) circle (0.5);
300 % \filldraw[fill=white, draw=black,
301 % blur shadow={shadow opacity=60}]
302 % (2,0) circle (0.5);
303 % \end{tikzpicture}
304 %\end{center}
305 %
306 % \DescribeMacro{shadow blur extra rounding}
307 % A close inspection of the shadow in Fig.~\ref{fig:geometry}
308 % reveals that if the original path has a corner, then
309 % the ``lines of equal opacity'' in the inner part of the shadow will
310 % also have corners. This is a consequence of the way the shadows are
311 % rendered by default. It gives the impression of the darkest part
312 % of the shadow extruding a little too much into the faded part.
313 % This effect can be reduced by adding the option |shadow extra rounding|,
314 % which has the effect of rounding all corners of the path before rendering
315 % the shadow. The rounding inset can be given as an argument; it
316 % defaults to the current value of the blur radius.
317 %
318 % Several points should be remembered when using this option:
319 % \begin{itemize}
320 % \item It uses the mechanism that \tikzname\ also uses for the
321 % |rounded corners| option. This works badly, distorting the
322 % path in strange ways, if the individual segments of the path
323 % are too short to be rounded with the given inset. If the
324 % shadows look strange, try reducing the inset, or drop this
325 % option altogether.
326 % \item Rounding many complex paths can slow \TeX\ down considerably.
327 % \item The ideal rounding inset depends on the angle the path has
328 % at each corner. This is not taken into account, the same
329 % inset is used everywhere. The default value is the one that
330 % works best with 90\textdegree\ angles, but it also looks
331 % fairly good with other angles.
332 % \item With or without this option, the shadows will not be
333 % photorealistic.
334 % \end{itemize}
335 % Here is an example of squares without and with extra rounding applied:
336 %\begin{verbatim}
337 % \begin{tikzpicture}
338 % \filldraw[fill=white, draw=black,
339 % blur shadow]
340 % (0,0) rectangle (1,1);
341 % \filldraw[fill=white, draw=black,
342 % blur shadow={shadow blur extra rounding}]
343 % (2,0) rectangle (3,1);
344 % \end{tikzpicture}
345 %\end{verbatim}
346 % Which gives:
347 %\begin{center}
348 % \begin{tikzpicture}
349 % \filldraw[fill=white, draw=black,
350 % blur shadow]
351 % (0,0) rectangle (1,1);
352 % \filldraw[fill=white, draw=black,
353 % blur shadow={shadow blur extra rounding}]
354 % (2,0) rectangle (3,1);
355 % \end{tikzpicture}
356 %\end{center}
357 %
358 % \DescribeMacro{shadow blur steps}
359 % \noindent The transition of opacity in these shadows is actually not
360 % smooth, but proceeds in a finite number of discrete steps.
361 % Specifically, there is a number $n$, such that the (shifted and
362 % scaled) original path fades outward to complete transparency in $n$
363 % steps and within the selected |shadow blur radius|, and inward to
364 % the maximum opacity of the shadow, also within $n$ steps and the
365 % |shadow blur radius|. This number of steps $n$ can be selected
366 % using the |shadow blur steps| option. It defaults to
367 % \csname pgfbs@steps\endcsname, which is
368 % enough e.g.~for inconspicuous shadows in presentations that nobody
369 % examines with a magnifying glass. The examples in the introduction
370 % use 8, under the assumption that readers will have a close look.
371 % Fig.~\ref{fig:geometry} uses 10 because the blur radius is so large.
372 %
373 % A large number of steps will slow down both the \TeX\ processing and the
374 % PDF rendering, usually with very little visible impact.
375 %
376 % \DescribeMacro{every shadow}
377 % To apply the same set of options to every shadow, it is possible to
378 % define the \emph{style} |every shadow|, which is taken from the
379 % standard shadow library. For instance, in the following, darker
380 % shadows with more steps are selected for several shapes:
381 %\begin{verbatim}
382 % \begin{tikzpicture}
383 % [every shadow/.style={shadow opacity=60,
384 % shadow blur steps=7}]
385 % \filldraw[fill=white, draw=black, blur shadow]
386 % (0,0) rectangle (1,1);
387 % \node[cloud,shape aspect=2,fill=white, draw=black,
388 % blur shadow]
389 % at (2.5,0.5) {Rain};
390 % \end{tikzpicture}
391 %\end{verbatim}
392 % Which gives:
393 %\begin{center}
394 % \begin{tikzpicture}
395 % [every shadow/.style={shadow opacity=60,
396 % shadow blur steps=7}]
397 % \filldraw[fill=white, draw=black, blur shadow]
398 % (0,0) rectangle (1,1);
399 % \node[cloud,shape aspect=2,fill=white, draw=black,
400 % blur shadow]
401 % at (2.5,0.5) {Rain};
402 % \end{tikzpicture}
403 %\end{center}
404
405 %
406 % \StopEventually{}
407 %
408 % \subsection{A Note on Nodes}
409 %
410
411 % While this library plays nicely with most closed paths, it doesn't
412 % like paths with non-closed parts. This is particularly annoying
413 % when used with standard node shapes, where you can't do much about
414 % the paths. Take the |rectangle split| shape for instance:
415 %
416 %\begin{verbatim}
417 % \begin{tikzpicture}
418 % \node[rectangle split, rectangle split parts=3, draw, fill=white,
419 % blur shadow={shadow xshift=1em}] {...};
420 % \end{tikzpicture}
421 %\end{verbatim}
422 %
423 %\begin{center}
424 % \begin{tikzpicture}
425 % \node[rectangle split, rectangle split parts=3, draw, fill=white,
426 % blur shadow={shadow xshift=1em}]
427 % {Cake \nodepart{two} icing: Icing \nodepart{three} getIcing()};
428 % \end{tikzpicture}
429 %\end{center}
430 %
431 % Note how the part separation lines produce white bars in the shadow.
432 % This is really hard to avoid in general. There are two simple
433 % workarounds: a) choosing a very small |shadow xshift| so most the
434 % ``bar'' gets hidden behind the shape, or b) putting
435 % the node inside a simple rectangle node and add a shadow to the latter.
436 % For solution b) to work, the inner padding of the outer node has to
437 % be removed. This in turn requires it to be reinstated for the inner
438 % node. Here's the example showing both workarounds:
439 %
440 %\begin{verbatim}
441 % \begin{tikzpicture}
442 % \node[rectangle split, rectangle split parts=3,
443 % draw, fill=white,
444 % blur shadow={shadow xshift=0.25ex}] at (-2,0) {...};
445 % \node[blur shadow={shadow xshift=1em},inner sep=0pt] at (2,0) {
446 % \tikz\node[rectangle split, rectangle split parts=3,
447 % draw, fill=white, inner sep=0.333em] {...};};
448 % \end{tikzpicture}
449 %\end{verbatim}
450 %
451 %\begin{center}
452 % \begin{tikzpicture}
453 % \node[rectangle split, rectangle split parts=3,
454 % draw, fill=white,
455 % blur shadow={shadow xshift=0.25ex}] at (-2,0)
456 % {Cake \nodepart{two} icing: Icing \nodepart{three} getIcing()};
457 % \node[blur shadow={shadow xshift=1em},inner sep=0pt] at (2,0) {
458 % \tikz\node[rectangle split, rectangle split parts=3,
459 % draw, fill=white, inner sep=0.333em]
460 % {Cake \nodepart{two} icing: Icing \nodepart{three} getIcing()};};
461 % \end{tikzpicture}
462 %\end{center}
463 %
464 % Solution b) is fine for rectangular outlines, but it wont work for e.g.~the
465 % |cylinder| shape.
466 %
467 % \section{Implementation}
468 %
469 %\begin{macro}{\fileversion}
470 % \begin{macro}{\filedate}
471 % We define the file version and date, and
472 % import the original shadow code for the offset and scale parameters.
473 % \begin{macrocode}
474 %<*texfile>
475 \def\fileversion{1.02}
476 \def\filedate{2012/12/09}
477 \message{ v\fileversion, \filedate}
478 \usetikzlibrary{shadows}
479 \usetikzlibrary{calc}
480 % \end{macrocode}
481 % \end{macro}
482 %\end{macro}
483 %\begin{macro}{\ifpgfbs@invert@fading}
484 % An |\if| to control whether to invert the fading or not.
485 % \begin{macrocode}
486 \newif\ifpgfbs@invert@fading
487 % \end{macrocode}
488 %\end{macro}
489 %\begin{macro}{\pgfbs@fading@count}
490 % A |count| to make the names unique
491 % \begin{macrocode}
492 \newcount\pgfbs@fading@count
493 \pgfbs@fading@count=0\relax
494 % \end{macrocode}
495 %\end{macro}
496 %\begin{macro}{shadow blur radius}
497 %\begin{macro}{shadow blur extra rounding}
498 %\begin{macro}{shadow blur steps}
499 %\begin{macro}{shadow opacity}
500 % Next we define the various \tikzname\ options, with their default values.
501 % The options |shadow xshift|, |shadow yshift|, |shadow scale| are imported
502 % from the standard \tikzname\ shadow library, so we don't need to do
503 % anything for them.
504 % Note how the default value of |shadow blur extra rounding| is by default
505 % set to the blur radius. This works because the value of this key is
506 % evaluated before it is used. All other options just store values
507 % in a couple of macros.
508 % \begin{macrocode}
509 \tikzset{
510 /tikz/shadow blur radius/.store in=\pgfbs@radius,
511 /tikz/shadow blur radius=.4ex,
512 /tikz/shadow blur extra rounding/.store in=\pgfbs@extra@rounding,
513 /tikz/shadow blur extra rounding=\pgfutil@empty,
514 /tikz/shadow blur extra rounding/.default=\pgfbs@radius,
515 /tikz/shadow blur steps/.store in=\pgfbs@steps,
516 /tikz/shadow blur steps=4,
517 /tikz/shadow blur invert/.is if=pgfbs@invert@fading,
518 /tikz/shadow opacity/.store in=\pgfbs@opacity,
519 /tikz/shadow opacity=40,
520 % \end{macrocode}
521 %\end{macro}
522 %\end{macro}
523 %\end{macro}
524 %\end{macro}
525 %\begin{macro}{blur shadow}
526 % The user level option |blur shadow| sets the
527 % |shadow xshift|, |shadow yshift|, |shadow scale| options to
528 % more useful defaults than the ones inherited from the shadows library.
529 % It includes any options set in the |every shadow| style, and the
530 % argument to |blur shadow|. Rendering the shadow is declared as a
531 % |.preaction| on the path. \tikzname\ will take care of saving the
532 % path for us.
533 % \begin{macrocode}
534 /tikz/blur shadow/.style={
535 shadow scale=1,
536 shadow xshift=.5ex,
537 shadow yshift=-.5ex,
538 preaction=render blur shadow,
539 every shadow,
540 #1,
541 },
542 % \end{macrocode}
543 %\end{macro}
544 % \begin{macro}{render blur shadow}
545 % The following does the actual shadow rendering. After some preliminary
546 % computation of dimensions, shifting and scaling is done using a
547 % canvas transform. The actual blurring effect is done using a special fading.
548 % Since PGF insists on centering every fading when it's constructed,
549 % it has to be shifted back again when it's installed.
550 % The shadow is painted by filling a large black rectangle using the
551 % constructed fading.
552 % \begin{macrocode}
553 /tikz/render blur shadow/.code={
554 \pgfbs@savebb
555 \global\advance\pgfbs@fading@count by 1\relax
556 \pgfsyssoftpath@getcurrentpath{\pgfbs@input@path}%
557 \pgfbs@compute@shadow@bbox
558 \pgfbs@process@rounding{\pgfbs@input@path}{\pgfbs@fadepath}%
559 \pgfbs@apply@canvas@transform
560 \colorlet{pstb@shadow@color}{white!\pgfbs@opacity!black}%
561 \ifpgfbs@invert@fading
562 \pgfdeclarefading{shadowfading-\the\pgfbs@fading@count}{\pgfbs@paint@invert@fading}%
563 \else
564 \pgfdeclarefading{shadowfading-\the\pgfbs@fading@count}{\pgfbs@paint@fading}%
565 \fi
566 \pgfsetfillcolor{black}%
567 \pgfsetfading{shadowfading-\the\pgfbs@fading@count}%
568 {\pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}}%
569 \pgfbs@usebbox{fill}%
570 \pgfbs@restorebb
571 },
572 }
573 % \end{macrocode}
574 % \end{macro}
575 %
576 % \begin{macro}{\pgfbs@savebb}
577 % Shadow rendering works with a fading. For a fading to contain PGF code,
578 % it must contain a |pgfpicture|. And nested |pgfpicture|s mess up the
579 % bounding box of the surrounding picture. Which is why we save the
580 % current picture bounding box at the beginning of the shadow code
581 % and restore it at the end. Thanks go to Andrew Stacey for this!
582 % \begin{macrocode}
583 \def\pgfbs@savebb{%
584 \edef\pgfbs@restorebb{%
585 \global\pgf@picminx=\the\pgf@picminx\relax
586 \global\pgf@picmaxx=\the\pgf@picmaxx\relax
587 \global\pgf@picminy=\the\pgf@picminy\relax
588 \global\pgf@picmaxy=\the\pgf@picmaxy\relax
589 }%
590 }
591 % \end{macrocode}
592 % \end{macro}
593 % \begin{macro}{\pgfbs@restorebb}
594 % Executing |\pgfbs@savebb| sets this bounding box restoring macro
595 % to something useful.
596 % \begin{macrocode}
597 \def\restorebb{}%
598 % \end{macrocode}
599 % \end{macro}
600 %\begin{macro}{\pgfbs@process@rounding}
601 % This macro prepares the path by taking care of all things having to do
602 % with rounding. First, it applies extra rounding to the path if requested
603 % by the |shadow blur extra rounding| option. Second, it removes all
604 % rounding tokens in the path by calling the |\pgfprocessround| macro.
605 % This is because rounding tokens don't work well with the fading code
606 % for some reason or other.
607 % |#1| must be a PGF soft path. |#2| must be a macro into which the resulting
608 % soft path will be stored.
609 % \begin{macrocode}
610 \def\pgfbs@process@rounding#1#2{
611 \expandafter\ifx\pgfbs@extra@rounding\pgfutil@empty%
612 \pgfprocessround{#1}{#2}%
613 \else%
614 \pgfmathsetmacro\pgfbs@exrd@val{\pgfbs@extra@rounding}%
615 \pgfbs@roundpath{#1}{\pgfbs@exrd@val pt}%
616 \pgfsyssoftpath@getcurrentpath{\pgfbs@extraroundedpath}%
617 \pgfprocessround{\pgfbs@extraroundedpath}{#2}%
618 \fi%
619 }
620 % \end{macrocode}
621 %\end{macro}
622 % \begin{macro}{\pgfbs@roundpath}
623 % |\pgfbs@roundpath{#1}{#2}| rounds every potential corner in path |#1|
624 % with an inset of at least |#2|.
625 % Corners that are already rounded in |#1| are either left intact if
626 % their insets are $\geq$|#2|, or the insets are increased to |#2|.
627 % Any rectangle tokens are resolved into moveto/lineto/closepath with rounding.
628 % The result is appended to PGF's ``current path.''
629 %
630 % The code works by giving an appropriate definition for each of the PGF
631 % soft path tokens and then executing the path.
632 % \begin{macrocode}
633 \def\pgfbs@roundpath#1#2{%
634 {%
635 \def\pgfbs@rp@skipround{%
636 \let\pgfbs@rp@possibleround\pgfbs@rp@insertround}%
637 \def\pgfbs@rp@insertround{\pgfsyssoftpath@specialround{#2}{#2}}%
638 \let\pgfbs@rp@possibleround\pgfbs@rp@insertround%
639 %
640 \def\pgfsyssoftpath@movetotoken##1##2{%
641 \pgfsyssoftpath@moveto{##1}{##2}}%
642 \def\pgfsyssoftpath@linetotoken##1##2{%
643 \pgfbs@rp@possibleround\pgfsyssoftpath@lineto{##1}{##2}}%
644 \def\pgfsyssoftpath@rectcornertoken##1##2##3##4##5{%
645 \pgf@xa=##1\relax%
646 \advance\pgf@xa by##4%
647 \pgf@ya=##2\relax%
648 \advance\pgf@ya by##5%
649 \pgfsyssoftpath@moveto{##1}{##2}%
650 \pgfbs@rp@possibleround%
651 \pgfsyssoftpath@lineto{\the\pgf@xa}{##2}%
652 \pgfbs@rp@possibleround%
653 \pgfsyssoftpath@lineto{\the\pgf@xa}{\the\pgf@ya}%
654 \pgfbs@rp@possibleround%
655 \pgfsyssoftpath@lineto{##1}{\the\pgf@ya}%
656 \pgfbs@rp@possibleround%
657 \pgfsyssoftpath@closepath}%
658 \def\pgfsyssoftpath@curvetosupportatoken%
659 ##1##2##3##4##5##6##7##8{%
660 \pgfbs@rp@possibleround%
661 \pgfsyssoftpath@curveto{##1}{##2}{##4}{##5}{##7}{##8}}%
662 \def\pgfsyssoftpath@closepathtoken##1##2{%
663 \pgfbs@rp@possibleround\pgfsyssoftpath@closepath}%
664 \def\pgfsyssoftpath@specialroundtoken##1##2{%
665 \pgfmathsetmacro\pgfbs@rp@ra{max(##1,#2)}%
666 \pgfmathsetmacro\pgfbs@rp@rb{max(##2,#2)}%
667 \pgfsyssoftpath@specialround%
668 {\pgfbs@rp@ra pt}{\pgfbs@rp@rb pt}%
669 \let\pgfbs@rp@possibleround\pgfbs@rp@skipround%
670 }
671 #1%
672 }
673 }
674 % \end{macrocode}
675 % \end{macro}
676 %\begin{macro}{\pgfbs@compute@shadow@bbox}
677 %\begin{macro}{\pgfbs@minx}
678 %\begin{macro}{\pgfbs@midx}
679 %\begin{macro}{\pgfbs@maxx}
680 %\begin{macro}{\pgfbs@miny}
681 %\begin{macro}{\pgfbs@midy}
682 %\begin{macro}{\pgfbs@maxy}
683 %\begin{macro}{\pgfbs@shadow@bbox}
684 % This macro figures out the bounding box of the shadow: it's the
685 % same as the bounding box of the current path, but enlarged by
686 % twice (for the inverse shadow) the blur radius in each direction. It also computes the
687 % coordinates of the center of the bounding box. These are
688 % stored in macros |\pgfbs@|\{|min|$\mid$|mid|$\mid$|max|\}\{|x|$\mid$|y|\}.
689 % It also creates a soft path for the bounding box which is stored in
690 % |\pgfbs@shadow@bbox|.
691 % \begin{macrocode}
692 \def\pgfbs@compute@shadow@bbox{%
693 \edef\pgfbs@minx{\the\pgf@pathminx}%
694 \edef\pgfbs@miny{\the\pgf@pathminy}%
695 \edef\pgfbs@maxx{\the\pgf@pathmaxx}%
696 \edef\pgfbs@maxy{\the\pgf@pathmaxy}%
697 \pgfmathsetmacro\pgfbs@midx{0.5*(\pgfbs@minx + \pgfbs@maxx)}%
698 \pgfmathsetmacro\pgfbs@midy{0.5*(\pgfbs@miny + \pgfbs@maxy)}%
699 \pgfmathsetmacro\pgfbs@minx{\pgfbs@minx - 2*\pgfbs@radius}%
700 \pgfmathsetmacro\pgfbs@miny{\pgfbs@miny - 2*\pgfbs@radius}%
701 \pgfmathsetmacro\pgfbs@maxx{\pgfbs@maxx + 2*\pgfbs@radius}%
702 \pgfmathsetmacro\pgfbs@maxy{\pgfbs@maxy + 2*\pgfbs@radius}%
703 \pgfmathsetmacro\pgfbs@wd{\pgfbs@maxx - \pgfbs@minx}%
704 \pgfmathsetmacro\pgfbs@ht{\pgfbs@maxy - \pgfbs@miny}%
705 \pgfsyssoftpath@setcurrentpath\pgfutil@empty%
706 \pgfsyssoftpath@rect{\pgfbs@minx pt}{\pgfbs@miny pt}%
707 {\pgfbs@wd pt}{\pgfbs@ht pt}%
708 \pgfsyssoftpath@getcurrentpath{\pgfbs@shadow@bbox}%
709 \pgfsyssoftpath@setcurrentpath\pgfutil@empty%
710 }
711 % \end{macrocode}
712 %\end{macro}
713 %\end{macro}\end{macro}\end{macro}
714 %\end{macro}\end{macro}\end{macro}
715 %\end{macro}
716 %\begin{macro}{\pgfbs@set@fading@pic@bbox}
717
718 % Set the bounding box of the fading picture painted by
719 % |\pgfbs@paint@fading|. Normally, the bounding box is updated
720 % automatically, but this doesn't happen when PGF's soft paths are
721 % used. The code that applies a fading needs the dimensions
722 % of the fading to be correct. So we explicitly set the picture
723 % bounding box according to the previously computed values.
724 % Thanks again to Andrew Stacey for pointing out this subtlety!
725 %
726 % \begin{macrocode}
727 \def\pgfbs@set@fading@pic@bbox{
728 \global\pgf@picminx=\pgfbs@minx pt\relax
729 \global\pgf@picminy=\pgfbs@miny pt\relax
730 \global\pgf@picmaxx=\pgfbs@maxx pt\relax
731 \global\pgf@picmaxy=\pgfbs@maxy pt\relax
732 }
733 % \end{macrocode}
734 %\end{macro}
735 %\begin{macro}{\pgfbs@usefadepath}
736 % The code of the |render blur shadow| option stores the pre-processed
737 % soft path into the macro |\pgfbs@fadepath|. This macro `uses'
738 % this path by executing |\pgfusepath{#1}| on it.
739 %
740 % \begin{macrocode}
741 \def\pgfbs@usefadepath#1{%
742 \pgfsyssoftpath@setcurrentpath{\pgfbs@fadepath}%
743 \pgfsyssoftpath@flushcurrentpath%
744 \pgfusepath{#1}%
745 }
746 % \end{macrocode}
747 %\end{macro}
748 %\begin{macro}{\pgfbs@usebbox}
749 % This is similar to the previous macro, but it `uses' the bounding box
750 % path.
751 % \begin{macrocode}
752 \def\pgfbs@usebbox#1{%
753 \pgfsyssoftpath@setcurrentpath{\pgfbs@shadow@bbox}%
754 \pgfsyssoftpath@flushcurrentpath%
755 \pgfusepath{#1}%
756 }
757 % \end{macrocode}
758 %\end{macro}
759 %\begin{macro}{\pgfbs@usefadeandbbox}
760 % This is similar to the previous macros, but it `uses' both the fading path and the bounding box
761 % path.
762 % \begin{macrocode}
763 \def\pgfbs@usefadeandbbox#1{%
764 \let\pgfbs@temppath\pgfbs@fadepath
765 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\pgfbs@temppath\expandafter\expandafter\expandafter{\expandafter\pgfbs@temppath\pgfbs@shadow@bbox}%
766 \pgfsyssoftpath@setcurrentpath{\pgfbs@temppath}%
767 \pgfsyssoftpath@flushcurrentpath%
768 \pgfusepath{#1}%
769 }
770 % \end{macrocode}
771 %\end{macro}
772 %\begin{macro}{\pgfbs@apply@canvas@transform}
773 % This achieves the scaling and shifting of the shadow. It is done by a
774 % canvas transform to avoid iterating through a soft path and transforming
775 % many coordinates inside \TeX. Scaling is `around' the bounding box
776 % mid point computed by |\pgfbs@compute@shadow@bbox|.
777 % \begin{macrocode}
778 \def\pgfbs@apply@canvas@transform{
779 \pgflowlevel{
780 \pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}
781 \pgftransformscale{\pgfkeysvalueof{/tikz/shadow scale}}
782 \pgftransformshift{\pgfpoint%
783 {\pgfkeysvalueof{/tikz/shadow xshift}-\pgfbs@midx}
784 {\pgfkeysvalueof{/tikz/shadow yshift}-\pgfbs@midy}
785 }
786 }
787 }
788 % \end{macrocode}
789 %\end{macro}
790 %\begin{macro}{\pgfbs@paint@fading}
791 % This paints the actual fading picture. It works by repeatedly
792 % drawing the |\pgfbs@fadepath| with different line widths and
793 % different shades of gray, leading to different opacity. First, the
794 % outer part of the fading is drawn. Then, remaining operations
795 % are clipped to the inside of the path. Next, the path is filled with
796 % the shadow opacity. Finally, the inner part of the fading is drawn.
797 % As mentioned previously, the bounding box needs to be set explicitly.
798 % \begin{macrocode}
799 \def\pgfbs@paint@fading{
800 \pgfpicture
801 \pgfsetbaseline{\pgf@picminy}%
802 % fix bounding box.
803 \pgfbs@set@fading@pic@bbox
804 % compute increments for line width and opacity
805 \pgfmathsetmacro\pgfbs@op@step{50/\pgfbs@steps}
806 \pgfmathsetmacro\pgfbs@wth@step{4*\pgfbs@radius/(2*\pgfbs@steps-1)}
807 % draw the outer part of the fading,
808 % starting with lightest, outermost line
809 \pgfsetroundjoin
810 \pgfmathsetmacro\pgfbs@max@i{\pgfbs@steps-2}
811 \pgfmathsetmacro\pgfbs@wth{2*\pgfbs@radius}
812 \pgfmathsetmacro\pgfbs@op{100-0.5*\pgfbs@op@step}
813 \foreach \pgfbs@i in {0,...,\pgfbs@max@i} {
814 \pgfsetlinewidth{\pgfbs@wth pt}
815 \pgfsetstrokecolor{black!\pgfbs@op!pstb@shadow@color}
816 \pgfbs@usefadepath{stroke}
817 \pgfmathsetmacro\pgfbs@wth{\pgfbs@wth-\pgfbs@wth@step}
818 \global\let\pgfbs@wth=\pgfbs@wth
819 \pgfmathsetmacro\pgfbs@op{\pgfbs@op-\pgfbs@op@step}
820 \global\let\pgfbs@op=\pgfbs@op
821 }
822 % clip to inside of path
823 \scope
824 \pgfbs@usefadepath{clip}
825 % fill inside with final darkest shadow color
826 \pgfsetfillcolor{pstb@shadow@color}
827 \pgfbs@usebbox{fill}
828 % draw the inner part of the fading,
829 % starting with the darkest, innermost line
830 \pgfmathsetmacro\pgfbs@wth{2*\pgfbs@radius}
831 \pgfmathsetmacro\pgfbs@op{0.5*\pgfbs@op@step}
832 \foreach \pgfbs@i in {0,...,\pgfbs@max@i} {
833 \pgfsetlinewidth{\pgfbs@wth pt}
834 \pgfsetstrokecolor{black!\pgfbs@op!pstb@shadow@color}
835 \pgfbs@usefadepath{stroke}
836 \pgfmathsetmacro\pgfbs@wth{\pgfbs@wth-\pgfbs@wth@step}
837 \global\let\pgfbs@wth=\pgfbs@wth
838 \pgfmathsetmacro\pgfbs@op{\pgfbs@op+\pgfbs@op@step}
839 \global\let\pgfbs@op=\pgfbs@op
840 }
841 \endscope
842 % a final stroke to hide clip/antialiasing artifcats
843 \pgfsetstrokecolor{black!50!pstb@shadow@color}
844 \pgfsetlinewidth{0.5*\pgfbs@wth@step}
845 \pgfbs@usefadepath{stroke}
846 \endpgfpicture
847 }
848 % \end{macrocode}
849 %\end{macro}
850 %\begin{macro}{\pgfbs@paint@invert@fading}
851 % This is an inverse fading.
852 % \begin{macrocode}
853 \def\pgfbs@paint@invert@fading{
854 \pgfpicture
855 \pgfsetbaseline{\pgf@picminy}%
856 % fix bounding box.
857 \pgfbs@set@fading@pic@bbox
858 % compute increments for line width and opacity
859 \pgfmathsetmacro\pgfbs@op@step{50/\pgfbs@steps}
860 \pgfmathsetmacro\pgfbs@wth@step{4*\pgfbs@radius/(2*\pgfbs@steps-1)}
861 % draw the outer part of the fading,
862 % starting with lightest, outermost line
863 \pgfsetroundjoin
864 \pgfmathsetmacro\pgfbs@max@i{\pgfbs@steps-2}
865 \pgfmathsetmacro\pgfbs@wth{2*\pgfbs@radius}
866 \pgfmathsetmacro\pgfbs@op{0.5*\pgfbs@op@step}
867 \foreach \pgfbs@i in {0,...,\pgfbs@max@i} {
868 \pgfsetlinewidth{\pgfbs@wth pt}
869 \pgfsetstrokecolor{black!\pgfbs@op!pstb@shadow@color}
870 \pgfbs@usefadepath{stroke}
871 \pgfmathsetmacro\pgfbs@wth{\pgfbs@wth-\pgfbs@wth@step}
872 \global\let\pgfbs@wth=\pgfbs@wth
873 \pgfmathsetmacro\pgfbs@op{\pgfbs@op+\pgfbs@op@step}
874 \global\let\pgfbs@op=\pgfbs@op
875 }
876 % clip to inside of path
877 \scope
878 \pgfseteorule
879 \pgfbs@usefadeandbbox{clip}
880 % fill inside with final darkest shadow color
881 \pgfsetfillcolor{pstb@shadow@color}
882 \pgfbs@usebbox{fill}
883 \endscope
884 \scope
885 \pgfbs@usefadepath{clip}
886 % draw the inner part of the fading,
887 % starting with the darkest, innermost line
888 \pgfmathsetmacro\pgfbs@wth{2*\pgfbs@radius}
889 \pgfmathsetmacro\pgfbs@op{100-0.5*\pgfbs@op@step}
890 \foreach \pgfbs@i in {0,...,\pgfbs@max@i} {
891 \pgfsetlinewidth{\pgfbs@wth pt}
892 \pgfsetstrokecolor{black!\pgfbs@op!pstb@shadow@color}
893 \pgfbs@usefadepath{stroke}
894 \pgfmathsetmacro\pgfbs@wth{\pgfbs@wth-\pgfbs@wth@step}
895 \global\let\pgfbs@wth=\pgfbs@wth
896 \pgfmathsetmacro\pgfbs@op{\pgfbs@op-\pgfbs@op@step}
897 \global\let\pgfbs@op=\pgfbs@op
898 }
899 \endscope
900 % a final stroke to hide clip/antialiasing artifcats
901 \pgfsetstrokecolor{black!50!pstb@shadow@color}
902 \pgfsetlinewidth{0.5*\pgfbs@wth@step}
903 \pgfbs@usefadepath{stroke}
904 \endpgfpicture
905 }
906 %</texfile>
907 % \end{macrocode}
908 %\end{macro}
909 %
910 % \Finale
911 %