Debian Codegraph @

texmf-dist/tex/generic/pgfplots/util/pgfplotscolor.code.tex

raw
1 %--------------------------------------------
2 %
3 % Package pgfplots
4 %
5 % Provides a user-friendly interface to create function plots (normal
6 % plots, semi-logplots and double-logplots).
7 %
8 % It is based on Till Tantau's PGF package.
9 %
10 % Copyright 2007-2013 by Christian Feuersänger.
11 %
12 % This program is free software: you can redistribute it and/or modify
13 % it under the terms of the GNU General Public License as published by
14 % the Free Software Foundation, either version 3 of the License, or
15 % (at your option) any later version.
16 %
17 % This program is distributed in the hope that it will be useful,
18 % but WITHOUT ANY WARRANTY; without even the implied warranty of
19 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 % GNU General Public License for more details.
21 %
22 % You should have received a copy of the GNU General Public License
23 % along with this program. If not, see <http://www.gnu.org/licenses/>.
24 %
25 %--------------------------------------------
26
27 \pgfkeys{
28 /pgfplots/color sequence/reset/.style={
29 /pgfplots/color sequence/colorspace,
30 /pgfplots/color sequence/default input colorspace,
31 /pgfplots/color sequence/every input component/.code=,
32 /pgfplots/color sequence/context message,
33 },
34 /pgfplots/color sequence/colorspace/.initial=auto,
35 /pgfplots/color sequence/colorspace/.default=auto,
36 /pgfplots/color sequence/default input colorspace/.initial=,
37 /pgfplots/color sequence/default input colorspace/.default=\pgfkeysvalueof{/pgfplots/color sequence/colorspace},
38 % applied to every INPUT component, i.e. before transforming it to some target color space.
39 /pgfplots/color sequence/every input component/.code=,
40 /pgfplots/color sequence/context message/.code={\def\pgfplotscolornormalizesequence@context@message{#1}},
41 /pgfplots/color sequence/context message/.default=\pgfplotscolornormalizesequence@context@message@default,
42 /pgfplots/color sequence/reset,
43 }
44
45 \newif\ifpgfplotscolor@colorspaceknown
46
47 % the beginning of a normalized color sequence.
48 %
49 % It is to be used like
50 % \pgfplotscolornormalizesequence[colorspace=rgb]
51 %
52 % \pgfplotscolornormalizesequencenext{1,1,1}
53 % -> \pgfplotsretval = {1,1,1} % uses default colorspace
54 % \pgfplotscolornormalizesequencenext{color=red}
55 % -> \pgfplotsretval = {1,0,0}
56 % \pgfplotscolornormalizesequencenext{color=blue}
57 % -> \pgfplotsretval = {0,0,1}
58 % \pgfplotscolornormalizesequencenext{rgb=1,0,0}
59 % -> \pgfplotsretval = {1,0,0}
60 % \pgfplotscolornormalizesequencenext{cmyk=1,0,0,1}
61 % -> \pgfplotsretval = {<converted value>}
62 %
63 % \endpgfplotscolornormalizesequence
64 %
65 % Every color provided in the sequence will be normalized by
66 % transforming it to the common color space and by computing the
67 % separate components representing the color in that space.
68 %
69 % These components are available for use in interpolation routines.
70 %
71 % #1 : keys in the /pgfplots/color sequence path
72 \def\pgfplotscolornormalizesequence[#1]{%
73 \pgfqkeys{/pgfplots/color sequence}{%
74 #1,%
75 }%
76 \pgfkeysgetvalue{/pgfplots/color sequence/colorspace}\pgfplots@loc@TMPa
77 \pgfkeysgetvalue{/pgfplots/color sequence/default input colorspace}\pgfplotscolornormalizesequence@colspace@input
78 \edef\pgfplotscolornormalizesequence@colspace@input{\pgfplotscolornormalizesequence@colspace@input}%
79 \pgfkeysgetvalue{/pgfplots/color sequence/every input component/.@cmd}\pgfplotscolornormalizesequencenext@every@component
80 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
81 \def\pgfplots@loc@TMPb{auto}%
82 \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa
83 % colorspace=auto: same as empty.
84 \let\pgfplots@loc@TMPa=\pgfutil@empty
85 \fi
86 \ifx\pgfplots@loc@TMPa\pgfutil@empty
87 % colorspace=auto:
88 \def\pgfplotscolornormalizesequence@colspace{}%
89 \else
90 \def\pgfplots@loc@TMPb{rgb}%
91 \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa
92 % colorspace=rgb:
93 \def\pgfplotscolornormalizesequence@colspace{rgb}%
94 \else
95 \def\pgfplots@loc@TMPb{cmyk}%
96 \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa
97 % colorspace=cmyk:
98 \def\pgfplotscolornormalizesequence@colspace{cmyk}%
99 \else
100 \def\pgfplots@loc@TMPb{gray}%
101 \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa
102 % colorspace=gray:
103 \def\pgfplotscolornormalizesequence@colspace{gray}%
104 \else
105 \pgfplots@error{Sorry, the choice colorspace=\pgfplots@loc@TMPa\space is unsupported as interpolation colorspace in pgfplots, please use one of 'auto,rgb,cmyk,gray'}%
106 \fi
107 \fi
108 \fi
109 \fi
110 }%
111
112 % ends a normalized color sequence and returns the final colorspace
113 % and its number of components into \pgfplotsretval and
114 % \pgfplotsretvalb, respectively
115 \def\endpgfplotscolornormalizesequence{%
116 \let\pgfplotsretval=\pgfplotscolornormalizesequence@colspace
117 \pgfplotscolor@get@num@components{\pgfplotsretval}{\pgfplotsretvalb}%
118 \pgfqkeys{/pgfplots/color sequence}{reset}%
119 }%
120
121 % accepts the next color in a sequence of colors. The color will be
122 % normalized and the normalized result written to \pgfplotsretval.
123 %
124 % SEE \pgfplotscolornormalizesequencenext -- it is MUCH more powerful!
125 %
126 % #1 the color space of the color.
127 % #2 the components of the color, separated by comma.
128 %
129 % POSTCONDITION:
130 % \pgfplotsretval contains '{<color space>}{<comma-separated-components>}'
131 % -> including the curly braces.
132 %
133 % \pgfplotsretvalb contains the number of input components in
134 % \pgfplotsretval
135 \def\pgfplotscolornormalizesequencenextbycomponents#1#2{%
136 \edef\pgfplotscolornormalizesequence@cur@colspace{#1}%
137 \pgfplotscolornormalizesequencenextbycomponents@normalize@components{#2}%
138 %
139 \ifx\pgfplotscolornormalizesequence@cur@colspace\pgfplotscolornormalizesequence@colspace
140 \else
141 \ifx\pgfplotscolornormalizesequence@colspace\pgfutil@empty
142 \pgfplotscolornormalizesequencenextbycomponents@assign@auto@colspace
143 \fi
144 %
145 \ifx\pgfplotscolornormalizesequence@colspace\pgfplotscolornormalizesequence@cur@colspace
146 % Ah, ok - the colorspace is NOW the correct one (because
147 % we chose it as the colorspace for this complete color
148 % sequence.
149 \else
150 % Oh. We need to convert the color space!
151 \edef\pgfplots@loc@TMPa{{\pgfplotscolornormalizesequence@cur@colspace}{\pgfplotsretval}}%
152 \expandafter\pgfutil@convertcolorspec\pgfplots@loc@TMPa
153 {\pgfplotscolornormalizesequence@colspace}% target color spaces
154 {\pgfplotsretval}% target macro
155 \fi
156 \fi
157 \edef\pgfplotsretval{\pgfplotsretval}%
158 \pgfplotscolor@get@num@components{\pgfplotscolornormalizesequence@colspace}{\pgfplotsretvalb}%
159 }
160
161 \def\pgfplotscolornormalizesequencenextbycomponents@assign@auto@colspace{%
162 % Ah; we have '/pgfplots/color sequence/colorspace=auto'.
163 % Well, check if the current colorspace (stored in
164 % \pgfplotscolornormalizesequence@cur@colspace) is suitable.
165 %
166 % It is suitable if it is rgb or cmyk. In all other cases,
167 % we choose either rgb or cmyk. More precisely. 'cmy' is
168 % mapped to cmyk. All other cases are treated as rgb.
169 %
170 \def\pgfplots@loc@TMPa{cmyk}%
171 \ifx\pgfplotscolornormalizesequence@cur@colspace\pgfplots@loc@TMPa
172 \let\pgfplotscolornormalizesequence@colspace=\pgfplotscolornormalizesequence@cur@colspace
173 \else
174 \def\pgfplots@loc@TMPa{cmy}%
175 \ifx\pgfplotscolornormalizesequence@cur@colspace\pgfplots@loc@TMPa
176 \def\pgfplotscolornormalizesequence@colspace{cmyk}%
177 \else
178 % rgb appears to be the best choice: (1) it is backwards
179 % compatible and (2) gray or something like that might fit
180 % badly to any other colors in the sequence.
181 \def\pgfplotscolornormalizesequence@colspace{rgb}%
182 \fi
183 \fi
184 }
185
186 % #1: color components
187 %
188 % PRECONDITION: \pgfplotscolornormalizesequence@cur@colspace is the
189 % current color space
190 %
191 % POSTCONDITION: \pgfplotsretval contains the normalized color
192 % components
193 \def\pgfplotscolornormalizesequencenextbycomponents@normalize@components#1{%
194 \pgfutil@ifundefined{pgfplots@colspace@name@\pgfplotscolornormalizesequence@cur@colspace}{%
195 \pgfplotscolor@colorspaceknownfalse
196 }{%
197 \pgfplotscolor@colorspaceknowntrue
198 }%
199 \edef\pgfplots@loc@TMPb{#1}%
200 \def\pgfplotsretval{}%
201 \c@pgf@counta=0 %
202 \expandafter\pgfplotscolornormalizesequencenext@prepare@loop\pgfplots@loc@TMPb,\pgfplots@EOI,%
203 }%
204
205 % assigns the number of color components for the given colorspace to
206 % \pgfplotsretval
207 \def\pgfplotscolorspacegetcomponents#1{%
208 \pgfplotscolor@get@num@components{#1}{\pgfplotsretval}%
209 }%
210
211 % Defines \pgfplotsretval to contain the number of components in the
212 % color space.
213 \def\pgfplotscolornormalizesequencegetnumcomponents{%
214 \ifx\pgfplotscolornormalizesequence@colspace\pgfutil@empty
215 \pgfplotsthrow{invalid argument}{\pgfplots@loc@TMPa}{Cannot create color with zero components: no colorspace set for the normalized color sequence.}\pgfeov%
216 \fi
217 \pgfplotscolorspacegetcomponents{\pgfplotscolornormalizesequence@colspace}%
218 }%
219
220 \def\pgfplotscolor@get@num@components#1#2{%
221 \pgfutil@ifundefined{pgfplots@colspace@numcomp@#1}{%
222 \pgfplotsthrow{invalid argument}{\pgfplots@loc@TMPa}{The input color has an unsupported color space '#1'}\pgfeov%
223 }{%
224 \edef#2{\csname pgfplots@colspace@numcomp@#1\endcsname}%
225 }%
226 }%
227
228
229 \def\pgfplots@colspace@numcomp@gray{1}%
230 \def\pgfplots@colspace@name@gray{gray}%
231
232 \def\pgfplots@colspace@numcomp@rgb{3}%
233 \def\pgfplots@colspace@name@rgb{rgb}%
234
235 \def\pgfplots@colspace@numcomp@cmyk{4}%
236 \def\pgfplots@colspace@name@cmyk{cmyk}%
237
238 \def\pgfplots@colspace@numcomp@cmy{3}%
239 \def\pgfplots@colspace@name@cmy{cmy}%
240
241 \def\pgfplots@colspace@numcomp@wave{1}%
242 \def\pgfplots@colspace@name@wave{wave}%
243 \pgfutil@namedef{pgfplots@colspace@minaccept@wave@0}{362.998}%
244 \pgfutil@namedef{pgfplots@colspace@min@wave@0}{363}%
245 \pgfutil@namedef{pgfplots@colspace@maxaccept@wave@0}{814.001}%
246 \pgfutil@namedef{pgfplots@colspace@max@wave@0}{814}%
247
248 \def\pgfplots@colspace@numcomp@Hsb{3}%
249 \def\pgfplots@colspace@name@Hsb{Hsb}%
250 \pgfutil@namedef{pgfplots@colspace@minaccept@Hsb@0}{-0.001}%
251 \pgfutil@namedef{pgfplots@colspace@min@Hsb@0}{0}%
252 \pgfutil@namedef{pgfplots@colspace@maxaccept@Hsb@0}{\rangeHsb}%
253 \pgfutil@namedef{pgfplots@colspace@max@Hsb@0}{\rangeHsb}%
254
255 \def\pgfplotscolornormalizesequencenext@prepare@loop#1,{%
256 \def\pgfmathresult{#1}%
257 \ifx\pgfmathresult\pgfplots@EOI
258 \else
259 \begingroup
260 \pgfkeyslet{/pgf/fpu/handlers/invalid number/.@cmd}\pgfplotscolornormalizesequencenextbycomponents@parsenumber@error
261 \expandafter\pgfplotscolornormalizesequencenext@every@component\expandafter{\pgfmathresult}\pgfeov%
262 \ifpgfplotscolor@colorspaceknown
263 \expandafter\pgfplotscolornormalizesequencenextbycomponents@parsenumber\expandafter{\pgfmathresult}%
264 \fi
265 \pgfmath@smuggleone\pgfmathresult
266 \endgroup
267 \ifpgfplotscolor@colorspaceknown
268 \expandafter\pgfplotscolornormalizesequencenextbycomponents@sanitize\expandafter{\pgfmathresult}%
269 \fi
270 \ifx\pgfplotsretval\pgfutil@empty
271 \edef\pgfplotsretval{\pgfmathresult}%
272 \else
273 \edef\pgfplotsretval{\pgfplotsretval,\pgfmathresult}%
274 \fi
275 \advance\c@pgf@counta by1 %
276 \expandafter\pgfplotscolornormalizesequencenext@prepare@loop
277 \fi
278 }
279
280 \def\pgfplotscolornormalizesequencenextbycomponents@parsenumber#1{%
281 \pgfmathfloatparsenumber{#1}%
282 \pgfmathfloattofixed\pgfmathresult
283 }
284
285 \def\pgfplotscolornormalizesequencenextbycomponents@parsenumber@error#1#2\pgfeov{%
286 \pgfplotsthrow{invalid color component}{\pgfmathresult}{Sorry, the color component value '#1' is no number. Did you mean 'color=#1'? The error occurred near `\pgfplotscolornormalizesequence@context@message'}\pgfeov%
287 \pgfmathfloatcreate{0}{0.0}{0}%
288 }%
289
290 % #1 the color component value
291 \def\pgfplotscolornormalizesequencenextbycomponents@sanitize#1{%
292 \pgf@xa=#1pt %
293 %
294 % check if we have something like
295 % \csname pgfplots@colspace@minaccept@<colorspace name>@2\endcsname where 2 is component index:
296 \edef\pgfplots@loc@TMPc{@\pgfplotscolornormalizesequence@cur@colspace @\the\c@pgf@counta}%
297 \pgfutil@ifundefined{pgfplots@colspace@minaccept\pgfplots@loc@TMPc}{%
298 % NO - implicitly defined to [0,1]
299 \def\pgfplots@colspace@minaccept@@{-0.001}%
300 \def\pgfplots@colspace@min@@{-0.001}%
301 \def\pgfplots@colspace@maxaccept@@{1.001}%
302 \def\pgfplots@colspace@max@@{1}%
303 }{%
304 % YES - expect all four values:
305 \edef\pgfplots@colspace@minaccept@@{\csname pgfplots@colspace@minaccept\pgfplots@loc@TMPc\endcsname}%
306 \edef\pgfplots@colspace@min@@{\csname pgfplots@colspace@min\pgfplots@loc@TMPc\endcsname}%
307 \edef\pgfplots@colspace@maxaccept@@{\csname pgfplots@colspace@maxaccept\pgfplots@loc@TMPc\endcsname}%
308 \edef\pgfplots@colspace@max@@{\csname pgfplots@colspace@max\pgfplots@loc@TMPc\endcsname}%
309 }%
310 \ifdim\pgf@xa<\pgfplots@colspace@minaccept@@ pt %
311 \edef\pgfmathresult{\pgfplots@colspace@min@@}%
312 \pgfplotscolor@rangeexception{#1}%
313 \else
314 \ifdim\pgf@xa>\pgfplots@colspace@maxaccept@@ pt %
315 \edef\pgfmathresult{\pgfplots@colspace@max@@}%
316 \pgfplotscolor@rangeexception{#1}%
317 \else
318 % Ah - the common case!
319 \edef\pgfmathresult{\pgf@sys@tonumber\pgf@xa}% normalize number (strip trailing zeros etc).
320 \fi
321 \fi
322 }
323
324 \def\pgfplotscolor@rangeexception#1{%
325 \pgfplotsthrow{invalid color component}{\pgfmathresult}{Sorry, the color component value #1 (no. \the\c@pgf@counta) is out of range. The allowed range is 0 <= value <= 1. The error occurred near `\pgfplotscolornormalizesequence@context@message'}\pgfeov%
326 }
327
328
329 % Same as \pgfplotscolornormalizesequencenextbycomponents but with
330 % more freedom in the input.
331 %
332 % #1 some color.
333 % Accepted formats:
334 % 'color=<xcolor value>'
335 % <xcolor value> is any valid expression of the xcolor package.
336 %
337 % 'rgb=R,G,B'
338 % R,G,B are numbers in [0,1]
339 %
340 % 'rgb255=R,G,B'
341 % R,G,B are numbers in [0,255]
342 %
343 % 'cmyk=C,M,Y,K'
344 % C, M, Y, and K are numbers in [0,1]
345 %
346 % 'cmyk255=C,M,Y,K'
347 % C, M, Y, and K are numbers in [0,255]
348 %
349 % 'gray=G'
350 % G is a gray scale number in [0,1]
351 %
352 % 'C1,C2,C3'
353 % any number of Ci can follow, each is interpreted in the default
354 % colorspace (i.e. the one set before at the beginning of the
355 % sequence)
356 %
357 %
358 % Example:
359 % \pgfplotscolornormalizesequencenext{color=blue}
360 % \pgfplotscolornormalizesequencenext{rgb=1,0,0}
361 % \pgfplotscolornormalizesequencenext{cmyk=1,0,0,1}
362 % \pgfplotscolornormalizesequencenext{1,0,0} (interpreted in the
363 % colorspace set at \pgfplotscolornormalizesequence)
364 %
365 % POSTCONDITION: see \pgfplotscolornormalizesequencenextbycomponents
366 \def\pgfplotscolornormalizesequencenext#1{%
367 \edef\pgfplotscolornormalizesequence@context@message@default{#1}%
368 \expandafter\pgfplotscolornormalizesequencenext@\pgfplotscolornormalizesequence@context@message@default\pgfplots@EOI
369 }
370 \def\pgfplotscolornormalizesequencenext@{%
371 \pgfutil@ifnextchar c{%
372 \pgfplotscolornormalizesequencenext@c
373 }{%
374 \pgfutil@ifnextchar r{%
375 \pgfplotscolornormalizesequencenext@rgb
376 }{%
377 \pgfutil@ifnextchar g{%
378 \pgfplotscolornormalizesequencenext@gray
379 }{%
380 \pgfplotscolornormalizesequencenext@defaultcolspace
381 }%
382 }%
383 }%
384 }
385
386 \def\pgfplotscolornormalizesequencenext@gray gray=#1\pgfplots@EOI{%
387 % FIXME : we might be better off with real support for a gray
388 % colorspace!
389 \pgfplotscolornormalizesequencenextbycomponents{rgb}{#1,#1,#1}%
390 }
391
392 \def\pgfplotscolornormalizesequencenext@defaultcolspace#1\pgfplots@EOI{%
393 \edef\pgfplotsretval{#1}%
394 \ifx\pgfplotsretval\pgfutil@empty
395 % hm. Ok, simply return the empty input.
396 %
397 % ... and the number of components.
398 \pgfplotscolor@get@num@components{\pgfplotscolornormalizesequence@colspace}{\pgfplotsretvalb}%
399 %
400 \else
401 \expandafter\pgfutil@in@\expandafter=\expandafter{\pgfplotsretval}%
402 \ifpgfutil@in@
403 \expandafter\pgfplotscolornormalizesequencenext@unknown@colspace\pgfplotsretval\pgfplots@EOI
404 \else
405 \ifx\pgfplotscolornormalizesequence@colspace@input\pgfutil@empty
406 \pgfplotsthrow{invalid argument}{\pgfplots@loc@TMPa}{The input color #1 cannot be interpreted; please assign a default color space first}\pgfeov%
407 \fi
408 \pgfplotscolornormalizesequencenextbycomponents{\pgfplotscolornormalizesequence@colspace@input}{#1}%
409 \fi
410 \fi
411 }
412
413 \def\pgfplotscolornormalizesequencenext@unknown@colspace#1=#2\pgfplots@EOI{%
414 \pgfplotscolornormalizesequencenextbycomponents{#1}{#2}%
415 }
416
417 \def\pgfplotscolornormalizesequencenext@rgb rgb{%
418 \pgfutil@ifnextchar2{%
419 \pgfplotscolornormalizesequencenext@rgb@two@five@five
420 }{%
421 \pgfplotscolornormalizesequencenext@rgb@plain
422 }%
423 }
424 \def\pgfplotscolornormalizesequencenext@rgb@plain=#1\pgfplots@EOI{%
425 \pgfplotscolornormalizesequencenextbycomponents{rgb}{#1}%
426 }
427
428 \def\pgfplotscolorsequence@two@five@five@rescale#1{%
429 \pgfmath@basic@multiply@{0.003921568}{#1}%
430 }%
431 \def\pgfplotscolornormalizesequencenext@rgb@two@five@five255=#1,#2,#3\pgfplots@EOI{%
432 \pgfplotscolorsequence@two@five@five@rescale{#1}%
433 \let\pgfplots@loc@TMPa=\pgfmathresult
434 \pgfplotscolorsequence@two@five@five@rescale{#2}%
435 \let\pgfplots@loc@TMPb=\pgfmathresult
436 \pgfplotscolorsequence@two@five@five@rescale{#3}%
437 \edef\pgfplots@loc@TMPc{{rgb}{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfmathresult}}%
438 \expandafter\pgfplotscolornormalizesequencenextbycomponents\pgfplots@loc@TMPc%
439 }
440
441 \def\pgfplotscolornormalizesequencenext@c c{%
442 \pgfutil@ifnextchar m{%
443 \pgfplotscolornormalizesequencenext@cmyk
444 }{%
445 \pgfplotscolornormalizesequencenext@color
446 }%
447 }%
448
449 \def\pgfplotscolornormalizesequencenext@cmyk myk{%
450 \pgfutil@ifnextchar2{%
451 \pgfplotscolornormalizesequencenext@cmyk@two@five@five
452 }{%
453 \pgfplotscolornormalizesequencenext@cmyk@plain
454 }%
455 }%
456
457 \def\pgfplotscolornormalizesequencenext@cmyk@plain=#1\pgfplots@EOI{%
458 \pgfplotscolornormalizesequencenextbycomponents{cmyk}{#1}%
459 }%
460 \def\pgfplotscolornormalizesequencenext@cmyk@two@five@five255=#1,#2,#3,#4\pgfplots@EOI{%
461 \pgfplotscolorsequence@two@five@five@rescale{#1}%
462 \let\pgfplots@loc@TMPa=\pgfmathresult
463 \pgfplotscolorsequence@two@five@five@rescale{#2}%
464 \let\pgfplots@loc@TMPb=\pgfmathresult
465 \pgfplotscolorsequence@two@five@five@rescale{#3}%
466 \let\pgfplots@loc@TMPc=\pgfmathresult
467 \pgfplotscolorsequence@two@five@five@rescale{#4}%
468 \edef\pgfplots@loc@TMPc{{cmyk}{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc,\pgfmathresult}}%
469 \expandafter\pgfplotscolornormalizesequencenextbycomponents\pgfplots@loc@TMPc%
470 }
471
472 % The implementation of \pgfutil@extractcolorspec for plain tex and
473 % context is ... strange. I prefer one which does the same as the
474 % xcolor version (which is also what pgf does for latex):
475 \def\pgfplotsutil@extractcolorspec@xcolor@substitute#1#2{%
476 \begingroup
477 % this here relies on PGF's emulation of color in plain tex and
478 % context. Let's hope it works in the future...
479 \def\xcolor@##1##2##3##4{%
480 \edef#2{{##3}{##4}}%
481 }%
482 \csname\string\color@#1\endcsname
483 \global\let\pgfutil@extractcolorspec@@temp=#2%
484 \endgroup
485 \let#2=\pgfutil@extractcolorspec@@temp
486 }%
487
488 \def\pgfplots@glob@TMPa#1#2{%
489 \def#2{{#1}}%
490 }%
491
492 \pgfutil@IfUndefined{extractcolorspec}{%
493 % Ah. We do not have a suitable implementation of
494 % \extractcolorspec -- \pgfutil@extractcolorspec does not yield
495 % the colorspec on context and plain tex.
496 \def\pgfplotsutil@extractcolorspec{\pgfplotsutil@extractcolorspec@xcolor@substitute}%
497 }{%
498 \ifx\extractcolorspec\pgfplots@glob@TMPa
499 % Same problem as above: pgfutil-plain.def says
500 % \let\extractcolorspec=\pgfutil@extractcolorspec and that one
501 % is broken.
502 % Use my substitute:
503 \def\pgfplotsutil@extractcolorspec{\pgfplotsutil@extractcolorspec@xcolor@substitute}%
504 \else
505 \def\pgfplotsutil@extractcolorspec{\extractcolorspec}%
506 \fi
507 }%
508
509 \def\pgfplotscolornormalizesequencenext@color olor=#1\pgfplots@EOI{%
510 \pgfutil@colorlet{pgf@tempcol}{#1}%
511 \pgfplotsutil@extractcolorspec{pgf@tempcol}{\pgf@tempcolor}%
512 \edef\pgfplots@loc@TMPa{\expandafter\pgfutil@firstoftwo\pgf@tempcolor}%
513 \edef\pgfplots@loc@TMPb{\expandafter\pgfutil@secondoftwo\pgf@tempcolor}%
514 %
515 % I expect that \pgf@tempcolor is of the form
516 % {<colorspace>}{<comma-separated components>}
517 %
518 % unfortunately, the <colorspace> has strange catcodes such that
519 % we cannot easily compare it by means of \ifx. I normalize it
520 % here:
521 \pgfutil@ifundefined{pgfplots@colspace@name@\pgfplots@loc@TMPa}{%
522 % ohoh. we cannot normalize the name. Let's hope that works out.
523 % note that we cannot throw an exception here as we might very well be able
524 % to convert the color to some suitable color space!
525 }{%
526 \edef\pgfplots@loc@TMPa{%
527 \csname pgfplots@colspace@name@\pgfplots@loc@TMPa\endcsname%
528 }%
529 }%
530 \edef\pgf@tempcolor{%
531 {\pgfplots@loc@TMPa}%
532 {\pgfplots@loc@TMPb}%
533 }%
534 \expandafter\pgfplotscolornormalizesequencenextbycomponents\pgf@tempcolor%
535 %
536 }%
537
538 % Defines \pgfplotsretval to be a "neutral" color, i.e. one in which
539 % all components are zero.
540 % @see \pgfplotscolorzero
541 % @see \pgfplotscoloraddweighted
542 \def\pgfplotscolornormalizesequencezero{%
543 \pgfplotscolornormalizesequencegetnumcomponents
544 \pgfplotscolorzero{\pgfplotsretval}%
545 }
546
547 % Defines \pgfplotsretval to be a "neutral" color, i.e. one in which
548 % all components are zero.
549 %
550 % #1: the number of color components to be used (like 3 for rgb)
551 % @see \pgfplotscoloraddweighted
552 \def\pgfplotscolorzero#1{%
553 \csname pgfplotscolorzero@num@#1\endcsname
554 }%
555
556 \expandafter\def\csname pgfplotscolorzero@num@1\endcsname{\def\pgfplotsretval{0}}
557 \expandafter\def\csname pgfplotscolorzero@num@2\endcsname{\def\pgfplotsretval{0,0}}
558 \expandafter\def\csname pgfplotscolorzero@num@3\endcsname{\def\pgfplotsretval{0,0,0}}
559 \expandafter\def\csname pgfplotscolorzero@num@4\endcsname{\def\pgfplotsretval{0,0,0,0}}
560
561 % Defines \pgfplotsretval to be the interpolated color #1 + #2*#3.
562 % #1 the first color (like 0,0,0)
563 % #2 a scaling factor (like 4)
564 % #3 the second color (like 1,0,0.5)
565 %
566 % POSTCONDITION: \pgfplotsretval contains the result
567 %
568 % @see \pgfplotscolorzero
569 % @see \pgfplotscoloraddweighted
570 \def\pgfplotscolornormalizesequenceaddweighted#1#2#3{%
571 \begingroup
572 \pgfplotscolornormalizesequencegetnumcomponents
573 \global\let\pgfplots@glob@TMPd\pgfplotsretval
574 \endgroup
575 \pgfplotscoloraddweighted{\pgfplots@glob@TMPd}{#1}{#2}{#3}%
576 }
577
578 % Defines \pgfplotsretval to be the interpolated color #2 + #3*#4.
579 % #1 the number of color components to be used (3 for rgb)
580 % #2 the first color (like 0,0,0)
581 % #3 a scaling factor (like 4)
582 % #4 the second color (like 1,0,0.5)
583 %
584 % POSTCONDITION: \pgfplotsretval contains the result
585 %
586 % @see \pgfplotscolorzero
587 \def\pgfplotscoloraddweighted#1#2#3#4{%
588 \pgfplots@ifempty{#4}{%
589 \pgfplots@error{Illegal input argument encountered while computing colors:
590 one color argument is missing (was empty). Please ensure that you have explicit color values in your input}%
591 }{%
592 \expandafter\let
593 \expandafter\pgfplots@loc@TMPb\csname pgfplotscolornormalizesequencegetnumcomponents@#1\endcsname
594 \edef\pgfplots@loc@TMPa{#2:#4\noexpand\relax{#3}}%
595 \expandafter\pgfplots@loc@TMPb\pgfplots@loc@TMPa%
596 }%
597 }%
598
599 \def\pgfplotscolornormalizesequenceaddweighted@single#1#2#3{%
600 \pgf@xa=#1pt %
601 \pgf@xb=#3pt %
602 \advance\pgf@xa by#2\pgf@xb
603 \edef\pgfplotsretval{\pgf@sys@tonumber\pgf@xa}%
604 }%
605
606 \expandafter\def\csname pgfplotscolornormalizesequencegetnumcomponents@1\endcsname#1:#2\relax#3{%
607 \pgfplotscolornormalizesequenceaddweighted@single{#1}{#3}{#2}%
608 }%
609 \expandafter\def\csname pgfplotscolornormalizesequencegetnumcomponents@3\endcsname#1,#2,#3:#4,#5,#6\relax#7{%
610 \pgfplotscolornormalizesequenceaddweighted@single{#1}{#7}{#4}%
611 \let\pgfplots@loc@TMPa=\pgfplotsretval
612 \pgfplotscolornormalizesequenceaddweighted@single{#2}{#7}{#5}%
613 \let\pgfplots@loc@TMPb=\pgfplotsretval
614 \pgfplotscolornormalizesequenceaddweighted@single{#3}{#7}{#6}%
615 \let\pgfplots@loc@TMPc=\pgfplotsretval
616 \edef\pgfplotsretval{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc}%
617 }%
618 \expandafter\def\csname pgfplotscolornormalizesequencegetnumcomponents@4\endcsname#1,#2,#3,#4:#5,#6,#7,#8\relax#9{%
619 \pgfplotscolornormalizesequenceaddweighted@single{#1}{#9}{#5}%
620 \let\pgfplots@loc@TMPa=\pgfplotsretval
621 \pgfplotscolornormalizesequenceaddweighted@single{#2}{#9}{#6}%
622 \let\pgfplots@loc@TMPb=\pgfplotsretval
623 \pgfplotscolornormalizesequenceaddweighted@single{#3}{#9}{#7}%
624 \let\pgfplots@loc@TMPc=\pgfplotsretval
625 \pgfplotscolornormalizesequenceaddweighted@single{#4}{#9}{#8}%
626 \let\pgfplots@loc@TMPd=\pgfplotsretval
627 \edef\pgfplotsretval{\pgfplots@loc@TMPa,\pgfplots@loc@TMPb,\pgfplots@loc@TMPc,\pgfplots@loc@TMPd}%
628 }%
629
630 \endinput