colo-ini.mkiv /size: 48 Kb    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=colo-ini,
3%D        version=2007.08.08,
4%D          title=\CONTEXT\ Color Macros,
5%D       subtitle=Initialization,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D We need to clean this up further but first we have to make sure that mkiv
15%D code works ok.
16
17\writestatus{loading}{ConTeXt Color Macros / Initialization}
18
19%D Todo: move color space in color attribute (last two bits)
20
21%D This module implements color. Since \MKII\ and \MKIV\ use a completely
22%D different approach, this module only implements a few generic mechanisms.
23
24\installcorenamespace{color}
25\installcorenamespace{colorattribute}
26\installcorenamespace{transparencyattribute}
27\installcorenamespace{colorsetter}
28\installcorenamespace{transparencysetter}
29\installcorenamespace{colorpaletspecification}
30\installcorenamespace{colorpalet}
31\installcorenamespace{colorstack}
32\installcorenamespace{colorconversions}
33\installcorenamespace{colornumber}
34
35\registerctxluafile{colo-ini}{}
36\registerctxluafile{colo-icc}{}
37
38\unprotect
39
40%D In \MKIV\ we have independent color, colorspace and transparency but I'm still
41%D not sure if I keep it that way as it's probably more efficient to combine them
42%D (less attributes and finalizing). If it becomes a bottleneck we can set up a more
43%D complex system with one shared attribute for colorspace, color and transparency.
44%D
45%D When typesetting for paper, we prefer using the \CMYK\ color space, but for
46%D on||screen viewing we prefer \RGB\ (the previous implementation supported only
47%D this scheme). Independant of such specifications, we support some automatic
48%D conversions:
49%D
50%D \startitemize[packed]
51%D \item  convert all colors to \RGB
52%D \item  convert all colors to \CMYK
53%D \item  convert all colors to gray scales
54%D \stopitemize
55%D
56%D These options are communicated by means of:
57
58\newconditional\c_colo_rgb_supported
59\newconditional\c_colo_cmyk_supported
60\newconditional\c_colo_spot_supported   % backend driven
61\newconditional\c_colo_convert_gray     \settrue\c_colo_convert_gray
62\newconditional\c_colo_enabled
63\newconditional\c_colo_expanded
64
65\let\m_colo_weight_gray\v!yes
66
67\let\currentcolormodel \empty
68\let\currentcolorname  \empty
69\let\currentcolorpalet \empty
70\let\currentcolorprefix\empty % \currentcolorpalet:
71
72%D \macros
73%D   {definecolor,defineglobalcolor,definenamedcolor,definespotcolor,definemultitonecolor,
74%D    definetransparency}
75%D
76%D \starttyping
77%D \definecolor [blue]   [c=1,m=.38,y=0,k=.64] % pantone pms 2965 uncoated m
78%D \definecolor [yellow] [c=0,m=.28,y=1,k=.06] % pantone pms  124 uncoated m
79%D
80%D \definespotcolor [blue-100]   [blue]   [p=1]
81%D \definespotcolor [yellow-100] [yellow] [p=1]
82%D
83%D \definemultitonecolor [pdftoolscolor] [blue=.12,yellow=.28] [c=.1,m=.1,y=.3,k=.1]
84%D
85%D \defineprocesscolor[myred][r=.5]
86%D \defineprocesscolor[myredish][red][a=1,t=.5]
87%D
88%D \blackrule[color=myred,width=\hsize,height=1cm] \par
89%D \blackrule[color=myredish,width=\hsize,height=1cm]
90%D
91%D \useexternalfigure[demofig][mill.png][object=no]
92%D
93%D \startcombination[4*1]
94%D   {\externalfigure[demofig]}                      {no color}
95%D   {\externalfigure[demofig][color=pdftoolscolor]} {indexed duotone}
96%D   {\externalfigure[demofig][color=blue-100]}      {spot color}
97%D   {\externalfigure[demofig][color=yellow-100]}    {spot color}
98%D \stopcombination
99%D \stoptyping
100
101\unexpanded\def\definecolor             {\dodoubleargument\colo_basics_define}
102\unexpanded\def\defineglobalcolor       {\dodoubleargument\colo_basics_define_global}
103\unexpanded\def\defineprocesscolor      {\dotripleargument\colo_basics_define_process}
104\unexpanded\def\definenamedcolor        {\dodoubleargument\colo_basics_define_named}
105\unexpanded\def\definespotcolor         {\dotripleargument\colo_basics_define_spot}
106\unexpanded\def\definemultitonecolor    {\doquadrupleempty\colo_basics_define_multitone}
107\unexpanded\def\definetransparency      {\dodoubleargument\colo_basics_define_transpancy}
108\unexpanded\def\defineglobaltransparency{\dodoubleargument\colo_basics_define_transpancy_global}
109
110\unexpanded\def\loadfoundcolorsetfile#1#2% name foundname / not a user command
111  {\startreadingfile
112   \startcolorset[#1]%
113   \input{#2}%
114   \stopcolorset
115   \showmessage\m!colors4{#1}%
116   \stopreadingfile}
117
118%D \macros
119%D   {startcolor,stopcolor,color,graycolor}
120%D
121%D The local and global commands are here just for compatibility with \MKII.
122%D
123%D \showsetup{startcolor}
124%D
125%D The simple color commands are:
126%D
127%D \showsetup{color}
128%D \showsetup{graycolor}
129
130%D We expect sane behaviour in \MKIV\ so we don't used grouped command any
131%D longer.
132
133% \testfeatureonce{100000}{\color[red]{}} % 1.046 => 0.541
134
135\let\g_color\empty
136\let\g_style\empty
137
138\unexpanded\def\switchtocolor[#1]{\begincsname#1\endcsname}
139
140% transparency
141
142\unexpanded\def\transparent[#1]%
143  {\bgroup
144   \edef\currenttransparencyname{#1}%
145   % the \relax catches a non existent csname
146   \ifx\currenttransparencyname\v!reset
147     \c_attr_transparency\attributeunsetvalue
148   \else
149     \begincsname\??transparencysetter\currenttransparencyname\endcsname\relax
150   \fi
151   \let\nexttoken}
152
153\unexpanded\def\starttransparent[#1]%$
154  {\begingroup
155   \edef\currenttransparencyname{#1}%
156   \ifx\currenttransparencyname\v!reset
157     \c_attr_transparency\attributeunsetvalue
158   \else
159     \begincsname\??transparencysetter\currenttransparencyname\endcsname\relax
160   \fi}
161
162\unexpanded\def\stoptransparent
163  {\endgroup}
164
165% color
166
167\unexpanded\def\coloronly[#1]%
168  {\bgroup
169   \edef\currentcolorname{#1}%
170   \ifx\currentcolorprefix\empty
171     \colo_helpers_activate_nop_only
172   \else
173     \colo_helpers_activate_yes_only
174   \fi
175   \let\nexttoken}
176
177\unexpanded\def\startcoloronly[#1]%$
178  {\begingroup
179   \edef\currentcolorname{#1}%
180   \ifx\currentcolorprefix\empty
181     \colo_helpers_activate_nop_only
182   \else
183     \colo_helpers_activate_yes_only
184   \fi}
185
186\unexpanded\def\stopcoloronly
187  {\endgroup}
188
189% color + transparency
190
191\unexpanded\def\color[#1]%
192  {\bgroup
193   \edef\currentcolorname{#1}%
194   \ifx\currentcolorprefix\empty
195     \colo_helpers_activate_nop
196   \else
197     \colo_helpers_activate_yes
198   \fi
199   \let\nexttoken}
200
201\unexpanded\def\graycolor[#1]%
202  {\bgroup
203   \colo_helpers_set_model\s!gray\colo_helpers_activate{#1}%
204   \let\nexttoken}
205
206\unexpanded\def\startcolor[#1]%$
207  {\begingroup
208   \edef\currentcolorname{#1}%
209   \ifx\currentcolorprefix\empty
210     \colo_helpers_activate_nop
211   \else
212     \colo_helpers_activate_yes
213   \fi}
214
215\unexpanded\def\stopcolor
216  {\endgroup}
217
218\unexpanded\def\colored[#1]%
219  {\bgroup
220   \colo_basics_defined_and_activated{#1}%
221   \let\nexttoken}
222
223\unexpanded\def\fastcolored[#1]#2%
224  {\begingroup % is this command still needed?
225   \colo_basics_defined_and_activated{#1}%
226   #2%
227   \endgroup}
228
229\unexpanded\def\directcolored[#1]%
230  {\colo_basics_defined_and_activated{#1}}
231
232\unexpanded\def\fastcolor[#1]#2%
233  {\begingroup % is this command still needed?
234   \edef\currentcolorname{#1}%
235   \ifx\currentcolorprefix\empty
236     \colo_helpers_activate_nop
237   \else
238     \colo_helpers_activate_yes
239   \fi
240   #2%
241   \endgroup}
242
243\unexpanded\def\directcolor[#1]%
244  {\edef\currentcolorname{#1}%
245   \ifx\currentcolorprefix\empty
246     \colo_helpers_activate_nop
247   \else
248     \colo_helpers_activate_yes
249   \fi}
250
251%D The following command is obsolete:
252
253\unexpanded\def\startcolorpage   {\startcolor[\ifx\maintextcolor\empty\defaulttextcolor\else\maintextcolor\fi]}
254\unexpanded\def\stopcolorpage    {\stopcolor}
255
256\unexpanded\def\getcolorattributevalue#1#2% obsolete, use \thecolorattribute instead ...
257  {\begingroup
258   \colo_helpers_activate{#1}%
259   \normalexpanded{\endgroup\edef\noexpand#2%
260     {\ifnum\c_attr_color=\attributeunsetvalue\else\number\c_attr_color\fi}}}
261
262\let\grey\graycolor % these macros are only used in tracing
263
264%D \macros
265%D   {startcurrentcolor,stopcurrentcolor}
266
267\unexpanded\def\startcurrentcolor{\startcolor[\outercolorname]}
268\unexpanded\def\stopcurrentcolor {\stopcolor}
269
270%D \macros
271%D   {setupcolor}
272%D
273%D Color definitions can be grouped in files with the name:
274%D
275%D \starttyping
276%D colo-imp-tag.tex
277%D \stoptyping
278%D
279%D Loading such a file is done by:
280%D
281%D \showsetup{usecolors}
282%D
283%D Some default colors are specified in \type {colo-imp-rgb}, which is loaded into
284%D the format by default.
285%D
286%D Some demo palets and groups are defined in \type {colo-imp-dem} which can be
287%D loaded with:
288%D
289%D \starttyping
290%D \usecolors[dem]
291%D \stoptyping
292
293\unexpanded\def\startcolorset[#1]{\clf_startcolorset{#1}}
294\unexpanded\def\stopcolorset     {\clf_stopcolorset}
295\unexpanded\def\usecolors    [#1]{\clf_usecolors{#1}}
296
297\let\setupcolor\usecolors
298
299\installsetuponlycommandhandler \??color {colors}
300
301\let\colo_helpers_show_message\gobblethreearguments
302
303% \newtoks\everysetupcolors
304
305\let\v_colo_freeze_state\s!false
306
307\setvalue{\??colorconversions\v!yes}%
308  {\settrue \c_colo_convert_gray}
309
310\setvalue{\??colorconversions\v!always}%
311  {\settrue \c_colo_convert_gray
312   \setfalse\c_colo_rgb_supported
313   \setfalse\c_colo_cmyk_supported}
314
315\appendtoks
316   %
317   \doifelse{\directcolorsparameter\c!spot     }\v!yes  \settrue \setfalse\c_colo_spot_supported
318   \doifelse{\directcolorsparameter\c!expansion}\v!yes  \settrue \setfalse\c_colo_expanded
319   \doifelse{\directcolorsparameter\c!rgb      }\v!yes  \settrue \setfalse\c_colo_rgb_supported
320   \doifelse{\directcolorsparameter\c!cmyk     }\v!yes  \settrue \setfalse\c_colo_cmyk_supported
321   \doifelse{\directcolorsparameter\c!state    }\v!start\settrue \setfalse\c_colo_enabled
322   %
323   \edef\m_colo_weight_gray{\directcolorsparameter\c!factor}%
324   %
325   \ifconditional\c_colo_expanded
326     \let\v_colo_freeze_state\s!true
327   \else
328     \let\v_colo_freeze_state\s!false
329   \fi
330   %
331   \setfalse\c_colo_convert_gray
332   \begincsname\??colorconversions\directcolorsparameter\c!conversion\endcsname
333   % too often:
334   \ifconditional\c_colo_rgb_supported \colo_helpers_show_message\m!colors{10}\v!rgb \fi
335   \ifconditional\c_colo_cmyk_supported\colo_helpers_show_message\m!colors{10}\v!cmyk\fi
336   \colo_helpers_set_current_model
337   \ifproductionrun
338     \edef\p_pagecolormodel{\directcolorsparameter\c!pagecolormodel}%
339     \clf_setpagecolormodel{\ifx\p_pagecolormodel\v!auto\currentcolormodel\else\p_pagecolormodel\fi}%
340   \fi
341\to \everysetupcolors
342
343\appendtoks
344    \setupcolors[\c!state=\v!start]%
345    \clf_enablecolor           % this can as well happen when
346    \clf_enabletransparency    % the handler is defined in lua
347    \let\colo_helpers_show_message\showmessage
348\to \everyjob
349
350%D We provide stacking independent of grouping.
351
352\newcount\c_colo_nesting
353
354\unexpanded\def\pushcolor[#1]%
355  {\global\advance\c_colo_nesting\plusone
356   \expandafter\edef\csname\??colorstack\number\c_colo_nesting\endcsname
357     {\c_attr_colormodel  \the\c_attr_colormodel
358      \c_attr_color       \the\c_attr_color
359      \c_attr_transparency\the\c_attr_transparency
360      \relax}% stack
361   \colo_helpers_activate{#1}}
362
363\unexpanded\def\popcolor
364  {\csname\??colorstack\number\c_colo_nesting\endcsname
365   \global\advance\c_colo_nesting\minusone}
366
367% a simple one: assumes grouping
368
369\newcount\c_colo_saved_attribute_color
370\newcount\c_colo_saved_attribute_transparency
371
372\unexpanded\def\savecolor
373  {\c_colo_saved_attribute_color       \c_attr_color
374   \c_colo_saved_attribute_transparency\c_attr_transparency}
375
376\unexpanded\def\restorecolor
377  {\c_attr_color       \c_colo_saved_attribute_color
378   \c_attr_transparency\c_colo_saved_attribute_transparency}
379
380%D In this documentation we will not go into too much details on palets. Curious
381%D users can find more information on this topic in \from[use of color].
382%D
383%D At the moment we implemented color in \CONTEXT\ color printing was not yet on the
384%D desktop. In spite of this lack our graphics designer made colorfull
385%D illustrations. When printed on a black and white printer, distinctive colors can
386%D come out equally gray. We therefore decided to use only colors that were
387%D distinctive in colors as well as in black and white print.
388%D
389%D Although none of the graphic packages we used supported logical colors and global
390%D color redefition, we build this support into \CONTEXT. This enabled us to
391%D experiment and also prepared us for the future.
392
393%D \macros
394%D   {definepalet}
395%D
396%D Colors are grouped in palets. The colors in such a palet can have colorful names,
397%D but best is to use names that specify their use, like {\em important} or {\em
398%D danger}. As a sort of example \CONTEXT\ has some palets predefined,
399%D like:\footnote{At the time I wrote the palet support, I was reading 'A hort
400%D history of time' of S.~Hawkins, so that's why we stuck to quarks.}
401%D
402%D \starttyping
403%D \definepalet
404%D   [alfa]
405%D   [     top=rood:7,
406%D      bottom=groen:6,
407%D          up=blauw:5,
408%D        down=cyaan:4,
409%D     strange=magenta:3,
410%D       charm=geel:2]
411%D \stoptyping
412%D
413%D It's formal definition is:
414%D
415%D \showsetup{definepalet}
416%D
417%D Visualized, such a palet looks like:
418%D
419%D \startbuffer[palet]
420%D \showpalet [alfa] [horizontal,name,number,value]
421%D \stopbuffer
422%D
423%D \startlinecorrection
424%D \getbuffer[palet]
425%D \stoplinecorrection
426%D
427%D This bar shows both the color and gray alternatives of the palet components (not
428%D visible in black and white print).
429%D
430%D When needed, one can copy a palet by saying:
431%D
432%D \starttyping
433%D \definepalet [TEXcolorpretty] [colorpretty]
434%D \stoptyping
435%D
436%D This saves us some typing in for instance the modules that deal with pretty
437%D verbatim typesetting.
438
439\installcorenamespace{paletlist}
440\installcorenamespace{paletsize}
441
442\let\m_colo_palet\relax
443\let\c_colo_palet\relax
444
445\def\colo_palet_allocate#1%
446  {\expandafter\let     \csname\??paletlist#1\endcsname\empty
447   \expandafter\newcount\csname\??paletsize#1\endcsname}
448
449\def\colo_palet_prepare#1%
450  {\edef\colo_palet_name{#1}%
451   \ifcsname\??paletlist\colo_palet_name\endcsname
452     \csname\??paletsize\colo_palet_name\endcsname\zerocount
453   \else
454     \colo_palet_allocate\colo_palet_name
455   \fi
456   \edef\m_colo_palet{\begincsname\??paletlist\colo_palet_name\endcsname}%
457   \expandafter\let\expandafter\c_colo_palet\csname\??paletsize\colo_palet_name\endcsname}
458
459\def\colo_palet_extend#1%
460  {\addtocommalist{#1}\m_colo_palet
461   \expandafter\let\csname\??paletlist\colo_palet_name\endcsname\m_colo_palet
462   \advance\c_colo_palet\plusone}
463
464\unexpanded\def\doifelsecolorpalet#1%
465  {\ifcsname\??paletlist#1\endcsname
466     \expandafter\firstoftwoarguments
467   \else
468     \expandafter\secondoftwoarguments
469   \fi}
470
471\let\paletlist\empty
472\let\paletsize\!!zerocount
473
474\unexpanded\def\getpaletlist[#1]%
475  {\edef\paletlist{\begincsname\??paletlist#1\endcsname}}
476
477\unexpanded\def\getpaletsize[#1]%
478  {\ifcsname\??paletsize#1\endcsname
479     \edef\paletsize{\the\lastnamedcs}%
480   \else
481     \let\paletsize\!!zerocount
482   \fi}
483
484\unexpanded\def\definepalet
485  {\dotripleempty\colo_palets_define}
486
487\def\colo_palets_define
488  {\ifthirdargument
489     \expandafter\colo_palets_define_b
490   \else
491     \expandafter\colo_palets_define_a
492   \fi}
493
494\unexpanded\def\colo_palets_define_a[#1][#2][#3]%
495  {\colo_palet_prepare{#1}%
496   \ifcondition\validassignment{#2}%
497     \setevalue{\??colorpaletspecification#1}{#2}%
498     \processcommalist[#2]{\colo_palets_define_one{#1}}%
499   \else
500     \ifcsname\??colorpaletspecification#2\endcsname
501       \normalexpanded{\colo_palets_define[#1][\lastnamedcs]}%
502     \fi
503   \fi}
504
505\unexpanded\def\colo_palets_define_b[#1][#2][#3]%
506  {\colo_palet_prepare{#1}%
507   \setevalue{\??colorpaletspecification#1}{#2}%
508   \colo_palet_extend{#2}%
509   \colo_palets_define_assign{#1}{#2}{#3}}
510
511\def\colo_palets_define_one#1#2% get rid of { }
512  {\ifcondition\validassignment{#2}% catch empty entries
513     \colo_palets_define_two{#1}[#2]%
514   \else
515     \colo_palets_define_three{#1}{#2}%
516   \fi}
517
518\def\colo_palets_define_two#1[#2=#3]%
519  {\colo_palet_extend{#2}%
520   \colo_palets_define_set{#1}{#2}{#3}}%
521
522\def\colo_palets_define_three#1#2%
523  {\ifcsname\??colorpaletspecification#2\endcsname
524     \processcommacommand[\lastnamedcs]{\colo_palets_define_one{#1}}%
525   \fi}
526
527%D Instead of refering to colors, one can also directly specify a color:
528%D
529%D \starttyping
530%D \definepalet[test][xx=green]
531%D \definepalet[test][xx={y=.4}]
532%D \stoptyping
533
534%D \macros
535%D   {setuppalet}
536%D
537%D Colors are taken from the current palet, if defined. Setting the current palet is
538%D done by:
539%D
540%D \showsetup{setuppalet}
541
542\newtoks\everysetuppalet
543
544\unexpanded\def\setuppalet
545  {\dosingleempty\colo_palets_setup}
546
547% \newtoks\t_colo_prefix % used in mp interface
548
549\def\colo_palets_setup[#1]%
550  {\edef\currentcolorpalet{#1}%
551   \ifx\currentcolorpalet\empty
552     % seems to be a reset
553     \let\currentcolorprefix\empty
554    %\t_colo_prefix\emptytoks
555   \else\ifcsname\??paletlist\currentcolorpalet\endcsname
556     \edef\currentcolorprefix{#1:}%
557    %\t_colo_prefix\expandafter{\currentcolorprefix}%
558   \else
559     \colo_helpers_show_message\m!colors7\currentcolorpalet
560     \let\currentcolorpalet\empty
561     \let\currentcolorprefix\empty
562    %\t_colo_prefix\emptytoks
563   \fi\fi
564   \the\everysetuppalet
565   \colo_helpers_initialize_maintextcolor}
566
567%D \macros
568%D   {showpalet}
569%D
570%D The previous visualization was typeset with:
571%D
572%D \typebuffer[palet]
573%D
574%D This commands is defined as:
575%D
576%D \showsetup{showpalet}
577
578\fetchruntimecommand \showpalet \f!colo_run
579
580%D \macros
581%D   {showcolorcomponents}
582%D
583%D \starttyping
584%D \showcolorcomponents[color-1,color-2]
585%D \stoptyping
586
587\fetchruntimecommand \showcolorcomponents \f!colo_run
588
589%D \macros
590%D   {comparepalet}
591%D
592%D There are some more testing macros available:
593%D
594%D \startbuffer
595%D \comparepalet [alfa]
596%D \stopbuffer
597%D
598%D \typebuffer
599%D
600%D shows the palet colors against a background:
601%D
602%D \startlinecorrection
603%D \getbuffer
604%D \stoplinecorrection
605%D
606%D The formal definition is:
607%D
608%D \showsetup{comparepalet}
609
610\fetchruntimecommand \comparepalet \f!colo_run
611
612%D \macros
613%D   {showcolor}
614%D
615%D But let's not forget that we also have the more traditional non||related colors.
616%D These show up after:
617%D
618%D \starttyping
619%D \showcolor [name]
620%D \stoptyping
621%D
622%D Where \type{name} for instance can be \type{rgb}.
623%D
624%D \showsetup{showcolor}
625
626\fetchruntimecommand \showcolor \f!colo_run
627
628%D It would make sense to put the following code in \type {colo-mps}, but it it
629%D rather low level.
630
631%D \macros
632%D   {negatecolorcomponent,negatedcolorcomponent}
633%D
634%D These speak for themselves. See \type {colo-ext} for usage.
635
636% \def\negatedcolorcomponent#1%
637%   {\ifdim\dimexpr\onepoint-#1\onepoint\relax<\zeropoint
638%      \!!zerocount
639%    \else
640%      \expandafter\withoutpt\the\dimexpr\onepoint-#1\onepoint\relax
641%    \fi}
642%
643% \unexpanded\def\negatecolorcomponent#1% #1 = \macro
644%   {\scratchdimen\onepoint\advance\scratchdimen-#1\onepoint
645%    \ifdim\scratchdimen<\zeropoint\scratchdimen\zeropoint\fi
646%    \edef#1{\withoutpt\the\scratchdimen}}
647%
648% \unexpanded\def\negatecolorcomponent#1% #1 = \macro
649%   {\edef#1{\negatedcolorcomponent{#1}}}
650
651\unexpanded\def\negatecolorcomponent#1% #1 = \macro
652  {\edef#1{\clf_negatedcolorcomponent{#1}}}
653
654\def\negatedcolorcomponent#1%
655  {\clf_negatedcolorcomponent{#1}}
656
657%D \macros
658%D   {MPcolor}
659%D
660%D A very special macro is \type{\MPcolor}. This one can be used to pass a \CONTEXT\
661%D color to \METAPOST.
662%D
663%D \starttyping
664%D \MPcolor{my own red}
665%D \stoptyping
666%D
667%D This macro returns \METAPOST\ code that represents the
668%D color.
669%D
670%D For the moment we keep the next downward compatibility switch, i.e.\ expanded
671%D colors. However, predefined colors and palets are no longer expanded (which is
672%D what I wanted in the first place).
673%D
674%D In \MKIV\ we don't support color separation as we might now assume that printing
675%D houses have the right programs to do it themselves. If it's ever needed in \MKIV\
676%D It is relatively easy to support it in the backend code.
677
678% todo: palets in definecolor
679% todo: {\red xx} vs \red{xx}
680
681% \def\mptexcolor#1{"\dogetattributeid\s!color \somecolorattribute{#1} A"}
682%
683% \startMPpage
684%     fill fullcircle scaled 10cm  ;
685%     fill fullcircle scaled 5cm withprescript \mptexcolor{red} withpostscript \mptexcolor{black} ;
686%     fill fullcircle scaled 3cm  ;
687%     draw btex test etex withprescript \mptexcolor{blue}  ;
688% \stopMPpage
689
690\unexpanded\def\setcolormodel[#1]% % beware, \setupcolors will overload this, so this one is
691  {\colo_helpers_set_model{#1}}  % only for local usage
692
693\def\colo_helpers_set_model#1% direct
694  {\edef\currentcolormodel{#1}%
695   \clf_setcolormodel{\currentcolormodel}{\m_colo_weight_gray}} % sets attribute at lua end
696
697\colo_helpers_set_model\s!all
698
699\def\colo_helpers_set_current_model
700  {\ifconditional\c_colo_enabled
701     \ifconditional\c_colo_rgb_supported
702       \ifconditional\c_colo_cmyk_supported
703         \colo_helpers_set_model\s!all
704       \else
705         \colo_helpers_set_model\s!rgb
706       \fi
707     \else
708       \ifconditional\c_colo_cmyk_supported
709         \colo_helpers_set_model\s!cmyk
710       \else
711         \ifconditional\c_colo_convert_gray
712           \colo_helpers_set_model\s!gray
713         \else
714           \colo_helpers_set_model\s!none
715         \fi
716       \fi
717     \fi
718   \else
719     \ifconditional\c_colo_convert_gray
720       \colo_helpers_set_model\s!gray
721     \else
722       \colo_helpers_set_model\s!none
723     \fi
724   \fi}
725
726%D Currently in mkiv transparency is implemented independent of color. This costs a
727%D bit more processing time but gives the possibility to apply transparency
728%D independently in the future. Is this useful? If not we may as well combine them
729%D again in the future. By coupling we are downward compatible. When we decouple we
730%D need to do more tricky housekeeping (e.g. persist color independent
731%D transparencies when color bound ones are nil.
732
733% Since we couple definitions, we could stick to one test. Todo. Same for mpcolor.
734
735\def\v_colo_dummy_name{c_o_l_o_r}
736
737\letvalue{\??colorattribute       \v_colo_dummy_name}\empty
738\letvalue{\??transparencyattribute\v_colo_dummy_name}\empty
739\letvalue{\??colorsetter          \v_colo_dummy_name}\empty
740\letvalue{\??transparencysetter   \v_colo_dummy_name}\empty
741
742\letvalue{\??colorsetter       -}\empty % used?
743\letvalue{\??transparencysetter-}\empty % used?
744
745% new: expandable (see tbl)
746
747\def\colo_helpers_fast_activate
748  {\ifx\currentcolorprefix\empty
749     \expandafter\colo_helpers_fast_activate_nop
750   \else
751     \expandafter\colo_helpers_fast_activate_yes
752   \fi}
753
754\def\colo_helpers_fast_activate_yes#1%
755  {\ifcsname\??colorsetter\currentcolorprefix#1\endcsname
756     \lastnamedcs
757     \begincsname\??transparencysetter\currentcolorprefix#1\endcsname
758   \else\ifcsname\??colorsetter#1\endcsname
759     \lastnamedcs
760     \begincsname\??transparencysetter#1\endcsname
761   \fi\fi}
762
763\def\colo_helpers_fast_activate_nop#1%
764  {\ifcsname\??colorsetter#1\endcsname
765     \lastnamedcs
766     \begincsname\??transparencysetter#1\endcsname
767   \fi}
768
769\def\colo_helpers_activate_dummy
770  {\begincsname\??colorsetter       \v_colo_dummy_name\endcsname
771   \begincsname\??transparencysetter\v_colo_dummy_name\endcsname}
772
773\let\dofastcoloractivation\colo_helpers_fast_activate
774
775% so far
776
777\def\colo_helpers_activate#1% two-step is not that much faster but less tracing
778  {\edef\currentcolorname{#1}%
779   \ifx\currentcolorprefix\empty
780     \expandafter\colo_helpers_activate_nop
781   \else
782     \expandafter\colo_helpers_activate_yes
783   \fi}
784
785\def\colo_helpers_activate_yes
786  {\ifcsname\??colorsetter\currentcolorprefix\currentcolorname\endcsname
787     \lastnamedcs
788     \begincsname\??transparencysetter\currentcolorprefix\currentcolorname\endcsname
789   \else\ifcsname\??colorsetter\currentcolorname\endcsname
790     \lastnamedcs
791     \begincsname\??transparencysetter\currentcolorname\endcsname
792   \fi\fi}
793
794\def\colo_helpers_activate_nop
795  {\ifcsname\??colorsetter\currentcolorname\endcsname
796     \lastnamedcs
797     \begincsname\??transparencysetter\currentcolorname\endcsname
798   \fi}
799
800\def\colo_helpers_activate_yes_only
801  {\ifcsname\??colorsetter\currentcolorprefix\currentcolorname\endcsname
802     \lastnamedcs
803   \else\ifcsname\??colorsetter\currentcolorname\endcsname
804     \lastnamedcs
805   \fi\fi}
806
807\def\colo_helpers_activate_nop_only
808  {\ifcsname\??colorsetter\currentcolorname\endcsname
809     \lastnamedcs
810   \fi}
811
812\let\dousecolorparameter\colo_helpers_activate
813
814\unexpanded\def\dousecolorhashparameter#1#2%
815  {\ifcsname#1#2\endcsname
816     \expandafter\dousecolorparameter\csname#1#2\endcsname
817   \fi}
818
819\unexpanded\def\dousecurrentcolorparameter
820  {\let\currentcolorname\currentcolorparameter % maybe only when success
821   \ifcsname\??colorsetter\currentcolorprefix\currentcolorparameter\endcsname
822     \lastnamedcs
823     \begincsname\??transparencysetter\currentcolorprefix\currentcolorparameter\endcsname
824   \else\ifcsname\??colorsetter\currentcolorparameter\endcsname
825     \lastnamedcs
826     \begincsname\??transparencysetter\currentcolorparameter\endcsname
827   \fi\fi}
828
829\let\dosetcolorattribute\dousecolorhashparameter % for a while
830
831\unexpanded\def\deactivatecolor % sort of public but a bad name
832  {\let\currentcolorname\s!black
833   \c_attr_color       \attributeunsetvalue
834   \c_attr_transparency\attributeunsetvalue}
835
836% todo: check if color is overloading a non-color command
837
838% \let\colo_basics_synchronize\gobbleoneargument  % used in mp interface
839% \let\colo_basics_inherit    \gobbletwoarguments % used in mp interface
840
841\def\colo_basics_allocate#1%
842  {\expandafter\newcount\csname\??colornumber#1\endcsname
843   \clf_synccolorcount{#1}\c_syst_last_allocated_count}
844
845\def\colo_basics_synchronize#1%
846  {\ifcsname\??colornumber#1\endcsname\else
847     \colo_basics_allocate{#1}%
848   \fi
849   \clf_synccolor{#1}%
850  %\csname\??colornumber#1\endcsname\csname\??colorattribute#1\endcsname
851   \lastnamedcs\csname\??colorattribute#1\endcsname}
852
853\let\colo_basics_inherit\clf_synccolorclone
854
855\newcount\c_colo_protection
856
857\unexpanded\def\startprotectedcolors
858  {\advance\c_colo_protection\plusone}
859
860\unexpanded\def\stopprotectedcolors
861  {\advance\c_colo_protection\minusone}
862
863\def\colo_basics_define[#1][#2]%
864  {\edef\m_colo_old{#1}%
865   \edef\m_colo_new{#2}%
866   \ifx\m_colo_old\m_colo_new
867     % maybe a warning
868   \else
869     \clf_defineprocesscolorlocal{#1}{#2}\v_colo_freeze_state\relax
870     \colo_basics_synchronize{#1}%
871     \ifcase\c_colo_protection
872       \unexpanded\setvalue{#1}{\colo_helpers_activate{#1}}%
873     \fi
874   \fi}
875
876\def\colo_basics_define_global[#1][#2]%
877  {\edef\m_colo_old{#1}%
878   \edef\m_colo_new{#2}%
879   \ifx\m_colo_old\m_colo_new
880     % maybe a warning
881   \else
882     \clf_defineprocesscolorglobal{#1}{#2}\v_colo_freeze_state\relax
883     \colo_basics_synchronize{#1}%
884     \ifcase\c_colo_protection
885       \unexpanded\setgvalue{#1}{\colo_helpers_activate{#1}}%
886     \fi
887   \fi}
888
889\let\colo_basics_define_named\colo_basics_define
890
891\def\dodefinefastcolor[#1][#2]% still not fast but ok (might change)
892  {\clf_defineprocesscolorlocal{#1}{#2}\v_colo_freeze_state\relax
893   \colo_basics_synchronize{#1}%
894   \ifcase\c_colo_protection
895     \unexpanded\setvalue{#1}{\colo_helpers_activate{#1}}%
896   \fi}
897
898\def\colo_basics_defined_and_activated#1%
899  {\clf_defineprocesscolordummy{#1}% we could pass dummy here too
900   \colo_basics_synchronize{\v_colo_dummy_name}%
901   \colo_helpers_activate_dummy}
902
903\def\colo_basics_define_process
904  {\ifthirdargument
905     \expandafter\colo_basics_define_process_yes
906   \else
907     \expandafter\colo_basics_define_process_nop
908   \fi}
909
910\def\colo_basics_define_process_yes[#1][#2][#3]%
911  {\clf_defineprocesscolorlocal{#1}{\processcolorcomponents{#2},#3}\v_colo_freeze_state\relax
912   \colo_basics_synchronize{#1}%
913   \ifcase\c_colo_protection
914     \unexpanded\setvalue{#1}{\colo_helpers_activate{#1}}%
915   \fi}
916
917\def\colo_basics_define_process_nop[#1][#2][#3]%
918  {\clf_defineprocesscolorlocal{#1}{#2}\v_colo_freeze_state\relax
919   \colo_basics_synchronize{#1}%
920   \ifcase\c_colo_protection
921     \unexpanded\setvalue{#1}{\colo_helpers_activate{#1}}%
922   \fi}
923
924%D Spotcolors used setxvalue but that messes up currentcolor and probably no global
925%D is needed either but they are global at the lua end (true argument) so we keep
926%D that if only because spot colors often are a document wide property
927
928\def\colo_basics_define_spot[#1][#2][#3]%
929  {\clf_definespotcolorglobal{#1}{#2}{#3}%
930   \colo_basics_synchronize{#1}%
931   \ifcase\c_colo_protection
932     \unexpanded\setgvalue{#1}{\colo_helpers_activate{#1}}%
933   \fi}
934
935\def\colo_basics_define_multitone[#1][#2][#3][#4]%
936  {\clf_definemultitonecolorglobal{#1}{#2}{#3}{#4}%
937   \colo_basics_synchronize{#1}%
938   \ifcase\c_colo_protection
939     \unexpanded\setgvalue{#1}{\colo_helpers_activate{#1}}%
940   \fi}
941
942%D Transparencies (only):
943
944\def\colo_basics_define_transpancy[#1][#2]%
945  {\clf_definetransparency{#1}{#2}}
946
947\def\colo_basics_define_transpancy_global[#1][#2]%
948  {\clf_definetransparencyglobal{#1}{#2}}
949
950% A goodie that replaces the startMPcolor hackery
951
952% \definecolor[red-t]  [r=1,t=0.5,a=1]
953% \definecolor[green-t][g=1,t=0.5,a=1]
954%
955% \defineintermediatecolor[mycolora][0.5,red,green]
956% \defineintermediatecolor[mycolorb][0.5,red-t,green-t]
957%
958% \definecolor[mycolorc][.5(blue,red)]
959% \definecolor[mycolord][.5(blue)]
960% \definecolor[mycolord][-.5(blue,red)] % complement
961% \definecolor[mycolord][-(blue)]       % complement
962%
963% \enabledirectives[colors.pgf]
964% \definecolor[mycolorx][magenta!50!yellow]
965%
966% \starttext
967%     test {\mycolora OEPS} test
968%     test {\mycolorb OEPS} test
969%     test {\mycolorc OEPS} test
970%     test {\mycolord OEPS} test
971%     test {\mycolorx OEPS} test
972% \stoptext
973%
974% Beware: if we say:
975%
976% \definecolor[one][two]
977%
978% Only color one is actually defined and two is not seen at the \LUA\ end. This
979% means that this doesn't work:
980%
981% \definecolor[ColorA][red]
982% \definecolor[ColorB][.5(ColorA)]
983% \definecolor[ColorC][.5(ColorB,white)]
984%
985% But this does work:
986%
987% \definecolor[ColorA][1.0(red)]
988% \definecolor[ColorB][0.5(ColorA)]
989% \definecolor[ColorC][0.5(ColorB,white)]
990%
991% because the fractional definition results in a new definition.
992
993\unexpanded\def\defineintermediatecolor
994  {\dotripleempty\colo_basics_define_intermediate}
995
996\def\colo_basics_define_intermediate[#1][#2][#3]% \dotripleempty adds {} inside []
997  {\colo_basics_define_intermediate_indeed[#1][#2][#3]}
998
999\def\colo_basics_define_intermediate_indeed[#1][#2,#3,#4][#5]%
1000  {\clf_defineintermediatecolor % not global
1001     {#1}%
1002     {#2}%
1003     \rawcolorattribute{#3} %
1004     \rawcolorattribute{#4} %
1005     \rawtransparencyattribute{#3} %
1006     \rawtransparencyattribute{#4} %
1007     {#5}%
1008     \v_colo_freeze_state
1009   \relax
1010   \colo_basics_synchronize{#1}%
1011   \unexpanded\setvalue{#1}{\colo_helpers_activate{#1}}}
1012
1013%D Here is a more efficient helper for pgf:
1014%D
1015%D \starttyping
1016%D \startluacode
1017%D     function commands.pgfxcolorspec(ca) -- {}{}{colorspace}{list}
1018%D         local cv = attributes.colors.values[ca]
1019%D         if cv then
1020%D             local model = cv[1]
1021%D             if model == 2 then
1022%D                 context("{}{}{gray}{%1.3f}",cv[2])
1023%D             elseif model == 3 then
1024%D                 context("{}{}{rgb}{%1.3f,%1.3f,%1.3f}",cv[3],cv[4],cv[5])
1025%D             elseif model == 4 then
1026%D                 context("{}{}{cmyk}{%1.3f,%1.3f,%1.3f,%1.3f}",cv[6],cv[7],cv[8],cv[9])
1027%D             else
1028%D                 context("{}{}{gray}{%1.3f}",cv[2])
1029%D             end
1030%D         else
1031%D             context("{}{}{gray}{0}")
1032%D         end
1033%D     end
1034%D \stopluacode
1035%D
1036%D \def\pgfutil@registercolor#1%
1037%D   {\setevalue{\string\color@#1}{\noexpand\xcolor@\ctxcommand{pgfxcolorspec(\thecolorattribute{#1})}}}
1038%D
1039%D \definecolor [darkblue] [r=0,g=0,b=0.5]
1040%D
1041%D \starttikzpicture
1042%D     \fill [blue] (0,0) circle(1);
1043%D     \fill [darkblue] (0,0) circle(1);
1044%D \stoptikzpicture
1045%D \stoptyping
1046%D
1047%D \stopmode
1048
1049\def\pgf@context@registercolor#1{\setevalue{\string\color@#1}{\noexpand\xcolor@{}{}\clf_pgfxcolorspec\zerocount\thecolorattribute{#1}}}
1050\def\pgf@context@registergray #1{\setevalue{\string\color@#1}{\noexpand\xcolor@{}{}\clf_pgfxcolorspec\plustwo  \thecolorattribute{#1}}}
1051\def\pgf@context@registerrgb  #1{\setevalue{\string\color@#1}{\noexpand\xcolor@{}{}\clf_pgfxcolorspec\plusthree\thecolorattribute{#1}}}
1052\def\pgf@context@registercmyk #1{\setevalue{\string\color@#1}{\noexpand\xcolor@{}{}\clf_pgfxcolorspec\plusfour \thecolorattribute{#1}}}
1053
1054%D \starttyping
1055%D \ifdefined\pgf@context@registercolor
1056%D     \let\pgfutil@registercolor\pgf@context@registercolor
1057%D \fi
1058%D \stoptyping
1059
1060%D \macros
1061%D   {doifcolorelse, doifcolor}
1062%D
1063%D Switching to a color is done by means of the following command. Later on we will
1064%D explain the use of palets. We define ourselves a color conditional first.
1065
1066\def\doifelsecolor#1%
1067  {\ifcsname\??colorattribute\currentcolorprefix#1\endcsname
1068     \expandafter\firstoftwoarguments
1069   \else\ifcsname\??colorattribute#1\endcsname
1070     \doubleexpandafter\firstoftwoarguments
1071   \else
1072     \doubleexpandafter\secondoftwoarguments
1073   \fi\fi}
1074
1075\let\doifcolorelse\doifelsecolor
1076
1077\def\doifcolor#1%
1078  {\ifcsname\??colorattribute\currentcolorprefix#1\endcsname
1079     \expandafter\firstofoneargument
1080   \else\ifcsname\??colorattribute#1\endcsname
1081     \doubleexpandafter\firstofoneargument
1082   \else
1083     \doubleexpandafter\gobbleoneargument
1084   \fi\fi}
1085
1086%D \macros
1087%D   {startregistercolor,stopregistercolor,permitcolormode}
1088%D
1089%D If you only want to register a color, the switch \type {\ifpermitcolormode} can
1090%D be used. That way the nested colors know where to go back to.
1091%D
1092%D We use these macros for implementing text colors (actually, the first application
1093%D was in foreground colors).
1094%D
1095%D \starttyping
1096%D \starttextcolor[red]
1097%D   \dorecurse{10}{\input tufte \color[green]{oeps} \par}
1098%D \stoptextcolor
1099%D \stoptyping
1100%D
1101%D This is more efficient than the alternative:
1102%D
1103%D \starttyping
1104%D \setupbackgrounds[text][foregroundcolor=red]
1105%D \startregistercolor[red]
1106%D   \dorecurse{10}{\input tufte \color[green]{oeps} \par}
1107%D \stopregistercolor
1108%D \stoptyping
1109
1110\let\maintextcolor   \empty
1111\def\defaulttextcolor{black}
1112
1113\unexpanded\def\inheritmaintextcolor
1114  {\ifx\maintextcolor\empty\else\colo_helpers_activate\maintextcolor\fi}
1115
1116\unexpanded\def\onlyinheritmaintextcolor
1117  {\ifx\maintextcolor\empty
1118     \deactivatecolor
1119   \else
1120     \colo_helpers_activate\maintextcolor
1121   \fi}
1122
1123\appendtoks
1124    \deactivatecolor % public?
1125    \inheritmaintextcolor
1126\to \everybeforeoutput
1127
1128\def\colo_helpers_switch_to_maintextcolor#1%
1129  {\let\maintextcolor\s!themaintextcolor
1130   \definecolor[\maintextcolor][#1]% can be fast one
1131   \colo_helpers_activate\maintextcolor
1132   \clf_registermaintextcolor\thecolorattribute\maintextcolor\relax}
1133
1134\unexpanded\def\starttextcolor[#1]%
1135  {\doifsomething{#1}
1136     {\colo_helpers_switch_to_maintextcolor{#1}}}
1137
1138\let\stoptextcolor\relax
1139
1140\let\p_colo_textcolor\empty
1141
1142\def\colo_helpers_initialize_maintextcolor
1143  {\edef\p_colo_textcolor{\directcolorsparameter\c!textcolor}%
1144   \ifx\p_colo_textcolor\empty
1145     \colo_helpers_switch_to_maintextcolor\defaulttextcolor
1146   \else
1147     \colo_helpers_switch_to_maintextcolor\p_colo_textcolor
1148   \fi}
1149
1150\appendtoks \colo_helpers_initialize_maintextcolor \to \everyjob
1151\appendtoks \colo_helpers_initialize_maintextcolor \to \everysetupcolors
1152
1153\letvalue{\??colorsetter       }\empty \letvalue{\??colorattribute       }\!!zerocount
1154\letvalue{\??transparencysetter}\empty \letvalue{\??transparencyattribute}\!!zerocount
1155
1156\def\colo_helpers_inherited_direct_cs#1{\ifcsname\??colorsetter          #1\endcsname\lastnamedcs\fi}
1157\def\colo_helpers_inherited_direct_ca#1{\ifcsname\??colorattribute       #1\endcsname\lastnamedcs\else\!!zerocount\fi}
1158\def\colo_helpers_inherited_direct_ts#1{\ifcsname\??transparencysetter   #1\endcsname\lastnamedcs\fi}
1159\def\colo_helpers_inherited_direct_ta#1{\ifcsname\??transparencyattribute#1\endcsname\lastnamedcs\else\!!zerocount\fi}
1160
1161% %def\colo_helpers_inherited_palet_cs#1#2{\csname\??colorsetter          \ifcsname\??colorsetter          \??colorpalet#1:#2\endcsname\??colorpalet#1:#2\fi\endcsname}
1162% %def\colo_helpers_inherited_palet_ca#1#2{\csname\??colorattribute       \ifcsname\??colorattribute       \??colorpalet#1:#2\endcsname\??colorpalet#1:#2\fi\endcsname}
1163% %def\colo_helpers_inherited_palet_ts#1#2{\csname\??transparencysetter   \ifcsname\??transparencysetter   \??colorpalet#1:#2\endcsname\??colorpalet#1:#2\fi\endcsname}
1164% %def\colo_helpers_inherited_palet_ta#1#2{\csname\??transparencyattribute\ifcsname\??transparencyattribute\??colorpalet#1:#2\endcsname\??colorpalet#1:#2\fi\endcsname}
1165%
1166% \def\colo_helpers_inherited_palet_cs#1#2{\ifcsname\??colorsetter          \??colorpalet#1:#2\endcsname\lastnamedcs\fi}
1167% \def\colo_helpers_inherited_palet_ca#1#2{\ifcsname\??colorattribute       \??colorpalet#1:#2\endcsname\lastnamedcs\else\!!zerocount\fi}
1168% \def\colo_helpers_inherited_palet_ts#1#2{\ifcsname\??transparencysetter   \??colorpalet#1:#2\endcsname\lastnamedcs}
1169% \def\colo_helpers_inherited_palet_ta#1#2{\ifcsname\??transparencyattribute\??colorpalet#1:#2\endcsname\lastnamedcs\else\!!zerocount\fi}
1170
1171\let\colo_helpers_set_value\setvalue
1172
1173\appendtoks
1174   \ifconditional\c_colo_expanded
1175     \let\colo_helpers_set_value\setevalue
1176   \else
1177     \let\colo_helpers_set_value\setvalue
1178   \fi
1179\to \everysetupcolors
1180
1181\def\colo_palets_define_set#1#2#3%
1182  {\ifcondition\validassignment{#3}% \definepalet[test][xx={y=.4}]
1183     \expandafter\colo_palets_define_assign
1184   \else\ifcsname\??colorsetter#3\endcsname
1185     % \definepalet[test][xx=green]
1186     \doubleexpandafter\colo_palets_define_inherit
1187   \else
1188     % not entered when making format
1189     \doubleexpandafter\colo_palets_define_undefine
1190   \fi\fi
1191   {#1}{#2}{#3}}
1192
1193\def\colo_palets_define_inherit#1#2#3%
1194  {\colo_basics_inherit{#1:#2}{#3}%
1195   \colo_helpers_set_value{\??colorsetter          #1:#2}{\colo_helpers_inherited_direct_cs{#3}}%
1196   \colo_helpers_set_value{\??colorattribute       #1:#2}{\colo_helpers_inherited_direct_ca{#3}}%
1197   \colo_helpers_set_value{\??transparencysetter   #1:#2}{\colo_helpers_inherited_direct_ts{#3}}%
1198   \colo_helpers_set_value{\??transparencyattribute#1:#2}{\colo_helpers_inherited_direct_ta{#3}}}
1199
1200\def\colo_palets_define_undefine#1#2#3%
1201  {\localundefine{\??colorsetter          #1:#2}%
1202   \localundefine{\??colorattribute       #1:#2}%
1203   \localundefine{\??transparencysetter   #1:#2}%
1204   \localundefine{\??transparencyattribute#1:#2}}
1205
1206\def\colo_palets_define_assign#1#2#3%
1207  {\definecolor[\??colorpalet#1:#2][#3]%
1208   \colo_helpers_set_value{\??colorsetter          #1:#2}{\colo_helpers_inherited_direct_cs{\??colorpalet#1:#2}}%
1209   \colo_helpers_set_value{\??colorattribute       #1:#2}{\colo_helpers_inherited_direct_ca{\??colorpalet#1:#2}}%
1210   \colo_helpers_set_value{\??transparencysetter   #1:#2}{\colo_helpers_inherited_direct_ts{\??colorpalet#1:#2}}%
1211   \colo_helpers_set_value{\??transparencyattribute#1:#2}{\colo_helpers_inherited_direct_ta{\??colorpalet#1:#2}}}
1212
1213\setvalue{\??colorattribute        currentcolor}{\the\c_attr_color}        % for mpcolor
1214\setvalue{\??transparencyattribute currentcolor}{\the\c_attr_transparency} % for mpcolor
1215
1216%def\colo_helpers_inherited_current_ca#1{\csname\??colorattribute       \ifcsname\??colorattribute       \currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??colorattribute       #1\endcsname#1\fi\fi\endcsname}
1217%def\colo_helpers_inherited_current_cs#1{\csname\??colorsetter          \ifcsname\??colorsetter          \currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??colorsetter          #1\endcsname#1\fi\fi\endcsname}
1218%def\colo_helpers_inherited_current_ta#1{\csname\??transparencyattribute\ifcsname\??transparencyattribute\currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??transparencyattribute#1\endcsname#1\fi\fi\endcsname}
1219%def\colo_helpers_inherited_current_ts#1{\csname\??transparencysetter   \ifcsname\??transparencysetter   \currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??transparencysetter   #1\endcsname#1\fi\fi\endcsname}
1220
1221\def\colo_helpers_inherited_current_ca#1{\ifcsname\??colorattribute       \currentcolorprefix#1\endcsname\lastnamedcs\else\ifcsname\??colorattribute       #1\endcsname\lastnamedcs\else\!!zerocount\fi\fi}
1222\def\colo_helpers_inherited_current_cs#1{\ifcsname\??colorsetter          \currentcolorprefix#1\endcsname\lastnamedcs\else\ifcsname\??colorsetter          #1\endcsname\lastnamedcs\else\fi\fi}
1223\def\colo_helpers_inherited_current_ta#1{\ifcsname\??transparencyattribute\currentcolorprefix#1\endcsname\lastnamedcs\else\ifcsname\??transparencyattribute#1\endcsname\lastnamedcs\else\!!zerocount\fi\fi}
1224\def\colo_helpers_inherited_current_ts#1{\ifcsname\??transparencysetter   \currentcolorprefix#1\endcsname\lastnamedcs\else\ifcsname\??transparencysetter   #1\endcsname\lastnamedcs\else\fi\fi}
1225
1226%D Low level defs:
1227
1228\unexpanded\def\colordefalc#1#2{\setevalue{\??colorattribute       #1}{#2}\setvalue {\??colorsetter       #1}{\c_attr_color       #2 }}
1229\unexpanded\def\colordefagc#1#2{\setxvalue{\??colorattribute       #1}{#2}\setgvalue{\??colorsetter       #1}{\c_attr_color       #2 }} % was not g
1230\unexpanded\def\colordefalt#1#2{\setevalue{\??transparencyattribute#1}{#2}\setvalue {\??transparencysetter#1}{\c_attr_transparency#2 }}
1231\unexpanded\def\colordefagt#1#2{\setxvalue{\??transparencyattribute#1}{#2}\setgvalue{\??transparencysetter#1}{\c_attr_transparency#2 }}
1232
1233\unexpanded\def\colordefflc#1#2{\setvalue {\??colorattribute       #1}{\colo_helpers_inherited_current_ca{#2}}\setvalue {\??colorsetter       #1}{\colo_helpers_inherited_current_cs{#2}}}
1234\unexpanded\def\colordeffgc#1#2{\setgvalue{\??colorattribute       #1}{\colo_helpers_inherited_current_ca{#2}}\setvalue {\??colorsetter       #1}{\colo_helpers_inherited_current_cs{#2}}}
1235\unexpanded\def\colordefflt#1#2{\setvalue {\??transparencyattribute#1}{\colo_helpers_inherited_current_ta{#2}}\setvalue {\??transparencysetter#1}{\colo_helpers_inherited_current_ts{#2}}}
1236\unexpanded\def\colordeffgt#1#2{\setgvalue{\??transparencyattribute#1}{\colo_helpers_inherited_current_ta{#2}}\setgvalue{\??transparencysetter#1}{\colo_helpers_inherited_current_ts{#2}}}
1237
1238\unexpanded\def\colordefrlc  #1{\localundefine {\??colorattribute       #1}\localundefine {\??colorsetter       #1}}
1239\unexpanded\def\colordefrgc  #1{\globalundefine{\??colorattribute       #1}\globalundefine{\??colorsetter       #1}}
1240\unexpanded\def\colordefrlt  #1{\localundefine {\??transparencyattribute#1}\localundefine {\??transparencysetter#1}}
1241\unexpanded\def\colordefrgt  #1{\globalundefine{\??transparencyattribute#1}\globalundefine{\??transparencysetter#1}}
1242
1243%D \macros
1244%D   {colorvalue, grayvalue}
1245%D
1246%D We can typeset the color components using \type {\colorvalue} and \type
1247%D {\grayvalue}. The commands:
1248%D
1249%D \startbuffer
1250%D color value of SomeKindOfRed: \colorvalue{SomeKindOfRed} \crlf
1251%D gray value of SomeKindOfRed: \grayvalue{SomeKindOfRed}
1252%D \stopbuffer
1253%D
1254%D \typebuffer
1255%D
1256%D show us:
1257%D
1258%D \startexample
1259%D \getbuffer
1260%D \stopexample
1261
1262\let\currentcolorname\s!black % todo
1263\let\outercolorname  \s!black % todo
1264
1265\let\colorformatseparator\space
1266
1267\def\MPcolor#1%
1268  {\clf_mpcolor
1269     \c_attr_colormodel
1270     \colo_helpers_inherited_current_ca{#1} %
1271     \colo_helpers_inherited_current_ta{#1} }
1272
1273\def\MPcoloronly#1%
1274  {\clf_mpcolor
1275     \c_attr_colormodel
1276     \colo_helpers_inherited_current_ca{#1} %
1277     \zerocount}
1278
1279\def\MPtransparency#1%
1280  {\clf_mpcolor
1281     \zerocount
1282     \zerocount
1283     \colo_helpers_inherited_current_ta{#1} }
1284
1285\def\MPoptions#1%
1286  {\clf_mpoptions
1287     \c_attr_colormodel
1288     \colo_helpers_inherited_current_ca{#1} %
1289     \colo_helpers_inherited_current_ta{#1} }
1290
1291\def\thecolormodelattribute    {\the\c_attr_colormodel}
1292
1293%def\thecolorattribute       #1{\number\csname\??colorattribute       \ifcsname\??colorattribute       \currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??colorattribute       #1\endcsname#1\fi\fi\endcsname}
1294%def\thetransparencyattribute#1{\number\csname\??transparencyattribute\ifcsname\??transparencyattribute\currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??transparencyattribute#1\endcsname#1\fi\fi\endcsname}
1295
1296\def\rawcolorattribute       #1{\ifcsname\??colorattribute       \currentcolorprefix#1\endcsname\lastnamedcs\else\ifcsname\??colorattribute       #1\endcsname\lastnamedcs\else\zerocount\fi\fi}
1297\def\rawtransparencyattribute#1{\ifcsname\??transparencyattribute\currentcolorprefix#1\endcsname\lastnamedcs\else\ifcsname\??transparencyattribute#1\endcsname\lastnamedcs\else\zerocount\fi\fi}
1298
1299\def\thecolorattribute       #1{\number\ifcsname\??colorattribute       \currentcolorprefix#1\endcsname\lastnamedcs\else\ifcsname\??colorattribute       #1\endcsname\lastnamedcs\else\zerocount\fi\fi}
1300\def\thetransparencyattribute#1{\number\ifcsname\??transparencyattribute\currentcolorprefix#1\endcsname\lastnamedcs\else\ifcsname\??transparencyattribute#1\endcsname\lastnamedcs\else\zerocount\fi\fi}
1301\def\internalspotcolorname   #1{\clf_spotcolorname  \thecolorattribute{#1} }
1302\def\internalspotcolorparent #1{\clf_spotcolorparent\thecolorattribute{#1} }
1303\def\internalspotcolorsize   #1{\clf_spotcolorvalue \thecolorattribute{#1} }
1304
1305\def\colorcomponents         #1{\clf_colorcomponents       \thecolorattribute       {#1} }
1306\def\transparencycomponents  #1{\clf_transparencycomponents\thetransparencyattribute{#1} }
1307\def\processcolorcomponents  #1{\clf_processcolorcomponents\thecolorattribute       {#1} }
1308
1309\def\colorvalue              #1{\clf_formatcolor\thecolorattribute{#1}{\colorformatseparator}}
1310\def\grayvalue               #1{\clf_formatgray \thecolorattribute{#1}{\colorformatseparator}}
1311
1312\def\doifelseblack           #1{\clf_doifelseblack\thecolorattribute{#1} }
1313\def\doifelsedrawingblack      {\clf_doifelsedrawingblack}
1314
1315\let\doifblackelse        \doifelseblack
1316\let\doifdrawingblackelse \doifelsedrawingblack
1317
1318\let\doifblackelse       \doifelseblack
1319\let\doifdrawingblackelse\doifelsedrawingblack
1320
1321%D \macros
1322%D   {forcecolorhack}
1323%D
1324%D We can out this in front of (for instance) a special and so force color to be
1325%D applied (only glyphs, rules and leaders are handled).
1326%D
1327%D \startbuffer
1328%D \framed
1329%D   [background=color,backgroundcolor=yellow,framecolor=red,corner=round]
1330%D   {test}
1331%D \stopbuffer
1332%D
1333%D \typebuffer \getbuffer
1334
1335% ignores in attribute handler
1336%
1337% \def\forcecolorhack{\vrule\s!width\zeropoint\s!height\zeropoint\s!depth\zeropoint}
1338
1339% \normal added else fails in metafun manual (leaders do a hard scan)
1340
1341% \unexpanded\def\forcecolorhack{\leaders\hrule\hskip\zeropoint\relax} % relax is needed !
1342%
1343% I really need to sort this out!
1344
1345\unexpanded\def\forcecolorhack{\leaders\hrule height\zeropoint depth\zeropoint\hskip\zeropoint\relax} % relax is needed !
1346
1347%D We default to the colors defined in \type {colo-imp-rgb} and
1348%D support both \RGB\ and \CMYK\ output. Transparencies are defined
1349%D here:
1350
1351\definecolor[black][s=0]
1352\definecolor[white][s=1]
1353
1354\definetransparency [none]        [0]
1355\definetransparency [normal]      [1]
1356\definetransparency [multiply]    [2]
1357\definetransparency [screen]      [3]
1358\definetransparency [overlay]     [4]
1359\definetransparency [softlight]   [5]
1360\definetransparency [hardlight]   [6]
1361\definetransparency [colordodge]  [7]
1362\definetransparency [colorburn]   [8]
1363\definetransparency [darken]      [9]
1364\definetransparency [lighten]    [10]
1365\definetransparency [difference] [11]
1366\definetransparency [exclusion]  [12]
1367\definetransparency [hue]        [13]
1368\definetransparency [saturation] [14]
1369\definetransparency [color]      [15]
1370\definetransparency [luminosity] [16]
1371
1372%D Some common ones:
1373
1374\definecolor[trace:0][s=.4]
1375\definecolor[trace:1][r=.6]
1376\definecolor[trace:2][g=.6]
1377\definecolor[trace:3][b=.6]
1378\definecolor[trace:4][r=.6,g=.6]
1379\definecolor[trace:5][r=.6,b=.6]
1380\definecolor[trace:6][g=.6,b=.6]
1381\definecolor[trace:7][r=.8,g=.4]
1382\definecolor[trace:8][r=.8,b=.4]
1383\definecolor[trace:9][g=.4,b=.8]
1384
1385\definecolor[trace:w][s=1]
1386\definecolor[trace:r][r=.75,t=.5,a=1]
1387\definecolor[trace:g][g=.75,t=.5,a=1]
1388\definecolor[trace:b][b=.75,t=.5,a=1]
1389%definecolor[trace:c][c=.75,t=.5,a=1]
1390%definecolor[trace:m][m=.75,t=.5,a=1]
1391%definecolor[trace:y][y=.75,t=.5,a=1]
1392\definecolor[trace:c][g=.75,b=.75,t=.5,a=1]
1393\definecolor[trace:m][r=.75,b=.75,t=.5,a=1]
1394\definecolor[trace:y][r=.75,g=.75,t=.5,a=1]
1395\definecolor[trace:s][s=.75,t=.5,a=1]
1396\definecolor[trace:d][s=.25,t=.5,a=1]
1397\definecolor[trace:o][r=1,g=.6,b=.1,t=.5,a=1]
1398
1399\definecolor[trace:dw][s=1]
1400\definecolor[trace:dr][r=.75,t=.75,a=1]
1401\definecolor[trace:dg][g=.75,t=.75,a=1]
1402\definecolor[trace:db][b=.75,t=.75,a=1]
1403%definecolor[trace:dc][c=.75,t=.75,a=1]
1404%definecolor[trace:dm][m=.75,t=.75,a=1]
1405%definecolor[trace:dy][y=.75,t=.75,a=1]
1406\definecolor[trace:dc][g=.75,b=.75,t=.75,a=1]
1407\definecolor[trace:dm][r=.75,b=.75,t=.75,a=1]
1408\definecolor[trace:dy][r=.75,g=.75,t=.75,a=1]
1409\definecolor[trace:ds][s=.75,t=.75,a=1]
1410\definecolor[trace:dd][s=.25,t=.75,a=1]
1411\definecolor[trace:do][r=1,g=.6,b=.1,t=.75,a=1]
1412
1413\setupcolors
1414  [\c!state=\v!stop, % color will be enabled later on
1415   \c!conversion=\v!yes,
1416   \c!rgb=\v!yes,
1417   \c!cmyk=\v!yes,
1418   \c!spot=\v!yes,
1419   \c!pagecolormodel=\v!none,
1420   \c!expansion=\v!no,
1421   \c!textcolor=,
1422   \c!factor=\v!yes]
1423
1424\setupcolor
1425  [\v!rgb]
1426
1427\protect \endinput
1428