summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tcolorbox/tcbvignette.code.tex
blob: 51a4c9d6d054156106a752a798ac6dd53b33fa2e (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
%% The LaTeX package tcolorbox - version 6.3.0 (2024/07/10)
%% tcbvignette.code.tex: Code for ornamental frames
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2024 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `author-maintained'.
%%
%% This work consists of all files listed in README
%%
\tcb@set@library@version{6.3.0}

\tcbuselibrary{skins}

\usetikzlibrary{fadings}

\pgfdeclarehorizontalshading{tcb@fade@east}{100bp}
{color(0bp)=(pgftransparent!50); color(25bp)=(pgftransparent!50);
 color(75bp)=(pgftransparent!100); color(100bp)=(pgftransparent!100)}

\pgfdeclarehorizontalshading{tcb@fade@west}{100bp}
{color(0bp)=(pgftransparent!100); color(25bp)=(pgftransparent!100);
 color(75bp)=(pgftransparent!50); color(100bp)=(pgftransparent!50)}

\pgfdeclareverticalshading{tcb@fade@north}{100bp}
{color(0bp)=(pgftransparent!50); color(25bp)=(pgftransparent!50);
 color(75bp)=(pgftransparent!100); color(100bp)=(pgftransparent!100)}

\pgfdeclareverticalshading{tcb@fade@south}{100bp}
{color(0bp)=(pgftransparent!100); color(25bp)=(pgftransparent!100);
 color(75bp)=(pgftransparent!50); color(100bp)=(pgftransparent!50)}

\pgfdeclarefading{semi east}{\pgfuseshading{tcb@fade@east}}
\pgfdeclarefading{semi west}{\pgfuseshading{tcb@fade@west}}
\pgfdeclarefading{semi north}{\pgfuseshading{tcb@fade@north}}
\pgfdeclarefading{semi south}{\pgfuseshading{tcb@fade@south}}

\def\tcb@vig@draw@north#1{\path[#1]\pgfextra{%
  \pgfpathmoveto{\pgfqpoint{\tcb@vig@xA}{\tcb@vig@yB}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xB}{\tcb@vig@yB}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xb}{\tcb@vig@yb}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xa}{\tcb@vig@yb}}%
  \pgfpathclose};}

\def\tcb@vig@draw@east#1{\path[#1]\pgfextra{%
  \pgfpathmoveto{\pgfqpoint{\tcb@vig@xB}{\tcb@vig@yB}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xB}{\tcb@vig@yA}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xb}{\tcb@vig@ya}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xb}{\tcb@vig@yb}}%
  \pgfpathclose};}

\def\tcb@vig@draw@south#1{\path[#1]\pgfextra{%
  \pgfpathmoveto{\pgfqpoint{\tcb@vig@xB}{\tcb@vig@yA}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xA}{\tcb@vig@yA}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xa}{\tcb@vig@ya}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xb}{\tcb@vig@ya}}%
  \pgfpathclose};}

\def\tcb@vig@draw@west#1{\path[#1]\pgfextra{%
  \pgfpathmoveto{\pgfqpoint{\tcb@vig@xA}{\tcb@vig@yA}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xA}{\tcb@vig@yB}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xa}{\tcb@vig@yb}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xa}{\tcb@vig@ya}}%
  \pgfpathclose};}

\def\tcb@vig@draw@direct{%
  \ifdim\tcb@vig@yB>\tcb@vig@yb\relax%
    \begingroup\edef\x{\endgroup\noexpand\tcb@vig@draw@north{fill,draw=none,\expandonce\tcb@vig@style@north}}\x%
  \fi%
  \ifdim\tcb@vig@xB>\tcb@vig@xb\relax%
    \begingroup\edef\x{\endgroup\noexpand\tcb@vig@draw@east{fill,draw=none,\expandonce\tcb@vig@style@east}}\x%
  \fi%
  \ifdim\tcb@vig@yA<\tcb@vig@ya\relax%
    \begingroup\edef\x{\endgroup\noexpand\tcb@vig@draw@south{fill,draw=none,\expandonce\tcb@vig@style@south}}\x%
  \fi%
  \ifdim\tcb@vig@xA<\tcb@vig@xa\relax%
    \begingroup\edef\x{\endgroup\noexpand\tcb@vig@draw@west{fill,draw=none,\expandonce\tcb@vig@style@west}}\x%
  \fi%
}

\def\tcb@vig@draw@clipped{%
  \ifdim\tcb@vig@yB>\tcb@vig@yb\relax%
    \begin{scope}
    \tcb@vig@draw@north{clip}%
    \begingroup\edef\x{\endgroup\noexpand\path[fill,\expandonce\tcb@vig@style@north]}%
    \x\pgfextra{\pgfpathrectanglecorners{\pgfpoint{\tcb@vig@xA-1mm}{\tcb@vig@yb}}%
        {\pgfpoint{\tcb@vig@xB+1mm}{\tcb@vig@yB}}};
    \end{scope}
  \fi%
  \ifdim\tcb@vig@xB>\tcb@vig@xb\relax%
    \begin{scope}
    \tcb@vig@draw@east{clip}%
    \begingroup\edef\x{\endgroup\noexpand\path[fill,\expandonce\tcb@vig@style@east]}%
    \x\pgfextra{\pgfpathrectanglecorners{\pgfpoint{\tcb@vig@xb}{\tcb@vig@yA-1mm}}%
          {\pgfpoint{\tcb@vig@xB}{\tcb@vig@yB+1mm}}};
    \end{scope}
  \fi%
  \ifdim\tcb@vig@yA<\tcb@vig@ya\relax%
    \begin{scope}
    \tcb@vig@draw@south{clip}%
    \begingroup\edef\x{\endgroup\noexpand\path[fill,\expandonce\tcb@vig@style@south]}%
    \x\pgfextra{\pgfpathrectanglecorners{\pgfpoint{\tcb@vig@xA-1mm}{\tcb@vig@yA}}%
        {\pgfpoint{\tcb@vig@xB+1mm}{\tcb@vig@ya}}};
    \end{scope}
  \fi%
  \ifdim\tcb@vig@xA<\tcb@vig@xa\relax%
    \begin{scope}
    \tcb@vig@draw@west{clip}%
    \begingroup\edef\x{\endgroup\noexpand\path[fill,\expandonce\tcb@vig@style@west]}%
    \x\pgfextra{%
      \pgfpathrectanglecorners{\pgfpoint{\tcb@vig@xA}{\tcb@vig@yA-1mm}}%
        {\pgfpoint{\tcb@vig@xa}{\tcb@vig@yB+1mm}}};
    \end{scope}
  \fi%
}

\newcommand{\tcbvignette}[1]{%
  \ifdefined\pgfpictureid%
    \begingroup%
    \tcbset{vig/.cd,#1}%
    \tcbdimto\tcb@vig@xA{\tcb@vig@xmin}%
    \tcbdimto\tcb@vig@xB{\tcb@vig@xmax}%
    \tcbdimto\tcb@vig@yA{\tcb@vig@ymin}%
    \tcbdimto\tcb@vig@yB{\tcb@vig@ymax}%
    \tcbdimto\tcb@vig@xa{\tcb@vig@xA+\tcb@vig@size@west}%
    \tcbdimto\tcb@vig@xb{\tcb@vig@xB-(\tcb@vig@size@east)}%
    \tcbdimto\tcb@vig@ya{\tcb@vig@yA+\tcb@vig@size@south}%
    \tcbdimto\tcb@vig@yb{\tcb@vig@yB-(\tcb@vig@size@north)}%
    \begin{scope}[tcb@vig@scope]%
    \tcb@vig@draw%
    \end{scope}
    \endgroup%
  \else%
    \tcb@warning{'tcbvignette' was found outside a 'tikzpicture' environment and is ignored}%
  \fi%
}

\tcbset{%
  vig/.cd,
  xmin/.store in=\tcb@vig@xmin,
  xmax/.store in=\tcb@vig@xmax,
  ymin/.store in=\tcb@vig@ymin,
  ymax/.store in=\tcb@vig@ymax,
  lower left corner/.code={\tcb@gettikzxy{(#1)}{\tcb@vig@xmin}{\tcb@vig@ymin}},
  upper right corner/.code={\tcb@gettikzxy{(#1)}{\tcb@vig@xmax}{\tcb@vig@ymax}},
  %
  inside node/.style={lower left corner={#1.south west},upper right corner={#1.north east}},
  outside node/.style={lower left corner={[xshift=-\tcb@vig@size@west,yshift=-\tcb@vig@size@south]#1.south west},
    upper right corner={[xshift=\tcb@vig@size@east,yshift=\tcb@vig@size@north]#1.north east}},
  %
  on node/.style={lower left corner={#1.south west},upper right corner={#1.north east}},
  over node offset/.store in=\tcb@vig@onoffset,%
  over node/.style={lower left corner={[xshift=-\tcb@vig@onoffset,yshift=-\tcb@vig@onoffset]#1.south west},
    upper right corner={[xshift=\tcb@vig@onoffset,yshift=\tcb@vig@onoffset]#1.north east}},
  north size/.store in=\tcb@vig@size@north,
  south size/.store in=\tcb@vig@size@south,
  east size/.store in=\tcb@vig@size@east,
  west size/.store in=\tcb@vig@size@west,
  vertical size/.style={north size=#1,south size=#1},
  horizontal size/.style={east size=#1,west size=#1},
  size/.style={north size=#1,south size=#1,east size=#1,west size=#1},
  north style/.store in=\tcb@vig@style@north,
  south style/.store in=\tcb@vig@style@south,
  east style/.store in=\tcb@vig@style@east,
  west style/.store in=\tcb@vig@style@west,
  scope/.code={\tikzset{tcb@vig@scope/.style={#1}}},
  draw method/.is choice,
  draw method/direct/.code={\let\tcb@vig@draw\tcb@vig@draw@direct},%
  draw method/clipped/.code={\let\tcb@vig@draw\tcb@vig@draw@clipped},%
  base color/.colorlet=tcbcol@vig@base,
  raised color/.style={%
    base color=#1,
    north style={tcbcol@vig@base!50!white},
    east style={tcbcol@vig@base!75!black},
    south style={tcbcol@vig@base!50!black},
    west style={tcbcol@vig@base!75!white},
  },
  lowered color/.style={%
    base color=#1,
    north style={tcbcol@vig@base!50!black},
    east style={tcbcol@vig@base!75!white},
    south style={tcbcol@vig@base!50!white},
    west style={tcbcol@vig@base!75!black},
  },
  color from/.style args={#1 to #2}{%
    north style={bottom color=#1,top color=#2},
    east style={left color=#1,right color=#2},
    south style={top color=#1,bottom color=#2},
    west style={right color=#1,left color=#2},
  },
  fade in/.style={%
    north style={#1,path fading=south},
    east style={#1,path fading=west},
    south style={#1,path fading=north},
    west style={#1,path fading=east},
  },
  fade in/.default=white,
  fade out/.style={%
    north style={#1,path fading=north},
    east style={#1,path fading=east},
    south style={#1,path fading=south},
    west style={#1,path fading=west},
  },
  fade out/.default=white,
  semi fade in/.style={%
    north style={#1,path fading=semi south},
    east style={#1,path fading=semi west},
    south style={#1,path fading=semi north},
    west style={#1,path fading=semi east},
  },
  semi fade in/.default=white,
  semi fade out/.style={%
    north style={#1,path fading=semi north},
    east style={#1,path fading=semi east},
    south style={#1,path fading=semi south},
    west style={#1,path fading=semi west},
  },
  semi fade out/.default=white,
  %
  scope=,
  draw method=direct,
  xmin=0pt,
  xmax=1cm,
  ymin=0pt,
  ymax=1cm,
  size=2mm,
  over node offset=0.1mm,
  raised color=red,
}

\tcbset{%
  finish@vignette/.style 2 args={finish #1={%
    \begin{tcbclipframe}\tcbvignette{%
      scope={transparency group,opacity=0.25},
      north style=white,
      east style=black!75,
      south style=black,
      west style=black!25,#2,inside node=frame
      }\end{tcbclipframe}}},
  finish vignette/.style={%
    finish@vignette={unbroken}{#1},%
    finish@vignette={first}{#1,south size=0pt},%
    finish@vignette={middle}{#1,north size=0pt,south size=0pt},%
    finish@vignette={last}{#1,north size=0pt}%
  },
%
  finish@raised@vignette/.style 2 args={finish #1={%
    \begin{tcbclipframe}\tcbvignette{%
      draw method=clipped,
      north style={white,path fading=semi south},
      east style={black!75,path fading=semi west},
      south style={black,path fading=semi north},
      west style={black!25,path fading=semi east},#2,inside node=frame
      }\end{tcbclipframe}}},
  finish raised fading vignette/.style={%
    finish@raised@vignette={unbroken}{#1},%
    finish@raised@vignette={first}{#1,south size=0pt},%
    finish@raised@vignette={middle}{#1,north size=0pt,south size=0pt},%
    finish@raised@vignette={last}{#1,north size=0pt}%
  },
%
  finish@fading@vignette/.style 2 args={finish #1={%
    \tcbvignette{%
      draw method=clipped,fade in=tcbcol@vig@base,#2,over node=frame}}},
  finish fading vignette/.style={%
    finish@fading@vignette={unbroken}{base color=white,#1},%
    finish@fading@vignette={first}{base color=white,#1,south size=0pt},%
    finish@fading@vignette={middle}{base color=white,#1,north size=0pt,south size=0pt},%
    finish@fading@vignette={last}{base color=white,#1,north size=0pt}%
  },
%
  underlay@vignette/.style 2 args={underlay #1={%
    \begin{tcbclipframe}\tcbvignette{%
      raised color=tcbcolframe,
      north size=\kvtcb@top@rule@stand,
      south size=\kvtcb@bottom@rule@stand,
      west size=\kvtcb@left@rule,
      east size=\kvtcb@right@rule,#2,inside node=frame
      }\end{tcbclipframe}}},
  underlay vignette/.style={%
    underlay@vignette={unbroken}{#1},%
    underlay@vignette={first}{#1,south size=0pt},%
    underlay@vignette={middle}{#1,north size=0pt,south size=0pt},%
    underlay@vignette={last}{#1,north size=0pt}%
  },
%
  underlay@fading@vignette/.style 2 args={underlay #1={%
    \begin{tcbclipframe}\tcbvignette{%
      draw method=clipped,
      north style={white,path fading=semi south},
      east style={black!75,path fading=semi west},
      south style={black,path fading=semi north},
      west style={black!25,path fading=semi east},#2,inside node=frame,
      }\end{tcbclipframe}}},
  underlay raised fading vignette/.style={%
    underlay@fading@vignette={unbroken}{#1},%
    underlay@fading@vignette={first}{#1,south size=0pt},%
    underlay@fading@vignette={middle}{#1,north size=0pt,south size=0pt},%
    underlay@fading@vignette={last}{#1,north size=0pt}%
  },
  %
  underlay raised shading vignette/.style={%
    underlay vignette={draw method=clipped,
      north style={bottom color=tcbcolframe,top color=tcbcolframe!33!white},
      east style={left color=tcbcolframe,right color=tcbcolframe!66!black},
      south style={top color=tcbcolframe,bottom color=tcbcolframe!33!black},
      west style={right color=tcbcolframe,left color=tcbcolframe!66!white},#1}},
  %
  underlay shade in vignette/.style={%
    underlay vignette={draw method=clipped,color from=tcbcolback to tcbcolframe,#1}},
}