| 1 |
% Copyright 2019 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{pgfcorepatterns.code.tex} |
| 11 |
|
| 12 |
% Creates a new uncolored pattern |
| 13 |
% |
| 14 |
% [#1] = optional list of variables. |
| 15 |
% #2 = pattern name |
| 16 |
% #3 = lower left of bounding box |
| 17 |
% #4 = upper right of bounding box |
| 18 |
% #5 = step vector |
| 19 |
% #6 = pattern code |
| 20 |
% |
| 21 |
% Description: |
| 22 |
% |
| 23 |
% Declares a new uncolored pattern. An uncolored pattern is a pattern |
| 24 |
% that has no inherent color. When the pattern is used, a color for |
| 25 |
% the pattern must be supplied. |
| 26 |
% |
| 27 |
% See the pdf-manual for more details on uncolored patterns. |
| 28 |
% |
| 29 |
% Specifying a variable list makes the pattern ``mutable''. |
| 30 |
% |
| 31 |
% The bounding box must be a bounding box of the pattern cell. |
| 32 |
% |
| 33 |
% The step vector must provide the x- and y-step by which the cells |
| 34 |
% are spaced. |
| 35 |
% |
| 36 |
% The pattern code should be pgf code that can be protocolled. |
| 37 |
% |
| 38 |
% The transformation matrix will be reset prior to invoking the |
| 39 |
% pattern code. |
| 40 |
% |
| 41 |
% Example: |
| 42 |
% |
| 43 |
% \pgfdeclarepatternformonly{stars}{\pgfpointorigin}{\pgfpoint{1cm}{1cm}} |
| 44 |
% {\pgfpoint{1cm}{1cm}}{ |
| 45 |
% \pgftransformshift{\pgfpoint{.5cm}{.5cm}} |
| 46 |
% \pgfpathmoveto{\pgfpointpolar{0}{4mm}} |
| 47 |
% \pgfpathlineto{\pgfpointpolar{144}{4mm}} |
| 48 |
% \pgfpathlineto{\pgfpointpolar{288}{4mm}} |
| 49 |
% \pgfpathlineto{\pgfpointpolar{72}{4mm}} |
| 50 |
% \pgfpathlineto{\pgfpointpolar{216}{4mm}} |
| 51 |
% \pgfpathclose% |
| 52 |
% \pgfusepath{stroke} |
| 53 |
% } |
| 54 |
% |
| 55 |
\def\pgfdeclarepatternformonly{% |
| 56 |
\def\pgf@pattern@type{formonly}% |
| 57 |
\pgfutil@ifnextchar[{\pgf@declarepattern@checkarg}{\pgf@declarepattern@checkarg[]}% |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
% Creates a new colored pattern |
| 62 |
% |
| 63 |
% [#1] = optional list of variables. |
| 64 |
% #2 = pattern name |
| 65 |
% #3 = lower left of bounding box |
| 66 |
% #4 = upper right of bounding box |
| 67 |
% #5 = step vector |
| 68 |
% #6 = pattern code |
| 69 |
% |
| 70 |
% Description: |
| 71 |
% |
| 72 |
% Declares a new colored pattern. Such patterns have a one or more |
| 73 |
% fixed inherent colors. See the pdf-manual for more details on |
| 74 |
% uncolored patterns. |
| 75 |
% |
| 76 |
% The parameters have the same effect as for uncolored patterns. |
| 77 |
% |
| 78 |
% Example: |
| 79 |
% |
| 80 |
% \pgfdeclarepatterninherentlycolored{red stars}{\pgfpointorigin}{\pgfpoint{1cm}{1cm}} |
| 81 |
% {\pgfpoint{1cm}{1cm}}{ |
| 82 |
% \pgfsetfillcolor{red} |
| 83 |
% \pgfsetstrokecolor{black} |
| 84 |
% \pgftransformshift{\pgfpoint{.5cm}{.5cm}} |
| 85 |
% \pgfpathmoveto{\pgfpointpolar{0}{4mm}} |
| 86 |
% \pgfpathlineto{\pgfpointpolar{144}{4mm}} |
| 87 |
% \pgfpathlineto{\pgfpointpolar{288}{4mm}} |
| 88 |
% \pgfpathlineto{\pgfpointpolar{72}{4mm}} |
| 89 |
% \pgfpathlineto{\pgfpointpolar{216}{4mm}} |
| 90 |
% \pgfpathclose% |
| 91 |
% \pgfusepath{stroke,fill} |
| 92 |
% } |
| 93 |
% |
| 94 |
\def\pgfdeclarepatterninherentlycolored{% |
| 95 |
\def\pgf@pattern@type{inherentlycolored}% |
| 96 |
\pgfutil@ifnextchar[{\pgf@declarepattern@checkarg}{\pgf@declarepattern@checkarg[]}% |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
\def\pgf@declarepattern@checkarg[#1]{% |
| 104 |
\def\pgf@pattern@tempvars{#1}% |
| 105 |
\ifx\pgf@pattern@tempvars\pgfutil@empty% |
| 106 |
\expandafter\let\expandafter\pgf@next\csname pgf@declarepattern\pgf@pattern@type\endcsname% |
| 107 |
\else% |
| 108 |
\expandafter\let\expandafter\pgf@next\csname pgf@declarepattern\pgf@pattern@type @mutable\endcsname% |
| 109 |
\fi% |
| 110 |
\pgf@next} |
| 111 |
|
| 112 |
\long\def\pgf@declarepatternformonly#1#2#3#4#5{\pgf@declarepattern{#1}{#2}{#3}{#4}{#5}{0}} |
| 113 |
|
| 114 |
\long\def\pgf@declarepatterninherentlycolored#1#2#3#4#5{\pgf@declarepattern{#1}{#2}{#3}{#4}{#5}{1}} |
| 115 |
|
| 116 |
\long\def\pgf@declarepatternformonly@mutable#1#2#3#4#5{% |
| 117 |
\def\pgf@marshal{\pgf@declarepatternmutable{#1}}% |
| 118 |
\expandafter\pgf@marshal\expandafter{\pgf@pattern@tempvars}{#2}{#3}{#4}{#5}{2}% |
| 119 |
} |
| 120 |
|
| 121 |
\long\def\pgf@declarepatterninherentlycolored@mutable#1#2#3#4#5#6{% |
| 122 |
\def\pgf@marshal{\pgf@declarepatternmutable{#1}}% |
| 123 |
\expandafter\pgf@marshal\expandafter{\pgf@pattern@tempvars}{#2}{#3}{#4}{#5}{3}% |
| 124 |
} |
| 125 |
|
| 126 |
\def\pgfsys@patternmatrix{{1.0}{0.0}{0.0}{1.0}{0.0pt}{0.0pt}} |
| 127 |
\def\pgf@declarepattern#1#2#3#4#5#6{% |
| 128 |
\pgfutil@ifundefined{pgf@pattern@name@#1}{% |
| 129 |
\pgfsysprotocol@getcurrentprotocol\pgf@pattern@temp% |
| 130 |
{% |
| 131 |
\pgfinterruptpath% |
| 132 |
\pgfpicturetrue% |
| 133 |
\pgf@relevantforpicturesizefalse% |
| 134 |
\pgftransformreset% |
| 135 |
\pgfsysprotocol@setcurrentprotocol\pgfutil@empty% |
| 136 |
\pgfsysprotocol@bufferedtrue% |
| 137 |
\pgfsys@beginscope% |
| 138 |
\pgfsetarrows{-}% |
| 139 |
#5% |
| 140 |
\pgfsys@endscope% |
| 141 |
\pgfsysprotocol@getcurrentprotocol\pgf@pattern@code% |
| 142 |
\global\let\pgf@pattern@code=\pgf@pattern@code% |
| 143 |
\endpgfinterruptpath% |
| 144 |
\pgf@process{#2}% |
| 145 |
\pgf@xa=\pgf@x% |
| 146 |
\pgf@ya=\pgf@y% |
| 147 |
\pgf@process{#3}% |
| 148 |
\pgf@xb=\pgf@x% |
| 149 |
\pgf@yb=\pgf@y% |
| 150 |
\pgf@process{#4}% |
| 151 |
\pgf@xc=\pgf@x% |
| 152 |
\pgf@yc=\pgf@y% |
| 153 |
% Now, build a name for the pattern |
| 154 |
\pgfutil@tempcnta=\pgf@pattern@number% |
| 155 |
\advance\pgfutil@tempcnta by1\relax% |
| 156 |
\xdef\pgf@pattern@number{\the\pgfutil@tempcnta}% |
| 157 |
\expandafter\xdef\csname pgf@pattern@name@#1\endcsname{\the\pgfutil@tempcnta}% |
| 158 |
\expandafter\gdef\csname pgf@pattern@type@#1\endcsname{#6}% |
| 159 |
\xdef\pgf@marshal{\noexpand\pgfsys@declarepattern |
| 160 |
{\csname pgf@pattern@name@#1\endcsname}% name |
| 161 |
{\the\pgf@xa}{\the\pgf@ya}{\the\pgf@xb}{\the\pgf@yb}% bbox |
| 162 |
{\the\pgf@xc}{\the\pgf@yc}% x/y step |
| 163 |
\pgfsys@patternmatrix% transformation matrix |
| 164 |
{\pgf@pattern@code}{#6}}% |
| 165 |
}% |
| 166 |
\pgfsysprotocol@setcurrentprotocol\pgf@pattern@temp% |
| 167 |
\expandafter\global\expandafter\let\csname pgf@pattern@instantiate@#1\endcsname=\pgf@marshal% |
| 168 |
} |
| 169 |
{% |
| 170 |
\pgferror{Pattern `#1' already defined}% |
| 171 |
}% |
| 172 |
} |
| 173 |
|
| 174 |
\def\pgf@pattern@number{0}% |
| 175 |
|
| 176 |
\def\pgf@declarepatternmutable#1#2#3#4#5#6#7{% |
| 177 |
\pgfutil@ifundefined{pgf@pattern@name@#1}{% |
| 178 |
\expandafter\gdef\csname pgf@pattern@name@#1\endcsname{#1}% |
| 179 |
\expandafter\gdef\csname pgf@pattern@variables@#1\endcsname{#2}% |
| 180 |
\expandafter\gdef\csname pgf@pattern@lowerleft@#1\endcsname{#3}% |
| 181 |
\expandafter\gdef\csname pgf@pattern@upperright@#1\endcsname{#4}% |
| 182 |
\expandafter\gdef\csname pgf@pattern@tilesize@#1\endcsname{#5}% |
| 183 |
\expandafter\long\expandafter\gdef\csname pgf@pattern@code@#1\endcsname{#6}% |
| 184 |
\expandafter\gdef\csname pgf@pattern@type@#1\endcsname{#7}% |
| 185 |
}{\pgferror{The pattern `#1' is already defined}}% |
| 186 |
} |
| 187 |
|
| 188 |
\def\pgf@ifpatternisinherentlycolored#1#2#3{% |
| 189 |
\expandafter\ifodd\csname pgf@pattern@type@#1\endcsname\relax#2\else#3\fi% |
| 190 |
} |
| 191 |
|
| 192 |
\def\pgf@ifpatternismutable#1#2#3{% |
| 193 |
\expandafter\ifnum\csname pgf@pattern@type@#1\endcsname>1\relax#2\else#3\fi% |
| 194 |
} |
| 195 |
|
| 196 |
\def\pgfpatternreleasename#1{\expandafter\let\csname pgf@pattern@name@#1\endcsname\relax} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
% Set an pattern as fill color |
| 204 |
% |
| 205 |
% #1 = Name of the pattern |
| 206 |
% #2 = Color to be used for the pattern. If the pattern is already |
| 207 |
% colored, this parameter is ignored. |
| 208 |
% |
| 209 |
% Description: |
| 210 |
% |
| 211 |
% Sets the pattern for subsequent filling operations. |
| 212 |
% |
| 213 |
% Example: |
| 214 |
% |
| 215 |
% \pgfsetfillpattern{stars}{red} |
| 216 |
% |
| 217 |
\def\pgfsetfillpattern#1#2{% |
| 218 |
\pgfutil@ifundefined{pgf@pattern@name@#1}% |
| 219 |
{% |
| 220 |
\pgferror{Undefined pattern `#1'}% |
| 221 |
}% |
| 222 |
{% |
| 223 |
\pgf@ifpatternismutable{#1}% |
| 224 |
{% |
| 225 |
% So, a mutable pattern. Check to see if the pattern |
| 226 |
% has been used with the current variable values... |
| 227 |
\let\pgf@pattern@tempvars\pgfutil@empty% |
| 228 |
\expandafter\expandafter\expandafter\pgf@pattern@check@vars% |
| 229 |
\csname pgf@pattern@variables@#1\endcsname,\pgf@stop,% |
| 230 |
\edef\pgf@pattern@nametemp{pgf@pattern@#1@\pgf@pattern@tempvars}% |
| 231 |
\expandafter\pgfutil@ifundefined\expandafter{\pgf@pattern@nametemp}% |
| 232 |
{% |
| 233 |
% ...Nope. So declare a new instance of the mutable pattern. |
| 234 |
\pgf@ifpatternisinherentlycolored{#1}% |
| 235 |
{\let\pgf@set@fillpattern@declare\pgfdeclarepatterninherentlycolored}% |
| 236 |
{\let\pgf@set@fillpattern@declare\pgfdeclarepatternformonly}% |
| 237 |
\pgf@set@fillpattern@declare% |
| 238 |
{\pgf@pattern@nametemp}% |
| 239 |
{\csname pgf@pattern@lowerleft@#1\endcsname}% |
| 240 |
{\csname pgf@pattern@upperright@#1\endcsname}% |
| 241 |
{\csname pgf@pattern@tilesize@#1\endcsname}% |
| 242 |
{\csname pgf@pattern@code@#1\endcsname}% |
| 243 |
}% |
| 244 |
{% |
| 245 |
% ...Yep. So do nothing. |
| 246 |
}% |
| 247 |
\expandafter\pgf@set@fillpattern\expandafter{\pgf@pattern@nametemp}{#2}% |
| 248 |
\expandafter\gdef\csname\pgf@pattern@nametemp\endcsname{#1}% |
| 249 |
}% |
| 250 |
{% |
| 251 |
% A non-mutable pattern. |
| 252 |
\pgf@set@fillpattern{#1}{#2}% |
| 253 |
}% |
| 254 |
}% |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
\def\pgf@set@fillpattern#1#2{% |
| 259 |
\pgfutil@ifundefined{pgf@pattern@name@#1}{% |
| 260 |
\pgferror{Undefined pattern `#1'}} |
| 261 |
{% |
| 262 |
\csname pgf@pattern@instantiate@#1\endcsname% |
| 263 |
\expandafter\global\expandafter\let\csname pgf@pattern@instantiate@#1\endcsname=\relax% |
| 264 |
\pgf@ifpatternisinherentlycolored{#1}{% |
| 265 |
\pgfsys@setpatterncolored{\csname pgf@pattern@name@#1\endcsname}% |
| 266 |
}{% |
| 267 |
\pgfutil@colorlet{pgf@tempcolor}{#2}% |
| 268 |
\pgfutil@ifundefined{applycolormixins}{}{\applycolormixins{pgf@tempcolor}}% |
| 269 |
\pgfutil@extractcolorspec{pgf@tempcolor}{\pgf@tempcolor}% |
| 270 |
\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{rgb}{\pgf@rgbcolor}% |
| 271 |
\expandafter\pgf@set@fill@patternuncolored\pgf@rgbcolor\relax{#1}% |
| 272 |
}% |
| 273 |
}% |
| 274 |
} |
| 275 |
|
| 276 |
\def\pgf@set@fill@patternuncolored#1,#2,#3\relax#4{% |
| 277 |
\pgfsys@setpatternuncolored{\csname pgf@pattern@name@#4\endcsname}{#1}{#2}{#3}% |
| 278 |
} |
| 279 |
|
| 280 |
\def\pgf@pattern@check@vars#1,{% |
| 281 |
\ifx#1\pgf@stop% |
| 282 |
\let\pgf@next\relax% |
| 283 |
\else% |
| 284 |
\afterassignment\pgfmath@gobbletilpgfmath@% |
| 285 |
\expandafter\let\expandafter\pgf@pattern@char#1#1\pgfmath@% |
| 286 |
\ifx\pgf@pattern@char/% |
| 287 |
\edef\pgf@pattern@tempvar{(\pgfkeysvalueof{#1})}% |
| 288 |
\else% |
| 289 |
\expandafter\ifcat\pgf@pattern@char\relax% |
| 290 |
\edef\pgf@pattern@tempvar{(\the#1)}% |
| 291 |
\else% |
| 292 |
\edef\pgf@pattern@tempvar{(#1)}% |
| 293 |
\fi% |
| 294 |
\fi% |
| 295 |
\edef\pgf@pattern@tempvars{\pgf@pattern@tempvars\pgf@pattern@tempvar}% |
| 296 |
\let\pgf@next\pgf@pattern@check@vars% |
| 297 |
\fi% |
| 298 |
\pgf@next% |
| 299 |
} |
| 300 |
|
| 301 |
\endinput |