summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/pgf-blur/tikzlibraryshadows.blur.code.tex
blob: bf6fc97d92ad3e176bc8038f4d3c76d3187ae35e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
%%
%% This is file `tikzlibraryshadows.blur.code.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pgf-blur.dtx  (with options: `texfile')
%% Copyright 2012 Martin Giese, martingi@ifi.uio.no
%% 
%% This file is under the LaTeX Project Public License
%% See CTAN archives in directory macros/latex/base/lppl.txt.
%% 
%% DESCRIPTION:
%%   `pgf-blur' adds blurred/faded/fuzzy shadows to TikZ/PGF
%% 


\def\fileversion{1.0}
\def\filedate{2012/05/06}
\message{ v\fileversion, \filedate}
\usetikzlibrary{shadows}
\usetikzlibrary{calc}
\tikzset{
  /tikz/shadow blur radius/.store in=\pgfbs@radius,
  /tikz/shadow blur radius=.4ex,
  /tikz/shadow blur extra rounding/.store in=\pgfbs@extra@rounding,
  /tikz/shadow blur extra rounding=\pgfutil@empty,
  /tikz/shadow blur extra rounding/.default=\pgfbs@radius,
  /tikz/shadow blur steps/.store in=\pgfbs@steps,
  /tikz/shadow blur steps=3,
  /tikz/shadow opacity/.store in=\pgfbs@opacity,
  /tikz/shadow opacity=40,
  /tikz/blur shadow/.style={
    shadow scale=1,
    shadow xshift=.5ex,
    shadow yshift=-.5ex,
    preaction=render blur shadow,
    every shadow,
    #1,
  },
  /tikz/render blur shadow/.code={
    \pgfbs@savebb
    \pgfsyssoftpath@getcurrentpath{\pgfbs@input@path}%
    \pgfbs@compute@shadow@bbox
    \pgfbs@process@rounding{\pgfbs@input@path}{\pgfbs@fadepath}%
    \pgfbs@apply@canvas@transform
    \colorlet{pstb@shadow@color}{white!\pgfbs@opacity!black}%
    \pgfdeclarefading{shadowfading}{\pgfbs@paint@fading}%
    \pgfsetfillcolor{black}%
    \pgfsetfading{shadowfading}%
       {\pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}}%
    \pgfbs@usebbox{fill}%
    \pgfbs@restorebb
  },
}
\def\pgfbs@savebb{%
  \edef\pgfbs@restorebb{%
    \global\pgf@picminx=\the\pgf@picminx\relax
    \global\pgf@picmaxx=\the\pgf@picmaxx\relax
    \global\pgf@picminy=\the\pgf@picminy\relax
    \global\pgf@picmaxy=\the\pgf@picmaxy\relax
  }%
}
\def\restorebb{}%
\def\pgfbs@process@rounding#1#2{
  \expandafter\ifx\pgfbs@extra@rounding\pgfutil@empty%
    \pgfprocessround{#1}{#2}%
  \else%
    \pgfmathsetmacro\pgfbs@exrd@val{\pgfbs@extra@rounding}%
    \pgfbs@roundpath{#1}{\pgfbs@exrd@val pt}%
    \pgfsyssoftpath@getcurrentpath{\pgfbs@extraroundedpath}%
    \pgfprocessround{\pgfbs@extraroundedpath}{#2}%
  \fi%
}
\def\pgfbs@roundpath#1#2{%
  {%
    \def\pgfbs@rp@skipround{%
      \let\pgfbs@rp@possibleround\pgfbs@rp@insertround}%
    \def\pgfbs@rp@insertround{\pgfsyssoftpath@specialround{#2}{#2}}%
    \let\pgfbs@rp@possibleround\pgfbs@rp@insertround%
    %
    \def\pgfsyssoftpath@movetotoken##1##2{%
      \pgfsyssoftpath@moveto{##1}{##2}}%
    \def\pgfsyssoftpath@linetotoken##1##2{%
      \pgfbs@rp@possibleround\pgfsyssoftpath@lineto{##1}{##2}}%
    \def\pgfsyssoftpath@rectcornertoken##1##2##3##4##5{%
      \pgf@xa=##1\relax%
      \advance\pgf@xa by##4%
      \pgf@ya=##2\relax%
      \advance\pgf@ya by##5%
      \pgfsyssoftpath@moveto{##1}{##2}%
      \pgfbs@rp@possibleround%
      \pgfsyssoftpath@lineto{\the\pgf@xa}{##2}%
      \pgfbs@rp@possibleround%
      \pgfsyssoftpath@lineto{\the\pgf@xa}{\the\pgf@ya}%
      \pgfbs@rp@possibleround%
      \pgfsyssoftpath@lineto{##1}{\the\pgf@ya}%
      \pgfbs@rp@possibleround%
      \pgfsyssoftpath@closepath}%
    \def\pgfsyssoftpath@curvetosupportatoken%
       ##1##2##3##4##5##6##7##8{%
      \pgfbs@rp@possibleround%
      \pgfsyssoftpath@curveto{##1}{##2}{##4}{##5}{##7}{##8}}%
    \def\pgfsyssoftpath@closepathtoken##1##2{%
      \pgfbs@rp@possibleround\pgfsyssoftpath@closepath}%
    \def\pgfsyssoftpath@specialroundtoken##1##2{%
      \pgfmathsetmacro\pgfbs@rp@ra{max(##1,#2)}%
      \pgfmathsetmacro\pgfbs@rp@rb{max(##2,#2)}%
      \pgfsyssoftpath@specialround%
          {\pgfbs@rp@ra pt}{\pgfbs@rp@rb pt}%
      \let\pgfbs@rp@possibleround\pgfbs@rp@skipround%
    }
    #1%
  }
}
\def\pgfbs@compute@shadow@bbox{%
  \edef\pgfbs@minx{\the\pgf@pathminx}%
  \edef\pgfbs@miny{\the\pgf@pathminy}%
  \edef\pgfbs@maxx{\the\pgf@pathmaxx}%
  \edef\pgfbs@maxy{\the\pgf@pathmaxy}%
  \pgfmathsetmacro\pgfbs@midx{0.5*(\pgfbs@minx + \pgfbs@maxx)}%
  \pgfmathsetmacro\pgfbs@midy{0.5*(\pgfbs@miny + \pgfbs@maxy)}%
  \pgfmathsetmacro\pgfbs@minx{\pgfbs@minx - \pgfbs@radius}%
  \pgfmathsetmacro\pgfbs@miny{\pgfbs@miny - \pgfbs@radius}%
  \pgfmathsetmacro\pgfbs@maxx{\pgfbs@maxx + \pgfbs@radius}%
  \pgfmathsetmacro\pgfbs@maxy{\pgfbs@maxy + \pgfbs@radius}%
  \pgfmathsetmacro\pgfbs@wd{\pgfbs@maxx - \pgfbs@minx}%
  \pgfmathsetmacro\pgfbs@ht{\pgfbs@maxy - \pgfbs@miny}%
  \pgfsyssoftpath@setcurrentpath\pgfutil@empty%
  \pgfsyssoftpath@rect{\pgfbs@minx pt}{\pgfbs@miny pt}%
                      {\pgfbs@wd pt}{\pgfbs@ht pt}%
  \pgfsyssoftpath@getcurrentpath{\pgfbs@shadow@bbox}%
  \pgfsyssoftpath@setcurrentpath\pgfutil@empty%
}

\def\pgfbs@set@fading@pic@bbox{
  \global\pgf@picminx=\pgfbs@minx pt\relax
  \global\pgf@picminy=\pgfbs@miny pt\relax
  \global\pgf@picmaxx=\pgfbs@maxx pt\relax
  \global\pgf@picmaxy=\pgfbs@maxy pt\relax
}
\def\pgfbs@usefadepath#1{%
  \pgfsyssoftpath@setcurrentpath{\pgfbs@fadepath}%
  \pgfsyssoftpath@flushcurrentpath%
  \pgfusepath{#1}%
}
\def\pgfbs@usebbox#1{%
  \pgfsyssoftpath@setcurrentpath{\pgfbs@shadow@bbox}%
  \pgfsyssoftpath@flushcurrentpath%
  \pgfusepath{#1}%
}
\def\pgfbs@apply@canvas@transform{
  \pgflowlevel{
    \pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}
    \pgftransformscale{\pgfkeysvalueof{/tikz/shadow scale}}
    \pgftransformshift{\pgfpoint%
      {\pgfkeysvalueof{/tikz/shadow xshift}-\pgfbs@midx}
      {\pgfkeysvalueof{/tikz/shadow yshift}-\pgfbs@midy}
    }
  }
}
\def\pgfbs@paint@fading{
  \pgfpicture
    % fix bounding box.
    \pgfbs@set@fading@pic@bbox
    % draw the outer part of the fading,
    % starting with lightest, outermost line
    \pgfsetroundjoin
    \pgfmathsetmacro\pgfbs@max@i{\pgfbs@steps - 1}
    \foreach \pgfbs@i in {0,...,\pgfbs@max@i} {
      \pgfmathsetmacro\pgfbs@wth{%
        2 * \pgfbs@radius * (1 - \pgfbs@i/\pgfbs@steps)}%
      \pgfmathsetmacro\pgfbs@op{%
        100 - (25/\pgfbs@steps) * (2*\pgfbs@i + 1)}%
      \pgfsetlinewidth{\pgfbs@wth pt}
      \pgfsetstrokecolor{black!\pgfbs@op!pstb@shadow@color}
      \pgfbs@usefadepath{stroke}
    }
    % clip to inside of path
    \pgfbs@usefadepath{clip}
    % fill inside with final darkest shadow color
    \pgfsetfillcolor{pstb@shadow@color}
    \pgfbs@usebbox{fill}
    % draw the inner part of the fading,
    % starting with the darkest, innermost line
    \foreach \pgfbs@i in {0,...,\pgfbs@max@i} {
      \pgfmathsetmacro\pgfbs@wth{%
        2 * \pgfbs@radius * (1 - \pgfbs@i/\pgfbs@steps)}%
      \pgfmathsetmacro\pgfbs@op{(25/\pgfbs@steps) * (2*\pgfbs@i + 1)}
      \pgfsetlinewidth{\pgfbs@wth pt}
      \pgfsetstrokecolor{black!\pgfbs@op!pstb@shadow@color}
      \pgfbs@usefadepath{stroke}
    }
  \endpgfpicture
}
\endinput
%%
%% End of file `tikzlibraryshadows.blur.code.tex'.