Debian Codegraph @

texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransparency.code.tex

raw
1 % Copyright 2018 by Till Tantau
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 \ProvidesFileRCS{pgfcoretransparency.code.tex}
11
12
13 % Sets the opacity of stroking operations.
14 %
15 % #1 = opacity, where 1 means fully opaque and 0 means fully
16 % transparent.
17 %
18 % Example:
19 %
20 % \pgfsetstrokeopacity{0.5}
21
22 \def\pgfsetstrokeopacity#1{%
23 \pgfmathparse{#1}%
24 \expandafter\pgfsys@stroke@opacity\expandafter{\pgfmathresult}}
25
26
27 % Sets the opacity of stroking operations.
28 %
29 % #1 = opacity, where 1 means fully opaque and 0 means fully
30 % transparent.
31 %
32 % Example:
33 %
34 % \pgfsetfillopacity{0.5}
35
36 \def\pgfsetfillopacity#1{%
37 \pgfmathparse{#1}%
38 \expandafter\pgfsys@fill@opacity\expandafter{\pgfmathresult}}
39
40
41
42 % Sets the current blend mode. See Section 7.2.4 of the PDF
43 % Specification 1.7 for an introduction to blend modes in general.
44 %
45 % #1 = One of the following modes, see also section 7.2.4 of the
46 % PDF Specification 1.7. (The PGF names, which are all lowercase with
47 % spaces as usual, must be mapped to the PDF or SVG by the drivers.)
48 %
49 % normal
50 % multiply
51 % screen
52 % overlay
53 % darken
54 % lighten
55 % color dodge
56 % color burn
57 % hard light
58 % soft light
59 % difference
60 % exclusion
61 % saturation
62 % color
63 % hue
64 % luminosity
65 %
66 % Example:
67 %
68 % \pgfsetblendmode{multiply}
69
70 \def\pgfsetblendmode#1{\pgfsys@blend@mode{#1}}
71
72
73 % Declares a new fading based on the contents of a box.
74 %
75 % #1 = name of the fading
76 % #2 = content of a TeX box that specifies the fading
77 %
78 % Description:
79 %
80 % This command declares a new fading based on the contents of
81 % the TeX box. The mask can later be used to mask other graphics.
82 %
83 % The box is used to determine where the mask is opaque: At the
84 % beginning, the mask is completely transparent. Wherever the box
85 % contains something (like text or a picture or whatever), the
86 % luminosity of the text/graphic is used to determine how opaque the
87 % point will be. The greater the luminosity, the more opaque. The net
88 % effect is that white corresponds to "completely opaque" and black to
89 % "completely transparent". This is rather counterintuitive. Because
90 % of this, the special color "pgftransparent" is defined, which is the
91 % same as black. By setting the color to, say,
92 % \color{pgftransparent!10} you get something that is 10% transparent
93 % and \color{pgftransparent!90} gives you 90% transparency.
94 %
95 % By default, the drawing color is set to opaque.
96 %
97 % Example:
98 %
99 % \pgfdeclarefading{mymask}{
100 % \fontsize{200}{200}\bfseries
101 % Ti\emph{k}Z
102 % }
103 % \pgfdeclarefading{myothermask}{
104 % \tikz \shade [left color=transparent,right color=transparent!0]
105 % (0,0) rectangle (5,5);
106 % }
107
108 \def\pgfdeclarefading#1#2{%
109 \setbox\pgfutil@tempboxa=\hbox{{\pgfsys@beginscope\pgfutil@color{white}\ignorespaces#2\pgfsys@endscope}}%
110 \pgfsys@fadingfrombox{#1}\pgfutil@tempboxa%
111 }
112
113 \pgfutil@colorlet{pgftransparent}{black}
114
115
116 % Use a previously declared fading.
117 %
118 % #1 = name of the fading
119 % #2 = transformation code
120 %
121 % Description:
122 %
123 % The command should be used *inside* a pgfpicture to install a
124 % fading. The fading is a part of the graphic state. (This command
125 % works much like \pgfsetstrokeopacity).
126 %
127 % The mask will be centered on the origin. The transformation code #2 is
128 % applied to the mask (but not the contents of the actual picture).
129
130 \def\pgfsetfading#1#2{%
131 {%
132 \pgftransformreset%
133 #2%
134 \pgfgettransform{\pgftrans@temp}%
135 \edef\pgf@marshal{\noexpand\pgfsys@usefading{#1}\pgftrans@temp}%
136 \pgf@marshal%
137 }%
138 }
139
140
141
142 % Use a previously declared fading scaled for the current path.
143 %
144 % #1 - an fading
145 % #2 - extra transformations
146 %
147 % Description:
148 %
149 % This command works a bit like \pgfshadepath. "Works a bit like"
150 % means the following: The masks's original size should
151 % completely cover the area between (0,0) and (100bp,100bp). The
152 % mask is then rescaled so that it completely covers the path. Then
153 % the additional transformation #2 is applied. Finally, the mask is
154 % made part of the graphic state (as with \pgfsetfading). The path
155 % used for computation purposes only -- it is not drawn or otherwise
156 % used.
157 %
158 % If no transformations occur, the lower left corner of the path will
159 % lie on (25bp, 25bp), the upper right corner on (75bp, 75bp).
160 %
161 % If the path was empty, the fading will be used at its natural size,
162 % centered on the origin.
163 %
164 % Example:
165 %
166 % \pgfdeclarefading{fade right}
167 % {\tikz[left color=transparent!0,right color=transparent!100]
168 % (0,0) rectangle (100bp,100bp);}
169 %
170 % \pgfpathmoveto{\pgforigin}
171 % \pgfpathlineto{\pgfxy(1,0)}
172 % \pgfpathlineto{\pgfxy(1,1)}
173 % \pgfsetfadingforcurrentpath{fade right}{}
174 % \pgfusepath{fill}
175
176 \def\pgfsetfadingforcurrentpath#1#2{%
177 \ifdim\pgf@pathminx=16000pt%
178 % Path was empty -> use natural size
179 \pgfsetfading{#1}{#2}%
180 \else%
181 \pgfsetfading{#1}{%
182 % Calculate center:
183 \pgf@xb=.5\pgf@pathmaxx%
184 \advance\pgf@xb by.5\pgf@pathminx%
185 \pgf@yb=.5\pgf@pathmaxy%
186 \advance\pgf@yb by.5\pgf@pathminy%
187 % Calculate scaling:
188 \pgf@xc=\pgf@pathmaxx%
189 \advance\pgf@xc by-\pgf@pathminx%
190 \ifdim\pgf@xc<0.1pt\pgf@xc=0.1pt\fi%
191 \pgf@yc=\pgf@pathmaxy%
192 \advance\pgf@yc by-\pgf@pathminy%
193 \ifdim\pgf@yc<0.1pt\pgf@yc=0.1pt\fi%
194 \pgf@xc=.02\pgf@xc%
195 \pgf@yc=.02\pgf@yc%
196 % Compute new transformation matrix:
197 \pgftransformcm{1}{0}{0}{1}{\pgfqpoint{\pgf@xb}{\pgf@yb}}%
198 \pgftransformcm{\pgf@sys@tonumber{\pgf@xc}}{0}{0}{\pgf@sys@tonumber{\pgf@yc}}{\pgfpointorigin}%
199 \pgfsys@clipfading%
200 #2%
201 }%
202 \fi%
203 }
204
205
206
207
208 % Use a previously declared fading scaled for the current path.
209 %
210 % #1 - an fading
211 % #2 - extra transformations
212 %
213 % Description:
214 %
215 % This command works like \pgfsetfadingforcurrentpath, only it takes
216 % the current line width into account: Before the path is considered,
217 % it is enlarged by half the line width in all directions.
218
219 \def\pgfsetfadingforcurrentpathstroked#1#2{%
220 \ifdim\pgf@pathminx=16000pt%
221 % Path was empty -> use natural size
222 \pgfsetfading{#1}{#2}%
223 \else%
224 \pgfsetfading{#1}{%
225 % Calculate center:
226 \pgf@xb=.5\pgf@pathmaxx%
227 \advance\pgf@xb by.5\pgf@pathminx%
228 \pgf@yb=.5\pgf@pathmaxy%
229 \advance\pgf@yb by.5\pgf@pathminy%
230 % Calculate scaling:
231 \pgf@xc=\pgf@pathmaxx%
232 \advance\pgf@xc by-\pgf@pathminx%
233 \advance\pgf@xc by\pgflinewidth%
234 \ifdim\pgf@xc<0.1pt\pgf@xc=0.1pt\fi%
235 \pgf@yc=\pgf@pathmaxy%
236 \advance\pgf@yc by-\pgf@pathminy%
237 \advance\pgf@yc by\pgflinewidth%
238 \ifdim\pgf@yc<0.1pt\pgf@yc=0.1pt\fi%
239 \pgf@xc=.02\pgf@xc%
240 \pgf@yc=.02\pgf@yc%
241 % Compute new transformation matrix:
242 \pgftransformcm{1}{0}{0}{1}{\pgfqpoint{\pgf@xb}{\pgf@yb}}%
243 \pgftransformcm{\pgf@sys@tonumber{\pgf@xc}}{0}{0}{\pgf@sys@tonumber{\pgf@yc}}{\pgfpointorigin}%
244 \pgfsys@clipfading%
245 #2%
246 }%
247 \fi%
248 }
249
250
251 % Group things in a a transparency group
252 %
253 % Description:
254 %
255 % This takes groups pgf commands inside a pgfpicture in a transparency
256 % group. This means that any transparency settings apply to commands a
257 % whole. For instance, if a box contains two overlapping black
258 % circles and you draw them normally with 50% transparency, then the
259 % overlap will be darker than the rest. By comparison, if the circles
260 % are part of a transparency group, the overlap will get the same
261 % color as the rest.
262 %
263 %
264
265 \def\pgftransparencygroup{%
266 \pgfutil@ifnextchar[{\pgftransparencygroup@}{\pgftransparencygroup@[]}%
267 }
268 \def\pgftransparencygroup@[#1]{%
269 \begingroup%
270 \pgfkeys{/pgf/transparency group options/.cd,%
271 isolated=false,
272 knockout=false,
273 #1}%
274 \setbox\pgfutil@tempboxa=\hbox\bgroup%
275 }
276 \pgfkeys{
277 /pgf/transparency group options/.cd,
278 isolated/.is if=pgfsys@transparency@group@isolated,
279 knockout/.is if=pgfsys@transparency@group@knockout
280 }
281
282 \def\endpgftransparencygroup{%
283 \egroup%
284 % Now compute the correct position. This is a bit tricky...
285 \ifdim\pgf@picminx=16000pt%
286 % Nothing needs to be done
287 \else%
288 % Safety margin to avoid clipping:
289 \advance\pgf@picminx by-1cm%
290 \advance\pgf@picmaxx by1cm%
291 \advance\pgf@picminy by-1cm%
292 \advance\pgf@picmaxy by1cm%
293 % Ok, set the box size to current picture size.
294 \setbox\pgfutil@tempboxa=\hbox{%
295 \vrule width0pt height\pgf@picmaxy depth-\pgf@picminy%
296 \hskip-\pgf@picminx%
297 \box\pgfutil@tempboxa%
298 \hskip\pgf@picmaxx%
299 }%
300 \pgfsys@transparencygroupfrombox\pgfutil@tempboxa%
301 \wd\pgfutil@tempboxa=0pt%
302 \ht\pgfutil@tempboxa=0pt%
303 \dp\pgfutil@tempboxa=0pt%
304 \hskip\pgf@picminx\box\pgfutil@tempboxa\hskip-\pgf@picminx%
305 \fi%
306 \endgroup%
307 }
308
309 \let\startpgftransparencygroup=\pgftransparencygroup
310 \let\stoppgftransparencygroup=\endpgftransparencygroup
311
312 \endinput