| 1 |
% Copyright 2019 by Till Tantau |
| 2 |
% CMYK and grayscale shadings adaptation copyright 2019 by David Purton |
| 3 |
% |
| 4 |
% This file may be distributed and/or modified |
| 5 |
% |
| 6 |
% 1. under the LaTeX Project Public License and/or |
| 7 |
% 2. under the GNU Public License. |
| 8 |
% |
| 9 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 10 |
|
| 11 |
\ProvidesFileRCS{pgfcoreshade.code.tex} |
| 12 |
|
| 13 |
% |
| 14 |
% Parsing functions |
| 15 |
% |
| 16 |
\newdimen\pgf@max |
| 17 |
\newcount\pgf@sys@shading@range@num |
| 18 |
\def\pgf@parsefunc#1{% |
| 19 |
\edef\temp{{#1}}% |
| 20 |
\expandafter\pgf@convertstring\temp% |
| 21 |
\edef\temp{{\pgf@conv}}% |
| 22 |
\expandafter\pgf@@parsefunc\temp} |
| 23 |
\def\pgf@@parsefunc#1{% |
| 24 |
\let\pgf@bounds=\pgfutil@empty% |
| 25 |
\let\pgf@funcs=\pgfutil@empty% |
| 26 |
\let\pgf@psfuncs=\pgfutil@empty% |
| 27 |
\let\pgf@encode=\pgfutil@empty% |
| 28 |
\let\pgf@sys@shading@ranges=\pgfutil@empty% |
| 29 |
\pgf@sys@shading@range@num=0\relax% |
| 30 |
\csname pgf@parsefirst\pgf@shading@model\endcsname[#1; ]% |
| 31 |
\csname pgf@parselastdom\pgf@shading@model\endcsname[#1; ]% |
| 32 |
\csname pgf@parsemid\pgf@shading@model\endcsname[#1; ]% |
| 33 |
\ifx\pgf@bounds\pgfutil@empty% |
| 34 |
\edef\pgf@pdfparseddomain{0 1}% |
| 35 |
\edef\pgf@pdfparsedfunction{\pgf@singlefunc\space}% |
| 36 |
\else% |
| 37 |
\edef\pgf@pdfparseddomain{\pgf@doma\space\pgf@domb}% |
| 38 |
\edef\pgf@pdfparsedfunction{% |
| 39 |
<< /FunctionType 3 /Domain [\pgf@doma\space\pgf@domb] /Functions |
| 40 |
[\pgf@funcs\space] /Bounds [\pgf@bounds] /Encode [0 1 \pgf@encode] |
| 41 |
>> }% << |
| 42 |
\fi% |
| 43 |
\xdef\pgf@psfuncs{\pgf@psfuncs}% |
| 44 |
} |
| 45 |
\def\pgf@parsefirstrgb[rgb(#1)=(#2,#3,#4)#5]{% |
| 46 |
\pgfmathsetlength\pgf@x{#1}% |
| 47 |
\edef\pgf@sys@shading@start@pos{\the\pgf@x}% |
| 48 |
\pgf@sys@bp@correct\pgf@x% |
| 49 |
\edef\pgf@doma{\pgf@sys@tonumber{\pgf@x}}% |
| 50 |
\edef\pgf@prevx{\pgf@sys@tonumber{\pgf@x}}% |
| 51 |
\pgf@getrgbtuplewithmixin{#2}{#3}{#4}% |
| 52 |
\edef\pgf@sys@shading@start@rgb{\pgf@sys@rgb}% |
| 53 |
\let\pgf@sys@prevcolor=\pgf@sys@shading@start@rgb% |
| 54 |
\let\pgf@sys@prevpos=\pgf@sys@shading@start@pos% |
| 55 |
\edef\pgf@prevcolor{\pgf@rgb}% |
| 56 |
\edef\pgf@firstcolor{\pgf@rgb}} |
| 57 |
\def\pgf@parselastdomrgb[rgb(#1)=(#2,#3,#4); {% |
| 58 |
\pgfutil@ifnextchar]{% |
| 59 |
\pgfmathsetlength\pgf@x{#1}% |
| 60 |
\edef\pgf@sys@shading@end@pos{\the\pgf@x}% |
| 61 |
\pgf@max=\pgf@x\relax% |
| 62 |
\pgf@sys@bp@correct\pgf@x% |
| 63 |
\edef\pgf@domb{\pgf@sys@tonumber{\pgf@x}}% |
| 64 |
\pgf@getrgbtuplewithmixin{#2}{#3}{#4}% |
| 65 |
\edef\pgf@sys@shading@end@rgb{\pgf@sys@rgb}% |
| 66 |
\pgfutil@gobble}{\pgf@parselastdomrgb[}} |
| 67 |
\def\pgf@parsemidrgb[rgb(#1)=(#2,#3,#4); {\pgf@parserestrgb[} |
| 68 |
\def\pgf@parserestrgb[rgb(#1)=(#2,#3,#4); {% |
| 69 |
\advance\pgf@sys@shading@range@num by1\relax% |
| 70 |
\pgfutil@ifnextchar]{% |
| 71 |
\pgf@getrgbtuplewithmixin{#2}{#3}{#4}% |
| 72 |
\edef\pgf@singlefunc{\space% |
| 73 |
<< /FunctionType 2 /Domain [0 1] /C0 |
| 74 |
[\pgf@prevcolor] /C1 [\pgf@rgb] /N 1 >> }% << |
| 75 |
\edef\pgf@funcs{\pgf@funcs\space% |
| 76 |
<< /FunctionType 2 /Domain [\pgf@doma\space\pgf@domb] /C0 |
| 77 |
[\pgf@prevcolor] /C1 [\pgf@rgb] /N 1 >> }% << |
| 78 |
\edef\pgf@psfuncs{\pgf@prevx\space \pgf@rgb\space \pgf@prevcolor\space pgfshade \pgf@psfuncs}% |
| 79 |
\pgfmathsetlength\pgf@x{#1}% |
| 80 |
\edef\pgf@sys@shading@ranges{\pgf@sys@shading@ranges{{\pgf@sys@prevpos}{\the\pgf@x}{\pgf@sys@prevcolor}{\pgf@sys@rgb}}}% |
| 81 |
\edef\pgf@sys@prevpos{\the\pgf@x}% |
| 82 |
\let\pgf@sys@prevcolor=\pgf@sys@rgb% |
| 83 |
\pgfutil@gobble}{% |
| 84 |
\pgfmathsetlength\pgf@x{#1}% |
| 85 |
\pgf@getrgbtuplewithmixin{#2}{#3}{#4}% |
| 86 |
\edef\pgf@sys@shading@ranges{\pgf@sys@shading@ranges{{\pgf@sys@prevpos}{\the\pgf@x}{\pgf@sys@prevcolor}{\pgf@sys@rgb}}}% |
| 87 |
\edef\pgf@sys@prevpos{\the\pgf@x}% |
| 88 |
\let\pgf@sys@prevcolor=\pgf@sys@rgb% |
| 89 |
\edef\pgf@psfuncs{\pgf@prevx\space \pgf@rgb\space \pgf@prevcolor\space pgfshade \pgf@psfuncs}% |
| 90 |
\pgf@sys@bp@correct\pgf@x% |
| 91 |
\edef\pgf@prevx{\pgf@sys@tonumber{\pgf@x}}% |
| 92 |
\edef\pgf@bounds{\pgf@bounds\space\pgf@sys@tonumber{\pgf@x}}% |
| 93 |
\edef\pgf@encode{\pgf@encode\space0 1}% |
| 94 |
\edef\pgf@singlefunc{\space% |
| 95 |
<< /FunctionType 2 /Domain [0 1] /C0 |
| 96 |
[\pgf@prevcolor] /C1 [\pgf@rgb] /N 1 >> }% << |
| 97 |
\edef\pgf@funcs{\pgf@funcs\space% |
| 98 |
<< /FunctionType 2 /Domain [\pgf@doma\space\pgf@domb] /C0 |
| 99 |
[\pgf@prevcolor] /C1 [\pgf@rgb] /N 1 >> }% << |
| 100 |
\edef\pgf@prevcolor{\pgf@rgb}% |
| 101 |
\pgf@parserestrgb[}} |
| 102 |
|
| 103 |
\def\pgf@getrgbtuplewithmixin#1#2#3{% |
| 104 |
\pgfutil@definecolor{pgfshadetemp}{rgb}{#1,#2,#3}% |
| 105 |
\pgfutil@ifundefined{applycolormixins}{}{\applycolormixins{pgfshadetemp}}% |
| 106 |
\pgfutil@extractcolorspec{pgfshadetemp}{\pgf@tempcolor}% |
| 107 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}% |
| 108 |
\expandafter\pgf@getrgb@@\pgf@rgbcolor!} |
| 109 |
\def\pgf@getrgb@@#1,#2,#3!{% |
| 110 |
\def\pgf@rgb{#1 #2 #3}% |
| 111 |
\def\pgf@sys@rgb{{#1}{#2}{#3}}% |
| 112 |
} |
| 113 |
|
| 114 |
\def\pgf@parsefirstcmyk[cmyk(#1)=(#2,#3,#4,#5)#6]{% |
| 115 |
\pgfmathsetlength\pgf@x{#1}% |
| 116 |
\edef\pgf@sys@shading@start@pos{\the\pgf@x}% |
| 117 |
\pgf@sys@bp@correct\pgf@x% |
| 118 |
\edef\pgf@doma{\pgf@sys@tonumber{\pgf@x}}% |
| 119 |
\edef\pgf@prevx{\pgf@sys@tonumber{\pgf@x}}% |
| 120 |
\pgf@getcmyktuplewithmixin{#2}{#3}{#4}{#5}% |
| 121 |
\edef\pgf@sys@shading@start@cmyk{\pgf@sys@cmyk}% |
| 122 |
\let\pgf@sys@prevcolor=\pgf@sys@shading@start@cmyk% |
| 123 |
\let\pgf@sys@prevpos=\pgf@sys@shading@start@pos% |
| 124 |
\edef\pgf@prevcolor{\pgf@cmyk}% |
| 125 |
\edef\pgf@firstcolor{\pgf@cmyk}} |
| 126 |
\def\pgf@parselastdomcmyk[cmyk(#1)=(#2,#3,#4,#5); {% |
| 127 |
\pgfutil@ifnextchar]{% |
| 128 |
\pgfmathsetlength\pgf@x{#1}% |
| 129 |
\edef\pgf@sys@shading@end@pos{\the\pgf@x}% |
| 130 |
\pgf@max=\pgf@x\relax% |
| 131 |
\pgf@sys@bp@correct\pgf@x% |
| 132 |
\edef\pgf@domb{\pgf@sys@tonumber{\pgf@x}}% |
| 133 |
\pgf@getcmyktuplewithmixin{#2}{#3}{#4}{#5}% |
| 134 |
\edef\pgf@sys@shading@end@cmyk{\pgf@sys@cmyk}% |
| 135 |
\pgfutil@gobble}{\pgf@parselastdomcmyk[}} |
| 136 |
\def\pgf@parsemidcmyk[cmyk(#1)=(#2,#3,#4,#5); {\pgf@parserestcmyk[} |
| 137 |
\def\pgf@parserestcmyk[cmyk(#1)=(#2,#3,#4,#5); {% |
| 138 |
\advance\pgf@sys@shading@range@num by1\relax% |
| 139 |
\pgfutil@ifnextchar]{% |
| 140 |
\pgf@getcmyktuplewithmixin{#2}{#3}{#4}{#5}% |
| 141 |
\edef\pgf@singlefunc{\space% |
| 142 |
<< /FunctionType 2 /Domain [0 1] /C0 |
| 143 |
[\pgf@prevcolor] /C1 [\pgf@cmyk] /N 1 >> }% << |
| 144 |
\edef\pgf@funcs{\pgf@funcs\space% |
| 145 |
<< /FunctionType 2 /Domain [\pgf@doma\space\pgf@domb] /C0 |
| 146 |
[\pgf@prevcolor] /C1 [\pgf@cmyk] /N 1 >> }% << |
| 147 |
\edef\pgf@psfuncs{\pgf@prevx\space |
| 148 |
\pgf@cmyk\space \pgf@prevcolor\space pgfshade \pgf@psfuncs}% |
| 149 |
\pgfmathsetlength\pgf@x{#1}% |
| 150 |
\edef\pgf@sys@shading@ranges{\pgf@sys@shading@ranges{% |
| 151 |
{\pgf@sys@prevpos}{\the\pgf@x}{\pgf@sys@prevcolor}{\pgf@sys@cmyk}}}% |
| 152 |
\edef\pgf@sys@prevpos{\the\pgf@x}% |
| 153 |
\let\pgf@sys@prevcolor=\pgf@sys@cmyk% |
| 154 |
\pgfutil@gobble}{% |
| 155 |
\pgfmathsetlength\pgf@x{#1}% |
| 156 |
\pgf@getcmyktuplewithmixin{#2}{#3}{#4}{#5}% |
| 157 |
\edef\pgf@sys@shading@ranges{\pgf@sys@shading@ranges{% |
| 158 |
{\pgf@sys@prevpos}{\the\pgf@x}{\pgf@sys@prevcolor}{\pgf@sys@cmyk}}}% |
| 159 |
\edef\pgf@sys@prevpos{\the\pgf@x}% |
| 160 |
\let\pgf@sys@prevcolor=\pgf@sys@cmyk% |
| 161 |
\edef\pgf@psfuncs{\pgf@prevx\space \pgf@cmyk\space |
| 162 |
\pgf@prevcolor\space pgfshade \pgf@psfuncs}% |
| 163 |
\pgf@sys@bp@correct\pgf@x% |
| 164 |
\edef\pgf@prevx{\pgf@sys@tonumber{\pgf@x}}% |
| 165 |
\edef\pgf@bounds{\pgf@bounds\space\pgf@sys@tonumber{\pgf@x}}% |
| 166 |
\edef\pgf@encode{\pgf@encode\space0 1}% |
| 167 |
\edef\pgf@singlefunc{\space% |
| 168 |
<< /FunctionType 2 /Domain [0 1] /C0 |
| 169 |
[\pgf@prevcolor] /C1 [\pgf@cmyk] /N 1 >> }% << |
| 170 |
\edef\pgf@funcs{\pgf@funcs\space% |
| 171 |
<< /FunctionType 2 /Domain [\pgf@doma\space\pgf@domb] /C0 |
| 172 |
[\pgf@prevcolor] /C1 [\pgf@cmyk] /N 1 >> }% << |
| 173 |
\edef\pgf@prevcolor{\pgf@cmyk}% |
| 174 |
\pgf@parserestcmyk[}} |
| 175 |
|
| 176 |
\def\pgf@getcmyktuplewithmixin#1#2#3#4{% |
| 177 |
\pgfutil@definecolor{pgfshadetemp}{cmyk}{#1,#2,#3,#4}% |
| 178 |
\pgfutil@ifundefined{applycolormixins}{}{\applycolormixins{pgfshadetemp}}% |
| 179 |
\pgfutil@extractcolorspec{pgfshadetemp}{\pgf@tempcolor}% |
| 180 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{cmyk}{\pgf@cmykcolor}% |
| 181 |
\expandafter\pgf@getcmyk@@\pgf@cmykcolor!} |
| 182 |
\def\pgf@getcmyk@@#1,#2,#3,#4!{% |
| 183 |
\def\pgf@cmyk{#1 #2 #3 #4}% |
| 184 |
\def\pgf@sys@cmyk{{#1}{#2}{#3}{#4}}% |
| 185 |
} |
| 186 |
|
| 187 |
\def\pgf@parsefirstgray[gray(#1)=(#2)#3]{% |
| 188 |
\pgfmathsetlength\pgf@x{#1}% |
| 189 |
\edef\pgf@sys@shading@start@pos{\the\pgf@x}% |
| 190 |
\pgf@sys@bp@correct\pgf@x% |
| 191 |
\edef\pgf@doma{\pgf@sys@tonumber{\pgf@x}}% |
| 192 |
\edef\pgf@prevx{\pgf@sys@tonumber{\pgf@x}}% |
| 193 |
\pgf@getgraytuplewithmixin{#2}% |
| 194 |
\edef\pgf@sys@shading@start@gray{\pgf@sys@gray}% |
| 195 |
\let\pgf@sys@prevcolor=\pgf@sys@shading@start@gray% |
| 196 |
\let\pgf@sys@prevpos=\pgf@sys@shading@start@pos% |
| 197 |
\edef\pgf@prevcolor{\pgf@gray}% |
| 198 |
\edef\pgf@firstcolor{\pgf@gray}} |
| 199 |
\def\pgf@parselastdomgray[gray(#1)=(#2); {% |
| 200 |
\pgfutil@ifnextchar]{% |
| 201 |
\pgfmathsetlength\pgf@x{#1}% |
| 202 |
\edef\pgf@sys@shading@end@pos{\the\pgf@x}% |
| 203 |
\pgf@max=\pgf@x\relax% |
| 204 |
\pgf@sys@bp@correct\pgf@x% |
| 205 |
\edef\pgf@domb{\pgf@sys@tonumber{\pgf@x}}% |
| 206 |
\pgf@getgraytuplewithmixin{#2}% |
| 207 |
\edef\pgf@sys@shading@end@gray{\pgf@sys@gray}% |
| 208 |
\pgfutil@gobble}{\pgf@parselastdomgray[}} |
| 209 |
\def\pgf@parsemidgray[gray(#1)=(#2); {\pgf@parserestgray[} |
| 210 |
\def\pgf@parserestgray[gray(#1)=(#2); {% |
| 211 |
\advance\pgf@sys@shading@range@num by1\relax% |
| 212 |
\pgfutil@ifnextchar]{% |
| 213 |
\pgf@getgraytuplewithmixin{#2}% |
| 214 |
\edef\pgf@singlefunc{\space% |
| 215 |
<< /FunctionType 2 /Domain [0 1] /C0 |
| 216 |
[\pgf@prevcolor] /C1 [\pgf@gray] /N 1 >> }% << |
| 217 |
\edef\pgf@funcs{\pgf@funcs\space% |
| 218 |
<< /FunctionType 2 /Domain [\pgf@doma\space\pgf@domb] /C0 |
| 219 |
[\pgf@prevcolor] /C1 [\pgf@gray] /N 1 >> }% << |
| 220 |
\edef\pgf@psfuncs{\pgf@prevx\space \pgf@gray\space |
| 221 |
\pgf@prevcolor\space pgfshade \pgf@psfuncs}% |
| 222 |
\pgfmathsetlength\pgf@x{#1}% |
| 223 |
\edef\pgf@sys@shading@ranges{\pgf@sys@shading@ranges{% |
| 224 |
{\pgf@sys@prevpos}{\the\pgf@x}{\pgf@sys@prevcolor}{\pgf@sys@gray}}}% |
| 225 |
\edef\pgf@sys@prevpos{\the\pgf@x}% |
| 226 |
\let\pgf@sys@prevcolor=\pgf@sys@gray% |
| 227 |
\pgfutil@gobble}{% |
| 228 |
\pgfmathsetlength\pgf@x{#1}% |
| 229 |
\pgf@getgraytuplewithmixin{#2}% |
| 230 |
\edef\pgf@sys@shading@ranges{\pgf@sys@shading@ranges{% |
| 231 |
{\pgf@sys@prevpos}{\the\pgf@x}{\pgf@sys@prevcolor}{\pgf@sys@gray}}}% |
| 232 |
\edef\pgf@sys@prevpos{\the\pgf@x}% |
| 233 |
\let\pgf@sys@prevcolor=\pgf@sys@gray% |
| 234 |
\edef\pgf@psfuncs{\pgf@prevx\space \pgf@gray\space |
| 235 |
\pgf@prevcolor\space pgfshade \pgf@psfuncs}% |
| 236 |
\pgf@sys@bp@correct\pgf@x% |
| 237 |
\edef\pgf@prevx{\pgf@sys@tonumber{\pgf@x}}% |
| 238 |
\edef\pgf@bounds{\pgf@bounds\space\pgf@sys@tonumber{\pgf@x}}% |
| 239 |
\edef\pgf@encode{\pgf@encode\space0 1}% |
| 240 |
\edef\pgf@singlefunc{\space% |
| 241 |
<< /FunctionType 2 /Domain [0 1] /C0 |
| 242 |
[\pgf@prevcolor] /C1 [\pgf@gray] /N 1 >> }% << |
| 243 |
\edef\pgf@funcs{\pgf@funcs\space% |
| 244 |
<< /FunctionType 2 /Domain [\pgf@doma\space\pgf@domb] /C0 |
| 245 |
[\pgf@prevcolor] /C1 [\pgf@gray] /N 1 >> }% << |
| 246 |
\edef\pgf@prevcolor{\pgf@gray}% |
| 247 |
\pgf@parserestgray[}} |
| 248 |
|
| 249 |
\def\pgf@getgraytuplewithmixin#1{% |
| 250 |
\pgfutil@definecolor{pgfshadetemp}{gray}{#1}% |
| 251 |
\pgfutil@ifundefined{applycolormixins}{}{\applycolormixins{pgfshadetemp}}% |
| 252 |
\pgfutil@extractcolorspec{pgfshadetemp}{\pgf@tempcolor}% |
| 253 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{gray}{\pgf@graycolor}% |
| 254 |
\expandafter\pgf@getgray@@\pgf@graycolor!} |
| 255 |
\def\pgf@getgray@@#1!{% |
| 256 |
\def\pgf@gray{#1}% |
| 257 |
\def\pgf@sys@gray{{#1}}% |
| 258 |
} |
| 259 |
|
| 260 |
% Normalized a <color specification> argument for shadings into a |
| 261 |
% series of color specifications in the current xcolor color model and write |
| 262 |
% the result into \pgf@conv. |
| 263 |
% |
| 264 |
% Example: |
| 265 |
% \pgf@convertstring{rgb(0cm)=(1,0,0); rgb(2cm)=(0,1,0); cmyk(4cm)=(1,0,0,0); gray(1cm)=(3); color(2cm)=(green); } |
| 266 |
% -> |
| 267 |
% \pgf@conv = macro:->'rgb(0cm)=(1,0,0); rgb(2cm)=(0,1,0); rgb(4cm)=(0,1,1); rgb(1cm)=(3,3,3); rgb(2cm)=(0,1,0); ' |
| 268 |
\def\pgf@convertstring#1{% |
| 269 |
\def\pgf@conv{}% |
| 270 |
\pgf@convert#1]% |
| 271 |
} |
| 272 |
\def\pgf@convert{% |
| 273 |
\pgfutil@ifnextchar]{\pgfutil@gobble}%done! |
| 274 |
{% |
| 275 |
\pgfutil@ifnextchar;{\pgf@grabsemicolor}% |
| 276 |
{% |
| 277 |
\pgfutil@ifnextchar c{\pgf@gobblec}% |
| 278 |
{% |
| 279 |
\pgfutil@ifnextchar g{\pgf@grabgray}% |
| 280 |
{% |
| 281 |
\pgfutil@ifnextchar o{\pgf@grabcolor}% |
| 282 |
{% |
| 283 |
\pgfutil@ifnextchar m{\pgf@grabcmyk}% |
| 284 |
{% |
| 285 |
\pgfutil@ifnextchar r{\pgf@grabrgb}% |
| 286 |
{\pgferror{Illformed shading |
| 287 |
specification}\pgf@convert}% |
| 288 |
}% |
| 289 |
}% |
| 290 |
}% |
| 291 |
}% |
| 292 |
}% |
| 293 |
}% |
| 294 |
} |
| 295 |
\def\pgf@savecolor#1{% |
| 296 |
\pgfutil@extractcolorspec{pgf@tempcol}{\pgf@tempcolor}% |
| 297 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor |
| 298 |
{\pgf@shading@model}{\pgf@color}% |
| 299 |
\expandafter\pgf@convget@\expandafter{\pgf@color}{#1}% |
| 300 |
} |
| 301 |
\def\pgf@grabsemicolor;{% |
| 302 |
\edef\pgf@conv{\pgf@conv; }\pgf@convert} |
| 303 |
\def\pgf@gobblec c{\pgf@convert} |
| 304 |
\def\pgf@grabrgb rgb(#1)=(#2,#3,#4){% |
| 305 |
\pgfutil@definecolor{pgf@tempcol}{rgb}{#2,#3,#4}% |
| 306 |
\pgf@savecolor{#1}% |
| 307 |
} |
| 308 |
\def\pgf@grabcmyk myk(#1)=(#2,#3,#4,#5){% |
| 309 |
\pgfutil@definecolor{pgf@tempcol}{cmyk}{#2,#3,#4,#5}% |
| 310 |
\pgf@savecolor{#1}% |
| 311 |
} |
| 312 |
\def\pgf@grabgray gray(#1)=(#2){% |
| 313 |
\pgfutil@definecolor{pgf@tempcol}{gray}{#2}% |
| 314 |
\pgf@savecolor{#1}% |
| 315 |
} |
| 316 |
\def\pgf@grabcolor olor(#1)=(#2){% |
| 317 |
\pgfutil@colorlet{pgf@tempcol}{#2}% |
| 318 |
\pgf@savecolor{#1}% |
| 319 |
} |
| 320 |
\def\pgf@convget@#1#2{% |
| 321 |
\edef\pgf@conv{\pgf@conv \pgf@shading@model(#2)=(#1)}\pgf@convert} |
| 322 |
|
| 323 |
|
| 324 |
\newcount\pgf@shadingcount |
| 325 |
\pgf@shadingcount=0 |
| 326 |
{ |
| 327 |
\catcode`\/=0 |
| 328 |
\catcode`\\=12 |
| 329 |
/gdef/pgf@shadingnum{\/the/pgf@shadingcount\} |
| 330 |
} |
| 331 |
|
| 332 |
% Set up shading properties based on the current xcolor color model. This is |
| 333 |
% called when shadings are declared and used. \ifpgfshadingmodelrgb, |
| 334 |
% \ifpgfshadingmodelcmyk, and \ifpgfshadingmodelgray are set so that the type |
| 335 |
% 4 function in functional shadings can be converted to the current color |
| 336 |
% model. See \pgffuncshading*to* macros. |
| 337 |
|
| 338 |
\newif\ifpgfshadingmodelrgb |
| 339 |
\newif\ifpgfshadingmodelcmyk |
| 340 |
\newif\ifpgfshadingmodelgray |
| 341 |
\def\pgf@setup@shading@model{% |
| 342 |
\pgfshadingmodelrgbtrue |
| 343 |
\pgfshadingmodelcmykfalse |
| 344 |
\pgfshadingmodelgrayfalse |
| 345 |
\XC@sdef\pgf@mod@test{\XC@tgt@mod{natural}}% |
| 346 |
\def\pgf@shading@device{/DeviceRGB}% |
| 347 |
\def\pgf@shading@ps@device{setrgbcolor}% |
| 348 |
\def\pgf@shading@functional@range{0 1 0 1 0 1}% |
| 349 |
\def\pgf@shading@model{rgb}% |
| 350 |
\ifx\pgf@mod@test\XC@mod@cmyk |
| 351 |
\def\pgf@shading@device{/DeviceCMYK}% |
| 352 |
\def\pgf@shading@ps@device{setcmykcolor}% |
| 353 |
\def\pgf@shading@functional@range{0 1 0 1 0 1 0 1}% |
| 354 |
\def\pgf@shading@model{cmyk}% |
| 355 |
\pgfshadingmodelrgbfalse |
| 356 |
\pgfshadingmodelcmyktrue |
| 357 |
\fi |
| 358 |
\ifx\pgf@mod@test\XC@mod@gray |
| 359 |
\def\pgf@shading@device{/DeviceGray}% |
| 360 |
\def\pgf@shading@ps@device{setgray}% |
| 361 |
\def\pgf@shading@functional@range{0 1}% |
| 362 |
\def\pgf@shading@model{gray}% |
| 363 |
\pgfshadingmodelrgbfalse |
| 364 |
\pgfshadingmodelgraytrue |
| 365 |
\fi |
| 366 |
\edef\pgf@sys@driver@dvisvgm{pgfsys-dvisvgm.def}% |
| 367 |
\ifx\pgfsysdriver\pgf@sys@driver@dvisvgm |
| 368 |
\def\pgf@shading@model{rgb}% |
| 369 |
\fi |
| 370 |
\edef\pgf@sys@driver@texforht{pgfsys-tex4ht.def}% |
| 371 |
\ifx\pgfsysdriver\pgf@sys@driver@texforht |
| 372 |
\def\pgf@shading@model{rgb}% |
| 373 |
\fi |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
% Declares a horizontal shading for later use. The shading is a |
| 378 |
% horizontal bar that changes its color. |
| 379 |
% |
| 380 |
% #1 = optional dependencies |
| 381 |
% #2 = name of the shading for later use |
| 382 |
% #3 = height of the shading |
| 383 |
% #4 = color specification in the following format: A list of colors |
| 384 |
% that the bar should have at certain points. If the bar should |
| 385 |
% be red at 1cm, this is specified as |
| 386 |
% "rgb(1cm)=(1,0,0)". Multiple specifications are separated by a |
| 387 |
% semicolon and a space. At least two specifications must be |
| 388 |
% given. The specified positions must be given in increasing |
| 389 |
% order. |
| 390 |
% |
| 391 |
% Description: |
| 392 |
% |
| 393 |
% The optional dependencies have the following effect: If present, it |
| 394 |
% should consist of a list of colors, separated by commas. Each time |
| 395 |
% the shading is used, these colors will be reevaluated. It will be |
| 396 |
% checked whether the colors still have their "original meaning". If |
| 397 |
% the colors have changed, a new shading will be created internally to |
| 398 |
% reflect the changed color's values. |
| 399 |
% |
| 400 |
% Example: |
| 401 |
% |
| 402 |
% \pgfdeclarehorizontalshading{redtogreentoblue}{1cm}{% |
| 403 |
% rgb(0cm)=(1,0,0); % red |
| 404 |
% rgb(1cm)=(0,1,0); % green |
| 405 |
% rgb(2cm)=(0,0,1)} |
| 406 |
% |
| 407 |
% \begin{document} |
| 408 |
% The following bar is 2cm long: \pgfuseshading{redtogreentoblue}. |
| 409 |
% \end{document} |
| 410 |
|
| 411 |
\def\pgfdeclarehorizontalshading{% |
| 412 |
\pgf@setup@shading@model |
| 413 |
\pgfutil@ifnextchar[% |
| 414 |
\pgf@declarehorizontalshading{\pgf@declarehorizontalshading[]}} |
| 415 |
\def\pgf@declarehorizontalshading[#1]#2#3#4{% |
| 416 |
\expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}% |
| 417 |
\expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\pgfutil@empty% |
| 418 |
\global\expandafter\let\csname pgf@num@pgfshading#2!\endcsname\pgfutil@empty |
| 419 |
\pgfsys@horishading{#2}{#3}{#4}% |
| 420 |
\else% |
| 421 |
\global\advance\pgf@shadingcount 1\relax |
| 422 |
\global\expandafter\edef\csname pgf@num@pgfshading#2!\endcsname{\pgf@shadingnum}% |
| 423 |
\expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@horishading}% |
| 424 |
\expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}% |
| 425 |
\expandafter\let\csname @pgfshading#2!\endcsname=\pgfutil@empty% |
| 426 |
\fi} |
| 427 |
|
| 428 |
|
| 429 |
% Declares a vertical shading for later use. |
| 430 |
% |
| 431 |
% #1 = optional dependencies |
| 432 |
% #2 = name of the shading for later use |
| 433 |
% #3 = height of the shading |
| 434 |
% #4 = color specification |
| 435 |
% |
| 436 |
% Example: |
| 437 |
% |
| 438 |
% \pgfdeclareverticalshading{redtogreentoblue}{1cm}{% |
| 439 |
% rgb(0cm)=(1,0,0); % red |
| 440 |
% rgb(1cm)=(0,1,0); % green |
| 441 |
% rgb(2cm)=(0,0,1)} |
| 442 |
% |
| 443 |
% \begin{document} |
| 444 |
% The following bar is 2cm high: \pgfuseshading{redtogreentoblue}. |
| 445 |
% \end{document} |
| 446 |
|
| 447 |
\def\pgfdeclareverticalshading{% |
| 448 |
\pgf@setup@shading@model |
| 449 |
\pgfutil@ifnextchar[% |
| 450 |
\pgf@declareverticalshading{\pgf@declareverticalshading[]}} |
| 451 |
\def\pgf@declareverticalshading[#1]#2#3#4{% |
| 452 |
\expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}% |
| 453 |
\expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\pgfutil@empty% |
| 454 |
\global\expandafter\let\csname pgf@num@pgfshading#2!\endcsname=\pgfutil@empty |
| 455 |
\pgfsys@vertshading{#2}{#3}{#4}% |
| 456 |
\else% |
| 457 |
\global\advance\pgf@shadingcount 1\relax |
| 458 |
\global\expandafter\edef\csname pgf@num@pgfshading#2!\endcsname{\pgf@shadingnum}% |
| 459 |
\expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@vertshading}% |
| 460 |
\expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}% |
| 461 |
\expandafter\let\csname @pgfshading#2!\endcsname=\pgfutil@empty% |
| 462 |
\fi} |
| 463 |
|
| 464 |
|
| 465 |
% Declares a radial shading for later use. |
| 466 |
% |
| 467 |
% #1 = optional dependencies |
| 468 |
% #2 = name of the shading for later use |
| 469 |
% #3 = center of inner circle |
| 470 |
% #4 = color specification |
| 471 |
% |
| 472 |
% Description: |
| 473 |
% |
| 474 |
% A radial shading creates a smooth color transition between two |
| 475 |
% circles. The center of the inner circle is at the give position. Its |
| 476 |
% radius is the start of the color specification. The |
| 477 |
% center of the outer circle is at the center of the whole shading, |
| 478 |
% whose radius is the end of the color specification. For example, |
| 479 |
% suppose the color specification is "rgb(1cm)=(1,1,1); rgb(2cm)=(0,0,0)". |
| 480 |
% Then the shading would be 4cm times 4cm large. The inner circle would |
| 481 |
% have diameter 1cm and the outer circle would have diameter 2cm. The |
| 482 |
% outer circle would be centered in the middle of the shading, whereas |
| 483 |
% the outer circle would be centered at the given position. |
| 484 |
% |
| 485 |
% Example: |
| 486 |
% |
| 487 |
% \pgfdeclareradialshading{redtogreentoblue}{\pgfpoint{2cm}{2cm}}{% |
| 488 |
% rgb(10pt)=(1,0,0); % red |
| 489 |
% rgb(2cm)=(0,1,0); % green |
| 490 |
% rgb(3cm)=(0,0,1)} |
| 491 |
% |
| 492 |
% \begin{document} |
| 493 |
% The following ball has diameter 3cm: \pgfuseshading{redtogreentoblue}. |
| 494 |
% \end{document} |
| 495 |
|
| 496 |
\def\pgfdeclareradialshading{% |
| 497 |
\pgf@setup@shading@model |
| 498 |
\pgfutil@ifnextchar[% |
| 499 |
\pgf@declareradialshading{\pgf@declareradialshading[]}} |
| 500 |
\def\pgf@declareradialshading[#1]#2#3#4{% |
| 501 |
\expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}% |
| 502 |
\expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\pgfutil@empty% |
| 503 |
\global\expandafter\let\csname pgf@num@pgfshading#2!\endcsname=\pgfutil@empty |
| 504 |
\pgfsys@radialshading{#2}{#3}{#4}% |
| 505 |
\else% |
| 506 |
\global\advance\pgf@shadingcount 1\relax |
| 507 |
\global\expandafter\edef\csname pgf@num@pgfshading#2!\endcsname{\pgf@shadingnum}% |
| 508 |
\expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfsys@radialshading}% |
| 509 |
\expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}}% |
| 510 |
\expandafter\let\csname @pgfshading#2!\endcsname=\pgfutil@empty% |
| 511 |
\fi} |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
% Declares a functional shading for later use. |
| 517 |
% |
| 518 |
% #1 = optional dependencies |
| 519 |
% #2 = name of the shading for later use |
| 520 |
% #3 = lower left corner of the shading as a pgfpoint. |
| 521 |
% #4 = upper right corner of the shading as a pgfpoint. |
| 522 |
% #5 = Preparation code |
| 523 |
% #6 = a PDF type 4 function (restricted Postscript function), see the |
| 524 |
% PDF-specification 1.7, section 3.9.4 |
| 525 |
% |
| 526 |
% Description: |
| 527 |
% |
| 528 |
% This command creates a so-called functional shading. For such a |
| 529 |
% shading the color of each point is calculated by calling a function |
| 530 |
% for each point that gets the coordinates as input and yields the |
| 531 |
% color as an output. Note that the function is evaluated by the |
| 532 |
% *renderer*, not by PGF or TeX or someone else at compile-time. This |
| 533 |
% means that the evaluation of this function has to be done *extremely |
| 534 |
% quickly* and the function should be *very simple*. For this reason, |
| 535 |
% only a very restricted set of operations are possible in the |
| 536 |
% function (see 3.9.4 of the PDF-spec 1.7). Also functions should be |
| 537 |
% kept small. Any errors in the function will only be noticed by the |
| 538 |
% renderer. |
| 539 |
% |
| 540 |
% The function gets the coordinates of a point as input (as bp). This |
| 541 |
% input consists of the top two elements of an otherwise empty |
| 542 |
% (virtual, PostScript) stack. The function should then replace these |
| 543 |
% two values by one value representing the gray color of the point for a |
| 544 |
% grayscale shading, three values, representing the red, green, and blue color |
| 545 |
% of the point for an RGB shading, or four values, representing the cyan, |
| 546 |
% magenta, yellow, and black color of the point for a CMYK shading. The |
| 547 |
% numbers should be real values, not integers since Apple's PDF renderer is |
| 548 |
% broken in this regard (use cvr at the end if necessary). |
| 549 |
% |
| 550 |
% Conceptually, the function will be evaluated once for each point of |
| 551 |
% the rectangle (#3) to (#4). A renderer may choose to evaluate the |
| 552 |
% function at less points, but, in principle, the function will be |
| 553 |
% evaluated for each pixel independently. |
| 554 |
% |
| 555 |
% Because of the rather difficult PostScript syntax, use this macro |
| 556 |
% only *if you know what you are doing* (or if you are adventurous, of |
| 557 |
% course). |
| 558 |
% |
| 559 |
% As for other shadings, the optional dependencies argument is used to |
| 560 |
% determine whether a shading needs to be recalculated when a color |
| 561 |
% has changed. |
| 562 |
% |
| 563 |
% The code #5 is executed each time a shading is |
| 564 |
% (re)calculated. Typically, it will contain code to extract |
| 565 |
% coordinates from colors (see below). |
| 566 |
% |
| 567 |
% Inside the PostScript function #6 you cannot use colors |
| 568 |
% directly. Rather, you must push the color components on the |
| 569 |
% stack. For this, it is useful to call \pgfshadecolortorgb, |
| 570 |
% \pgfshadecolortocmyk, or \pgfshadecolortogray in the startup |
| 571 |
% code #4. The macro takes a color name as input and stores the color's |
| 572 |
% component real numbers between 0.0 and 1.0 separated |
| 573 |
% by spaces (which is exactly what you need if you want to push it on |
| 574 |
% a stack) in a macro. |
| 575 |
% |
| 576 |
% Example: |
| 577 |
% |
| 578 |
%\pgfdeclarefunctionalshading{twospots}{\pgfpointorigin}{\pgfpoint{200bp}{200bp}}{}{ |
| 579 |
% 2 copy |
| 580 |
% 90 sub dup mul exch |
| 581 |
% 80 sub dup mul add sqrt |
| 582 |
% dup mul neg 1.0005 exch exp 1.0 exch sub |
| 583 |
% 3 1 roll |
| 584 |
% 120 sub dup mul exch |
| 585 |
% 100 sub dup mul add sqrt |
| 586 |
% dup mul neg 1.002 exch exp 1.0 exch sub |
| 587 |
% 1.0 |
| 588 |
%} |
| 589 |
% |
| 590 |
% \pgfdeclarefunctionalshading[mycol]{sweep}{\pgfpointorigin}{\pgfpoint{100bp}{100bp}} |
| 591 |
% {\pgfshadecolortorgb{mycol}{\myrgb}}{ |
| 592 |
% add 150 div % not very useful... |
| 593 |
% dup |
| 594 |
% \myrgb % push mycol |
| 595 |
% 5 4 roll % multiply all components by calculated value |
| 596 |
% mul |
| 597 |
% 3 1 roll |
| 598 |
% 3 index |
| 599 |
% mul |
| 600 |
% 3 1 roll |
| 601 |
% 4 3 roll |
| 602 |
% mul |
| 603 |
% 3 1 roll |
| 604 |
% } |
| 605 |
% |
| 606 |
% \begin{document} |
| 607 |
% Have a look at this: \pgfuseshading{twospots}. |
| 608 |
% Here is \colorlet{mycol}{green!50}\pgfuseshading{sweep} in green |
| 609 |
% and in \colorlet{mycol}{red!50!blue}\pgfuseshading{sweep} in red/blue. |
| 610 |
% \end{document} |
| 611 |
|
| 612 |
\def\pgfdeclarefunctionalshading{% |
| 613 |
\pgf@setup@shading@model |
| 614 |
\pgfutil@ifnextchar[% |
| 615 |
\pgf@declarefunctionalshading{\pgf@declarefunctionalshading[]}} |
| 616 |
\def\pgf@declarefunctionalshading[#1]#2#3#4#5#6{% |
| 617 |
\expandafter\def\csname pgf@deps@pgfshading#2!\endcsname{#1}% |
| 618 |
\expandafter\ifx\csname pgf@deps@pgfshading#2!\endcsname\pgfutil@empty% |
| 619 |
\global\expandafter\let\csname pgf@num@pgfshading#2!\endcsname=\pgfutil@empty |
| 620 |
\pgfshade@functionaldo{#2}{#3}{#4}{#5}{#6}% |
| 621 |
\else% |
| 622 |
\global\advance\pgf@shadingcount 1\relax |
| 623 |
\global\expandafter\edef\csname pgf@num@pgfshading#2!\endcsname{\pgf@shadingnum}% |
| 624 |
\expandafter\def\csname pgf@func@pgfshading#2!\endcsname{\pgfshade@functionaldo}% |
| 625 |
\expandafter\def\csname pgf@args@pgfshading#2!\endcsname{{#3}{#4}{#5}{#6}}% |
| 626 |
\expandafter\let\csname @pgfshading#2!\endcsname=\pgfutil@empty% |
| 627 |
\fi} |
| 628 |
\def\pgfshade@functionaldo#1#2#3#4#5{% |
| 629 |
\begingroup |
| 630 |
#4% |
| 631 |
\pgfsys@functionalshading{#1}{#2}{#3}{#5}% |
| 632 |
\expandafter\pgfmath@smuggleone\csname @pgfshading#1!\endcsname |
| 633 |
\endgroup |
| 634 |
} |
| 635 |
|
| 636 |
\def\pgfshadecolortorgb#1#2{% |
| 637 |
\pgfutil@colorlet{pgf@tempcol}{#1}% |
| 638 |
\pgfutil@extractcolorspec{pgf@tempcol}{\pgf@tempcolor}% |
| 639 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}% |
| 640 |
\expandafter\pgfshading@rgb\pgf@rgbcolor\relax% |
| 641 |
\edef#2{\pgf@sys@tonumber{\pgf@xa}\space\pgf@sys@tonumber{\pgf@xb}\space\pgf@sys@tonumber{\pgf@xc}\space}% |
| 642 |
\c@pgf@counta\escapechar% |
| 643 |
\escapechar-1\relax% |
| 644 |
\expandafter\edef\csname\string#2red\endcsname{\pgf@sys@tonumber{\pgf@xa}\space}% |
| 645 |
\expandafter\edef\csname\string#2green\endcsname{\pgf@sys@tonumber{\pgf@xb}\space}% |
| 646 |
\expandafter\edef\csname\string#2blue\endcsname{\pgf@sys@tonumber{\pgf@xc}\space}% |
| 647 |
\escapechar\c@pgf@counta% |
| 648 |
} |
| 649 |
\def\pgfshading@rgb#1,#2,#3\relax{% |
| 650 |
\pgf@xa=#1pt% |
| 651 |
\pgf@xb=#2pt% |
| 652 |
\pgf@xc=#3pt% |
| 653 |
} |
| 654 |
|
| 655 |
\def\pgfshadecolortocmyk#1#2{% |
| 656 |
\pgfutil@colorlet{pgf@tempcol}{#1}% |
| 657 |
\pgfutil@extractcolorspec{pgf@tempcol}{\pgf@tempcolor}% |
| 658 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{cmyk}{\pgf@cmykcolor}% |
| 659 |
\expandafter\pgfshading@cmyk\pgf@cmykcolor\relax% |
| 660 |
\edef#2{\pgf@sys@tonumber{\pgf@xa}\space\pgf@sys@tonumber{\pgf@xb}\space |
| 661 |
\pgf@sys@tonumber{\pgf@xc}\space\pgf@sys@tonumber{\pgf@xd}\space}% |
| 662 |
\c@pgf@counta\escapechar% |
| 663 |
\escapechar-1\relax% |
| 664 |
\expandafter\edef\csname\string#2cyan\endcsname{% |
| 665 |
\pgf@sys@tonumber{\pgf@xa}\space}% |
| 666 |
\expandafter\edef\csname\string#2magenta\endcsname{% |
| 667 |
\pgf@sys@tonumber{\pgf@xb}\space}% |
| 668 |
\expandafter\edef\csname\string#2yellow\endcsname{% |
| 669 |
\pgf@sys@tonumber{\pgf@xc}\space}% |
| 670 |
\expandafter\edef\csname\string#2black\endcsname{% |
| 671 |
\pgf@sys@tonumber{\pgf@xd}\space}% |
| 672 |
\escapechar\c@pgf@counta |
| 673 |
} |
| 674 |
\def\pgfshading@cmyk#1,#2,#3,#4\relax{% |
| 675 |
\pgf@xa=#1pt% |
| 676 |
\pgf@xb=#2pt% |
| 677 |
\pgf@xc=#3pt% |
| 678 |
\pgf@xd=#4pt% |
| 679 |
} |
| 680 |
|
| 681 |
\def\pgfshadecolortogray#1#2{% |
| 682 |
\pgfutil@colorlet{pgf@tempcol}{#1}% |
| 683 |
\pgfutil@extractcolorspec{pgf@tempcol}{\pgf@tempcolor}% |
| 684 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{gray}{\pgf@graycolor}% |
| 685 |
\expandafter\pgfshading@gray\pgf@graycolor\relax |
| 686 |
\edef#2{\pgf@sys@tonumber{\pgf@xa}\space}% |
| 687 |
\c@pgf@counta\escapechar |
| 688 |
\escapechar-1\relax |
| 689 |
\expandafter\edef\csname\string#2gray\endcsname{% |
| 690 |
\pgf@sys@tonumber{\pgf@xa}\space}% |
| 691 |
\escapechar\c@pgf@counta |
| 692 |
} |
| 693 |
\def\pgfshading@gray#1\relax{% |
| 694 |
\pgf@xa=#1pt% |
| 695 |
} |
| 696 |
|
| 697 |
% Functions to convert between color models in the type 4 PostScript data of |
| 698 |
% functional shadings. |
| 699 |
|
| 700 |
\def\pgffuncshadingrgbtocmyk{% |
| 701 |
1.0 exch sub 3 1 roll |
| 702 |
1.0 exch sub 3 1 roll |
| 703 |
1.0 exch sub 3 1 roll |
| 704 |
3 copy |
| 705 |
2 copy gt { exch } if pop |
| 706 |
2 copy gt { exch } if pop |
| 707 |
dup 3 1 roll sub |
| 708 |
0.0 2 copy lt { exch } if pop |
| 709 |
1.0 2 copy gt { exch } if pop |
| 710 |
4 1 roll |
| 711 |
dup 3 1 roll sub |
| 712 |
0.0 2 copy lt { exch } if pop |
| 713 |
1.0 2 copy gt { exch } if pop |
| 714 |
4 1 roll |
| 715 |
dup 3 1 roll sub |
| 716 |
0.0 2 copy lt { exch } if pop |
| 717 |
1.0 2 copy gt { exch } if pop |
| 718 |
4 1 roll |
| 719 |
} |
| 720 |
|
| 721 |
\def\pgffuncshadingrgbtogray{% |
| 722 |
0.11 mul exch 0.59 mul add exch 0.3 mul add |
| 723 |
} |
| 724 |
|
| 725 |
\def\pgffuncshadingcmyktorgb{% |
| 726 |
% convert to CMY |
| 727 |
dup 3 1 roll add |
| 728 |
1.0 2 copy gt { exch } if pop |
| 729 |
4 1 roll |
| 730 |
dup 3 1 roll add |
| 731 |
1.0 2 copy gt { exch } if pop |
| 732 |
4 1 roll |
| 733 |
add |
| 734 |
1.0 2 copy gt { exch } if pop |
| 735 |
3 1 roll |
| 736 |
% convert to RGB |
| 737 |
1.0 exch sub |
| 738 |
3 1 roll |
| 739 |
1.0 exch sub |
| 740 |
3 1 roll |
| 741 |
1.0 exch sub |
| 742 |
3 1 roll |
| 743 |
} |
| 744 |
|
| 745 |
\def\pgffuncshadingcmyktogray{% |
| 746 |
exch 0.11 mul add exch 0.59 mul add exch 0.3 mul add |
| 747 |
1.0 2 copy gt { exch } if pop |
| 748 |
1.0 exch sub |
| 749 |
} |
| 750 |
|
| 751 |
\def\pgffuncshadinggraytorgb{% |
| 752 |
dup dup |
| 753 |
} |
| 754 |
|
| 755 |
\def\pgffuncshadinggraytocmyk{% |
| 756 |
0.0 0.0 0.0 |
| 757 |
4 3 roll |
| 758 |
} |
| 759 |
|
| 760 |
% Inserts a box into the text that contains a previously defined |
| 761 |
% shading. |
| 762 |
% |
| 763 |
% #1 = Name of a shading |
| 764 |
% |
| 765 |
% Example: |
| 766 |
% |
| 767 |
% \pgfuseshading{redtogreentoblue} |
| 768 |
|
| 769 |
\def\pgfuseshading#1{% |
| 770 |
\edef\pgf@shadingname{@pgfshading#1}% |
| 771 |
\pgf@tryextensions{\pgf@shadingname}{\pgfalternateextension}% |
| 772 |
\expandafter\pgfutil@ifundefined\expandafter{\pgf@shadingname}% |
| 773 |
{\pgferror{Undefined shading "#1"}}% |
| 774 |
{% |
| 775 |
\edef\pgf@shade@adds{\csname pgf@num\pgf@shadingname\endcsname}% |
| 776 |
\pgfutil@ifundefined{pgf@deps\pgf@shadingname}% |
| 777 |
{}% |
| 778 |
{% |
| 779 |
\pgf@setup@shading@model |
| 780 |
\begingroup |
| 781 |
\pgfutil@globalcolorsfalse |
| 782 |
\edef\@list{\csname pgf@deps\pgf@shadingname\endcsname}% |
| 783 |
\pgfutil@for\@temp:=\@list\do{% |
| 784 |
\pgfutil@ifundefined{applycolormixins}{}{\applycolormixins{\@temp}}% |
| 785 |
\pgfutil@extractcolorspec{\@temp}{\pgf@tempcolor}% |
| 786 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{\pgf@shading@model}{\pgf@color}% |
| 787 |
\edef\pgf@shade@adds{\pgf@shade@adds,\pgf@color}% |
| 788 |
}% |
| 789 |
\pgfmath@smuggleone\pgf@shade@adds |
| 790 |
\endgroup |
| 791 |
}% |
| 792 |
\expandafter\pgf@strip@shadename\pgf@shadingname!!% |
| 793 |
\edef\pgf@shadingxname{@pgfshading\pgf@basename\pgf@shade@adds!}% |
| 794 |
\pgfutil@ifundefined{\pgf@shadingxname}% |
| 795 |
{% |
| 796 |
\begingroup |
| 797 |
\edef\@temp{\expandafter\noexpand\csname pgf@func\pgf@shadingname\endcsname}% |
| 798 |
\edef\@args{{\pgf@basename\pgf@shade@adds}}% |
| 799 |
\expandafter\expandafter\expandafter\def |
| 800 |
\expandafter\expandafter\expandafter\@@args |
| 801 |
\expandafter\expandafter\expandafter{\csname pgf@args\pgf@shadingname\endcsname}% |
| 802 |
\expandafter\expandafter\expandafter\@temp\expandafter\@args\@@args |
| 803 |
\expandafter\pgfmath@smuggleone\csname\pgf@shadingxname\endcsname |
| 804 |
\endgroup |
| 805 |
}% |
| 806 |
{}% |
| 807 |
\pgf@invokeshading{\csname\pgf@shadingxname\endcsname}% |
| 808 |
}% |
| 809 |
} |
| 810 |
|
| 811 |
\def\pgf@strip@shadename @pgfshading#1!!!{\def\pgf@basename{#1}} |
| 812 |
|
| 813 |
\def\pgf@invokeshading#1{% |
| 814 |
\ifpgfpicture% |
| 815 |
\pgfsys@shadinginsidepgfpicture{#1}% |
| 816 |
\else% |
| 817 |
\pgfsys@shadingoutsidepgfpicture{#1}% |
| 818 |
\fi% |
| 819 |
} |
| 820 |
|
| 821 |
|
| 822 |
% Create an alias name for a shading |
| 823 |
% |
| 824 |
% #1 = name of the alias |
| 825 |
% #2 = name of the original |
| 826 |
% |
| 827 |
% Example: |
| 828 |
% |
| 829 |
% \pgfaliasshading{shading!25}{shadingshaded} |
| 830 |
|
| 831 |
\def\pgfaliasshading#1#2{% |
| 832 |
\expandafter\let\expandafter\pgf@temp\expandafter=\csname @pgfshading#2!\endcsname% |
| 833 |
\expandafter\let\csname @pgfshading#1!\endcsname=\pgf@temp% |
| 834 |
\expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@num@pgfshading#2!\endcsname% |
| 835 |
\expandafter\let\csname pgf@num@pgfshading#1!\endcsname=\pgf@temp% |
| 836 |
\expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@deps@pgfshading#2!\endcsname% |
| 837 |
\expandafter\let\csname pgf@deps@pgfshading#1!\endcsname=\pgf@temp% |
| 838 |
\expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@func@pgfshading#2!\endcsname% |
| 839 |
\expandafter\let\csname pgf@func@pgfshading#1!\endcsname=\pgf@temp% |
| 840 |
\expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@args@pgfshading#2!\endcsname% |
| 841 |
\expandafter\let\csname pgf@args@pgfshading#1!\endcsname=\pgf@temp% |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
% Shades the current path, but does not discard it. |
| 848 |
% |
| 849 |
% #1 - a shading (see below) |
| 850 |
% #2 - an angle |
| 851 |
% |
| 852 |
% Description: |
| 853 |
% |
| 854 |
% \pgfshadepath ``tries'' to fill the |
| 855 |
% current path with a shading. The shading's original size should |
| 856 |
% completely cover the area between (0,0) and (100bp,100bp). The |
| 857 |
% shading will be rotated by #2 and then rescaled so that it |
| 858 |
% completely covers the path. Then the path will be used (locally) for |
| 859 |
% clipping and the shading is drawn. |
| 860 |
% |
| 861 |
% In addition to the rotation, any transformation set by the |
| 862 |
%\pgfsetadditionalshadetransform will also be applied. |
| 863 |
% |
| 864 |
% After all this, the path can still be used for the normal |
| 865 |
% stroking/clipping operations. |
| 866 |
% |
| 867 |
% The shading is rotated around its middle. If no rotation occurs, the |
| 868 |
% lower left corner of the path will lie on (25bp, 25bp), the upper |
| 869 |
% right corner on (75bp, 75bp). |
| 870 |
% |
| 871 |
% Example: |
| 872 |
% |
| 873 |
% \pgfdeclareverticalshading{myshading}{100bp}{color(0pt)=(red); color(100bp)=(green)} |
| 874 |
% |
| 875 |
% \pgfpathmoveto{\pgforigin} |
| 876 |
% \pgfpathlineto{\pgfxy(1,0)} |
| 877 |
% \pgfpathlineto{\pgfxy(1,1)} |
| 878 |
% \pgfshadepath{myshading}{0} |
| 879 |
% \pgfusepath{stroke} |
| 880 |
|
| 881 |
\def\pgfshadepath#1#2{% |
| 882 |
\ifdim\pgf@pathminx=16000pt% |
| 883 |
\pgfwarning{No path specified that can be filled}% |
| 884 |
\else% |
| 885 |
\begingroup% |
| 886 |
% Calculate center: |
| 887 |
\pgf@xb=.5\pgf@pathmaxx% |
| 888 |
\advance\pgf@xb by.5\pgf@pathminx% |
| 889 |
\pgf@yb=.5\pgf@pathmaxy% |
| 890 |
\advance\pgf@yb by.5\pgf@pathminy% |
| 891 |
% Calculate rotation: |
| 892 |
\pgfmathparse{#2}% |
| 893 |
\let\pgfshade@angle=\pgfmathresult |
| 894 |
\pgfmathsin@\pgfshade@angle |
| 895 |
\let\pgfshade@sin=\pgfmathresult |
| 896 |
\pgfmathcos@\pgfshade@angle |
| 897 |
\let\pgfshade@cos=\pgfmathresult |
| 898 |
% width and height of the bounding box |
| 899 |
\pgf@xa=\pgf@pathmaxx |
| 900 |
\advance\pgf@xa by-\pgf@pathminx |
| 901 |
\pgf@ya=\pgf@pathmaxy |
| 902 |
\advance\pgf@ya by-\pgf@pathminy |
| 903 |
% Calculate scaling: |
| 904 |
% xscale = 1pt/50bp * (w*|cos(a)|+h*|sin(a)|)/(|cos(a)|+|sin(a)|) |
| 905 |
% yscale = 1pt/50bp * (w*|sin(a)|+h*|cos(a)|)/(|cos(a)|+|sin(a)|) |
| 906 |
% 1pt/50bp = .01992528 |
| 907 |
\pgfmathabs@\pgfshade@sin |
| 908 |
\let\pgfshade@abssin=\pgfmathresult |
| 909 |
\pgfmathabs@\pgfshade@cos |
| 910 |
\let\pgfshade@abscos=\pgfmathresult |
| 911 |
\pgf@xc=\pgfshade@abscos\pgf@xa |
| 912 |
\advance\pgf@xc by\pgfshade@abssin\pgf@ya |
| 913 |
\pgf@yc=\pgfshade@abssin\pgf@xa |
| 914 |
\advance\pgf@yc by\pgfshade@abscos\pgf@ya |
| 915 |
\pgfmathadd@\pgfshade@abscos\pgfshade@abssin |
| 916 |
\pgfmathdivide@{.01992528}{\pgfmathresult}% |
| 917 |
\pgf@xc=\pgfmathresult\pgf@xc |
| 918 |
\pgf@yc=\pgfmathresult\pgf@yc |
| 919 |
\ifdim\pgf@xc<0.0001pt |
| 920 |
\ifdim\pgf@xc>-0.0001pt |
| 921 |
\pgf@no@shadetrue |
| 922 |
\fi |
| 923 |
\fi |
| 924 |
\ifdim\pgf@yc<0.0001pt |
| 925 |
\ifdim\pgf@yc>-0.0001pt |
| 926 |
\pgf@no@shadetrue |
| 927 |
\fi |
| 928 |
\fi |
| 929 |
\ifpgf@no@shade\else |
| 930 |
\pgfsys@beginscope |
| 931 |
\pgfsyssoftpath@invokecurrentpath |
| 932 |
\pgfsys@clipnext |
| 933 |
\pgfsys@discardpath |
| 934 |
% Compute new transformation matrix: |
| 935 |
% shift |
| 936 |
\pgfsys@transformcm{1}{0}{0}{1}{\the\pgf@xb}{\the\pgf@yb}% |
| 937 |
% rotation |
| 938 |
\pgf@x=\pgfshade@sin pt% |
| 939 |
\pgf@xa=-\pgf@x% |
| 940 |
\pgfsys@transformcm{\pgfshade@cos}{\pgfshade@sin}{\pgf@sys@tonumber{\pgf@xa}}{\pgfshade@cos}{0pt}{0pt}% |
| 941 |
% scaling |
| 942 |
\pgfsys@transformcm{\pgf@sys@tonumber{\pgf@xc}}{0}{0}{\pgf@sys@tonumber{\pgf@yc}}{0pt}{0pt}% |
| 943 |
% This will actually be the first transformation of the shading. |
| 944 |
% Should it be applied first so that it becomes the last one? |
| 945 |
\ifx\pgf@shade@extra@transform\pgfutil@empty% |
| 946 |
\else% |
| 947 |
\pgflowlevel{\pgf@shade@extra@transform}% |
| 948 |
\fi% |
| 949 |
\pgfuseshading{#1}% |
| 950 |
\pgfsys@endscope% |
| 951 |
\fi% |
| 952 |
\endgroup% |
| 953 |
\fi% |
| 954 |
} |
| 955 |
|
| 956 |
\newif\ifpgf@no@shade |
| 957 |
|
| 958 |
% Additionally transform shade paths |
| 959 |
% |
| 960 |
% #1 = Transformation code that is used in addition to the normal |
| 961 |
% shading transformation. |
| 962 |
% |
| 963 |
% Example: |
| 964 |
% |
| 965 |
% \pgfsetadditionalshadetransform{\pgftransformrotate{30}} |
| 966 |
|
| 967 |
\def\pgfsetadditionalshadetransform#1{\def\pgf@shade@extra@transform{#1}} |
| 968 |
\let\pgf@shade@extra@transform=\pgfutil@empty |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
\endinput |