Debian Codegraph @

texmf-dist/source/generic/pst-blur/pst-blur.dtx

raw
1 %\iffalse -*-mode:Latex;tex-command:"latex *;dvips -D600 pst-blur -o"-*- \fi
2 %\iffalse
3 %% $Id: pst-blur.dtx,v 2.0 2005/09/08 09:48:33 giese Exp $
4 %%
5 %% Copyright 1998-2007 Martin Giese, [email protected]
6 %% Herbert Voss, [email protected]
7 %%
8 %% This file is under the LaTeX Project Public License
9 %% See CTAN archives in directory macros/latex/base/lppl.txt.
10 %%
11 %% DESCRIPTION:
12 %% `pst-blur' is a PSTricks package for blurred shadows
13 %%
14 %
15 %\fi
16 %\iffalse
17 %<*driver>
18 \NeedsTeXFormat{LaTeX2e}
19 \documentclass{ltxdoc}
20 \usepackage{pst-node}
21 \usepackage{pst-text}
22 \usepackage{pst-blur}
23 \usepackage{url}
24 \AtBeginDocument{
25 % \OnlyDescription % comment out for implementation details
26 \EnableCrossrefs
27 \RecordChanges
28 \CodelineIndex}
29 \AtEndDocument{
30 \PrintChanges
31 \PrintIndex}
32 \hbadness=7000 % Over and under full box warnings
33 \hfuzz=3pt
34 \MakeShortVerb{\|}
35 \newcommand\file[1]{\texttt{#1}}
36 \begin{document}
37 \DocInput{pst-blur.dtx}
38 \end{document}
39 %</driver>
40 %\fi
41 %
42 % \CharacterTable
43 % {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
44 % 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
45 % Digits \0\1\2\3\4\5\6\7\8\9
46 % Exclamation \! Double quote \" Hash (number) \#
47 % Dollar \$ Percent \% Ampersand \&
48 % Acute accent \' Left paren \( Right paren \)
49 % Asterisk \* Plus \+ Comma \,
50 % Minus \- Point \. Solidus \/
51 % Colon \: Semicolon \; Less than \<
52 % Equals \= Greater than \> Question mark \?
53 % Commercial at \@ Left bracket \[ Backslash \\
54 % Right bracket \] Circumflex \^ Underscore \_
55 % Grave accent \` Left brace \{ Vertical bar \|
56 % Right brace \} Tilde \~}
57 % \CheckSum{152}
58 %
59 %
60 % \changes{v2.00}{2005/09/08}{%
61 % using the extended pst-xkey instead of the old pst-key package;
62 % creating a dtx file;
63 % new \LaTeX\ wrapper file (hv)}
64 % \changes{v1.80}{2001/02/16}{First public release. (mg)}
65 %
66 % \DoNotIndex{\!,\",\#,\$,\%,\&,\',\(,\+,\*,\,,\-,\.,\/,\:,\;,\<,\=,\>,\?}
67 % \DoNotIndex{\@,\@B,\@K,\@cTq,\@f,\@fPl,\@ifnextchar,\@nameuse,\@oVk}
68 % \DoNotIndex{\[,\\,\],\^,\_,\ }
69 % \DoNotIndex{\^,\\^,\\\^,$\^$,$\\^$,$\\^$}
70 % \DoNotIndex{\0,\2,\4,\5,\6,\7,\8,}
71 % \DoNotIndex{\A,\a}
72 % \DoNotIndex{\B,\b,\Bc,\begin,\Bq,\Bqc}
73 % \DoNotIndex{\C,\c,\catcode,\cJA,\CodelineIndex,\csname}
74 % \DoNotIndex{\D,\def,\define@key,\Df,\divide,\DocInput,\documentclass,\pst@addfams}
75 % \DoNotIndex{\eCN,\edef,\else,\eHd,\eMcj,\EnableCrossrefs,\end,\endcsname}
76 % \DoNotIndex{\endCenterExample,\endExample,\endinput,\endpsclip}
77 % \DoNotIndex{\PrintIndex,\PrintChanges,\ProvidesFile}
78 % \DoNotIndex{\endpspicture,\endSideBySideExample,\Example}
79 % \DoNotIndex{\F,\f,\FdUrr,\fi,\filedate,\fileversion,\FV@Environment}
80 % \DoNotIndex{\FV@UseKeyValues,\FV@XRightMargin,\FVB@Example,\fvset}
81 % \DoNotIndex{\G,\g,\GetFileInfo,\gr,\GradientLoaded,\gsFKrbK@o,\gsj,\gsOX}
82 % \DoNotIndex{\hbadness,\hfuzz,\HLEmphasize,\HLMacro,\HLMacro@i}
83 % \DoNotIndex{\HLReverse,\HLReverse@i,\hqcu,\HqY}
84 % \DoNotIndex{\I,\i,\ifx,\input,\Ir,\IU}
85 % \DoNotIndex{\j,\jl,\JT,\JVodH}
86 % \DoNotIndex{\K,\k,\kfSlL}
87 % \DoNotIndex{\L,\let}
88 % \DoNotIndex{\message,\mHNa,\mIU}
89 % \DoNotIndex{\N,\nB,\newcmykcolor,\newdimen,\newif,\nW}
90 % \DoNotIndex{\O,\oCDJDo,\ocQhVI,\OnlyDescription,\oRKJ}
91 % \DoNotIndex{\P,\p,\ProvidesPackage,\psframe,\pslinewidth,\psset}
92 % \DoNotIndex{\PstAtCode,\PSTricksLoaded}
93 % \DoNotIndex{\q,\Qr,\qssRXq,\qu,\qXjFQp,\qYL}
94 % \DoNotIndex{\R,\r,\RecordChanges,\relax,\RlaYI,\rN,\Rp,\rp,\RPDXNn,\rput}
95 % \DoNotIndex{\S,\scalebox,\SgY,\SideBySide@Example,\SideBySideExample}
96 % \DoNotIndex{\SgY,\sk,\Sp,\space,\sZb}
97 % \DoNotIndex{\T,\the,\tw@}
98 % \DoNotIndex{\u,\UiSWGEf@,\uJi,\usepackage,\uVQdMM,\UYj}
99 % \DoNotIndex{\VerbatimEnvironment,\VerbatimInput,\VrC@}
100 % \DoNotIndex{\WhZ,\WjKCYb,\WNs}
101 % \DoNotIndex{\XkN,\XW}
102 % \DoNotIndex{\Z,\ZCM,\Ze}
103 % \DoNotIndex{\addtocounter,\advance,\alph,\arabic,\AtBeginDocument,\AtEndDocument}
104 % \DoNotIndex{\AtEndOfPackage,\begingroup,\bfseries,\bgroup,\box,\csname}
105 % \DoNotIndex{\else,\endcsname,\endgroup,\endinput,\expandafter,\fi}
106 % \DoNotIndex{\TeX,\z@,\p@,\@one,\xdef,\thr@@,\string,\sixt@@n,\reset,\or,\multiply,\repeat,\RequirePackage}
107 % \DoNotIndex{\@cclvi,\@ne,\@ehpa,\@nil,\copy,\dp,\global,\hbox,\hss,\ht,\ifodd,\ifdim,\ifcase,\kern}
108 % \DoNotIndex{\chardef,\loop,\leavevmode,\ifnum,\lower,\next,\wd,\setbox}
109 % \setcounter{IndexColumns}{2}
110 %
111 % \title{\textsf{pst-blur} package \\ version \fileversion}
112 % \author{Martin Giese\thanks{\protect\url{[email protected]}}}
113 % \date{\filedate}
114 % \maketitle
115 %
116 %\section{Introduction}
117 % The ability to paint shadows on arbitrary shapes is a standard
118 % feature of PSTricks. However, these shadows are always `hard':\\
119 %{\psset{unit=0.6cm,linewidth=0.5pt}
120 % \begin{pspicture}(-5,0)(10,4)
121 % \psset{shadow=true,shadowcolor=gray,shadowsize=0.15cm}
122 % \psframe(1,1)(3,3)
123 % \pscircle(6,2){1}
124 % \rput(9,2){\pscharpath{\fontfamily{ptm}\fontsize{40}{40}\selectfont A}}
125 % \end{pspicture}
126 %}\\
127 % The |pst-blur| package provides blurred shadows
128 % for closed shapes drawn with PSTricks:\\
129 %{\psset{unit=0.6cm,linewidth=0.5pt,blur=true,blurradius=0.07cm}
130 % \begin{pspicture}(-5,0)(10,4)
131 % \psset{shadow=true,shadowcolor=gray,shadowsize=0.15cm}
132 % \psframe(1,1)(3,3)
133 % \pscircle(6,2){1}
134 % \rput(9,2){\pscharpath{\fontfamily{ptm}\fontsize{40}{40}\selectfont A}}
135 % \end{pspicture}
136 %}\\
137 % It also provides a new
138 % box command |\psblurbox|, which is similar to |\psshadowbox|,
139 % but gives the box a blurred shadow.
140 % \medskip
141 %
142 %The new graphics parameters and macros provided by the package
143 % are described in
144 %section 2 of this document. Section 3, if present, documents the
145 %implementation consisting of a generic \TeX\ file and a PostScript
146 %header for the |dvi|-to-PostScript converter. You can get section 3
147 %by calling \LaTeX\ as follows on most relevant systems:
148 %\begin{verbatim}
149 %latex '\AtBeginDocument{\AlsoImplementation}\input{pst-blur.dtx}'
150 %\end{verbatim}
151 %
152 %\section{Package Usage}
153 % To use |pst-blur|, you have to say
154 % \begin{verbatim}
155 % \usepackage{pst-blur}
156 % \end{verbatim}
157 % in the document prologue for \LaTeX, and
158 % \begin{verbatim}
159 % \input pst-blur.tex
160 % \end{verbatim}
161 % in ``plain'' \TeX.
162 %
163 % \DescribeMacro{blur}
164 % To paint shapes with blurred shadows,
165 % set the graphics parameters |shadow| and |blur| to |true|, eg
166 % \pscircle[shadow=true,blur=true](8,-0.5){0.5}
167 % \begin{verbatim}
168 % \psset{unit=1cm}
169 % \pscircle[shadow=true,blur=true](0,0){0.5}
170 % \end{verbatim}
171 % \psset{unit=1cm}
172 % for a circle with a blurred shadow.
173 % The parameter |blur| has no influence if |shadow| is |false|.
174 % \medskip
175 %
176 % \DescribeMacro{shadowsize}
177 % \DescribeMacro{shadowangle}
178 % \DescribeMacro{blurradius}
179 % The rendering of blurred shadows is controlled by a number of
180 % additional graphics parameters. The offset of the shadow is controlled
181 % by the parameters |shadowsize| and |shadowangle|, which are the same
182 % as for ordinary shadows.\footnote{In particular, |shadowangle| has
183 % to be negative for the usual placement of shadows below and to the
184 % right of shapes.} The size of the blurring effect is
185 % controlled by the parameter |blurradius|, see Fig~\ref{fig:params}.
186 % The default value for |blurradius| is 1.5pt, which fits nicely with
187 % the default |shadowsize| of 3pt.
188 % \medskip
189 %
190 % \begin{figure}\caption{Parameters for blurred shadows}
191 % \label{fig:params}
192 % \vskip1cm
193 % \qquad\qquad\begin{pspicture*}(0,0)(10,6)
194 % \psframe[linewidth=4pt,fillcolor=lightgray,fillstyle=crosshatch,
195 % shadow=true,blur=true,shadowsize=2cm,shadowangle=-35,
196 % blurradius=1cm,shadowcolor=lightgray](-5,3)(5,10)
197 % \pnode(5,3){A}
198 % \pnode(5.3,2.9){A1}
199 % \pnode(6.64,1.85){B}
200 % \pnode(7.51,2.35){C}
201 % \pscircle(6.64,1.85){1}
202 % \ncline{|-|}{A}{B}
203 % \bput(0.2){|shadowsize|}
204 % \ncline{->}{B}{C}
205 % \bput(1.5){|blurradius|}
206 % \psline(5,3)(6,3)
207 % \psarcn{->}(5,3){0.5}{0}{-35}
208 % \rput(7,3.7){\rnode{D}{$-|shadowangle|$}}
209 % \nccurve[linewidth=0.5pt,angleA=-90,angleB=70]{->}{D}{A1}
210 % \rput[l](6,5.6){|shadowcolor|}
211 % \rput[l](8,5){|blurbg|}
212 % {\psset{linestyle=dotted}
213 % \psline(0,0.85)(6.64,0.85)
214 % \psline(7.64,1.85)(7.64,6)
215 % \psset{linestyle=dashed}
216 % \psline(0,2.85)(5.64,2.85)
217 % \psline(5.64,2.85)(5.64,6)}
218 % {\psset{linewidth=0.5pt}
219 % \psline{*-}(5.64,5.3)(6,5.4)
220 % \psline{*-}(7.64,4.75)(8,4.85)
221 % \ncline{F}{F1}
222 % }
223 % \end{pspicture*}
224 % \end{figure}
225 %
226 % \DescribeMacro{shadowcolor}
227 % \DescribeMacro{blurbg}
228 % The inner, usually darkest part of the shadow is painted in the
229 % colour defined by |shadowcolor|. In the range defined by |blurradius|,
230 % the colour gradually fades to the background colour set by |blurbg|.
231 % The default value for |blurbg| is white. You should change this parameter
232 % when you want to paint shapes over a coloured background, ie\\
233 % \begin{minipage}{\textwidth}
234 % \begin{verbatim}
235 % \psframe[fillstyle=solid,fillcolor=yellow](-.7,-.7)(.7,.7)
236 % \pscircle[shadow=true,blur=true,blurbg=yellow](0,0){0.4}
237 % \end{verbatim}
238 % \rput(11.7,1.4){
239 % \psframe[fillstyle=solid,fillcolor=yellow](-.7,-.7)(.7,.7)
240 % \pscircle[shadow=true,blur=true,blurbg=yellow](0,0){0.4}}
241 % \end{minipage}
242 %
243 % \DescribeMacro{blursteps}
244 % The number of distinct colour steps painted between |shadowcolor|
245 % and |blurbg| is controlled by the parameter |blursteps|. The default
246 % value for |blursteps| is 20, which is usually more than sufficient.
247 % Note, that higher values for |blursteps| result in proportionally slower
248 % rendering. This can be very tiresome with complex shapes.
249 % \medskip
250 %
251 % \DescribeMacro{\psblurbox}
252 % Using a
253 % \psframebox[shadow=true,blur=true,blurradius=2.5pt,shadowcolor=gray]%
254 % {|\ttfamily\symbol{92}psframebox|}
255 % with a blurred
256 % shadow in the middle of some text produces poor results, because \TeX\
257 % does not know about the extra space taken by the shadow. For normal
258 % shadows, this problem is solved by the |\psshadowbox| macro, which
259 % adds the extra space around the box for the shadow. For blurred shadows,
260 % this is not sufficient: an extra |\blurradius| has to be added. This
261 % is done by the macro \psblurbox{\ttfamily\symbol{92}psblurbox}, which is otherwise
262 % identical to |\psshadowbox|. Note, that |\psblurbox| shares a
263 % deficiency of |\psshadowbox|: It only works correctly
264 % with $|shadowangle|=-45$, because \TeX\ does not provide trigonometric
265 % operations.
266 %
267 % \StopEventually{}
268 %
269 % \section{The Code}
270 %
271 % \subsection{The \file{pst-blur.sty} file}
272 % The \file{pst-blur.sty} file is very simple. It just loads
273 % the generic \file{pst-blur.tex} file.
274 % \begin{macrocode}
275 %<*stylefile>
276 \RequirePackage{pstricks}
277 \ProvidesPackage{pst-blur}[2005/09/08 package wrapper for
278 pst-blur.tex (hv)]
279 \input{pst-blur.tex}
280 \ProvidesFile{pst-blur.tex}
281 [\filedate\space v\fileversion\space `PST-blur' (hv)]
282 %</stylefile>
283 % \end{macrocode}
284 %
285 % \subsection{The \file{pst-blur.tex} file}
286 % \file{pst-blur.tex} contains the \TeX-side of things. We begin
287 % by identifying ourselves and setting things up, the same as in
288 % other PSTricks packages.
289 % \begin{macrocode}
290 %<*texfile>
291 \csname PstBlurLoaded\endcsname
292 \let\PstBlurLoaded\endinput
293 \ifx\PSTricksLoaded\endinput\else
294 \def\next{\input pstricks.tex }\expandafter\next
295 \fi
296 % \end{macrocode}
297 % \verb+pst-blur+ uses the extended version of the keyvalue interface.
298 % \begin{macrocode}
299 \ifx\PSTXKeyLoaded\endinput\else\input pst-xkey \fi
300 % \end{macrocode}
301 %%
302 % \begin{macrocode}
303 \def\fileversion{2.0}
304 \def\filedate{2005/09/08}
305 \message{ v\fileversion, \filedate}
306 \edef\TheAtCode{\the\catcode`\@}
307 \catcode`\@=11
308 % \end{macrocode}
309 % Add the package name to the list of family names of the keyvalue list.
310 % \begin{macrocode}
311 \pst@addfams{pst-blur}
312 \pstheader{pst-blur.pro}
313 % \end{macrocode}
314 %
315 % \subsubsection{New graphics parameters}
316 % \begin{macro}{blur}
317 % \begin{macro}{blurradius}
318 % \begin{macro}{blursteps}
319 % \begin{macro}{blurbg}
320 % The definitions of the new graphics parameters follow the definitions
321 % for parameters of the same types found in |pstricks.tex|.
322 % \begin{macrocode}
323 \newif\ifpsblur
324 \define@key[psset]{pst-blur}{blur}[true]{\@nameuse{psblur#1}\pst@setrepeatarrowsflag}
325 \psset{blur=false}
326 %%
327 \define@key[psset]{pst-blur}{blurradius}{\pst@getlength{#1}\psx@blurradius}
328 \psset{blurradius=1.5pt}
329 %%
330 \define@key[psset]{pst-blur}{blursteps}{\pst@getint{#1}\psx@blursteps}
331 \psset{blursteps=20}
332 %%
333 \define@key[psset]{pst-blur}{blurbg}{\pst@getcolor{#1}\psx@blurbg}
334 \psset{blurbg=white}
335 % \end{macrocode}
336 % \end{macro}
337 % \end{macro}
338 % \end{macro}
339 % \end{macro}
340 % \subsection{Hooking into the PSTricks shadow macros}
341 % \begin{macro}{\pst@closedshadow}
342 % The macro |\pst@closedshadow| is usually called internally by
343 % PSTricks to paint a shadow in the shape of the current path.
344 % This macro has been renamed |\pst@sharpclosedshadow|. The
345 % new |\pst@closedshadow| jumps to either of |\pst@sharpclosedshadow|
346 % or |\pst@blurclosedshadow|, depending on |\ifpsblur|, which is
347 % directly related to the graphics parameter |blur|.
348 % \begin{macrocode}
349 \def\pst@closedshadow{%
350 \ifpsblur\pst@blurclosedshadow\else\pst@sharpclosedshadow\fi
351 }
352 \def\pst@sharpclosedshadow{%
353 \addto@pscode{%
354 gsave
355 \psk@shadowsize \psk@shadowangle \tx@PtoC
356 \tx@Shadow
357 \pst@usecolor\psshadowcolor
358 gsave fill grestore
359 stroke
360 grestore
361 gsave
362 \pst@usecolor\psfillcolor
363 gsave fill grestore
364 stroke
365 grestore}}
366 % \end{macrocode}
367 % \end{macro}
368 % \begin{macro}{\pst@blurclosedshadow}
369 % The PostScript code for blurred shadows is produced by the following
370 % macro. It pushes the diverse parameters (|\tx@PtoC| does polar to
371 % cartesian coordinate transformation for the shadow offset) and calls
372 % |BlurShadow|. Afterwards, it fills and strokes the current path,
373 % same as the original |\pst@closedshadow|.
374 % \begin{macrocode}
375 \def\pst@blurclosedshadow{%
376 \addto@pscode{%
377 gsave
378 gsave \pst@usecolor\psshadowcolor currentrgbcolor grestore
379 gsave \pst@usecolor\psx@blurbg currentrgbcolor grestore
380 \psx@blurradius\space
381 \psx@blursteps\space
382 \psk@shadowsize \psk@shadowangle \tx@PtoC
383 tx@PstBlurDict begin BlurShadow end
384 grestore
385 gsave
386 \pst@usecolor\psfillcolor
387 gsave fill grestore
388 stroke
389 grestore}}
390 % \end{macrocode}
391 % \end{macro}
392 % \begin{macro}{\pst@blurclosedshadow}
393 % This one looks very impressing. In fact, it is a verbatim copy
394 % of |\psshadowbox|, with only the line
395 % |\advance\pst@dimh\psx@blurradius\p@| added!
396 % \begin{macrocode}
397 \def\psblurbox{%
398 \def\pst@par{}\pst@object{psblurbox}}
399 \def\psblurbox@i{\pst@makebox\psblurbox@ii}
400 \def\psblurbox@ii{%
401 \begingroup
402 \pst@useboxpar
403 \psblurtrue
404 \psshadowtrue
405 \psboxseptrue
406 \setbox\pst@hbox=\hbox{\psframebox@ii}%
407 \pst@dimh=\psk@shadowsize\p@
408 \pst@dimh=.7071\pst@dimh
409 \advance\pst@dimh\psx@blurradius\p@
410 \pst@dimg=\dp\pst@hbox
411 \advance\pst@dimg\pst@dimh
412 \dp\pst@hbox=\pst@dimg
413 \pst@dimg=\wd\pst@hbox
414 \advance\pst@dimg\pst@dimh
415 \wd\pst@hbox=\pst@dimg
416 \leavevmode
417 \box\pst@hbox
418 \endgroup}
419 %%
420 \catcode`\@=\TheAtCode\relax
421 %</texfile>
422 % \end{macrocode}
423 % \end{macro}
424 %
425 % \subsection{The \file{pst-blur.pro} file}
426 % The file \file{pst-blur.pro} contains PostScript definitions
427 % to be included in the PostScript output by the
428 % |dvi|-to-PostScript converter, eg |dvips|.
429 % This is all rather similar to
430 % \file{pst-slpe.pro}, and I just don't feel like explaining it,
431 % so you'll have to work through it yourself, if you want to
432 % know what happens. The trick is basically to draw the outline
433 % repeatedly with varying line widths. The procedure |Shadow|
434 % called in |BlurShadow| is defined in \file{pstricks.pro} and
435 % translates the current path based on an $x$- and $y$-displacement
436 % taken from the stack.
437 % \begin{macrocode}
438 %<*prolog>
439 /tx@PstBlurDict 60 dict def
440 tx@PstBlurDict begin
441 /Iterate {
442 /SegLines ED
443 /ThisB ED /ThisG ED /ThisR ED
444 /NextB ED /NextG ED /NextR ED
445 /W 2.0 BlurRadius mul def
446 /WDec W SegLines div def
447 /RInc NextR ThisR sub SegLines div def
448 /GInc NextG ThisG sub SegLines div def
449 /BInc NextB ThisB sub SegLines div def
450 /R ThisR def
451 /G ThisG def
452 /B ThisB def
453 SegLines {
454 R G B
455 sqrt 3 1 roll sqrt 3 1 roll sqrt 3 1 roll
456 setrgbcolor
457 gsave W setlinewidth
458 stroke grestore
459 /W W WDec sub def
460 /R R RInc add def
461 /G G GInc add def
462 /B B BInc add def
463 } bind repeat
464 } def
465 /BlurShadow {
466 Shadow
467 /BlurSteps ED
468 /BlurRadius ED
469 dup mul /BEnd ED dup mul /GEnd ED dup mul /REnd ED
470 dup mul /BBeg ED dup mul /GBeg ED dup mul /RBeg ED
471 RBeg REnd add 0.5 mul /RMid ED
472 GBeg GEnd add 0.5 mul /GMid ED
473 BBeg BEnd add 0.5 mul /BMid ED
474 /OuterSteps BlurSteps 2 div cvi def
475 /InnerSteps BlurSteps OuterSteps sub def
476 1 setlinejoin
477 RMid GMid BMid REnd GEnd BEnd OuterSteps Iterate
478 gsave RBeg sqrt GBeg sqrt BBeg sqrt setrgbcolor fill grestore
479 clip
480 0 setlinejoin
481 RMid GMid BMid RBeg GBeg BBeg InnerSteps Iterate
482 } def
483 end
484 %</prolog>
485 % \end{macrocode}
486 % \Finale
487 %