colo-grp.mkiv /size: 4817 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=colo-grp,
3%D        version=2011.12.27, % moved from colo-ini
4%D          title=\CONTEXT\ Color Macros,
5%D       subtitle=Groups,
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 Regular colors and palets are used most, contrary to groups
15%D which is why we define their support in a separate module.
16
17\writestatus{loading}{ConTeXt Color Macros / Groups}
18
19\unprotect
20
21%D \macros
22%D   {definecolorgroup}
23%D
24%D The naming of the colors in this palet suggests some
25%D ordening, which in turn is suported by color grouping.
26%D
27%D \starttyping
28%D \definecolorgroup
29%D   [red]
30%D   [1.00:0.90:0.90,
31%D    1.00:0.80:0.80,
32%D    1.00:0.70:0.70,
33%D    1.00:0.55:0.55,
34%D    1.00:0.40:0.40,
35%D    1.00:0.25:0.25,
36%D    1.00:0.15:0.15,
37%D    0.90:0.00:0.00]
38%D \stoptyping
39%D
40%D In such a color group colors are numbered from~$1$ to~$n$.
41%D
42%D \showsetup{definecolorgroup}
43%D
44%D This kind of specification is not only more compact than
45%D defining each color separate, it also loads faster and takes
46%D less bytes.
47
48\installcorenamespace{colorgroup}
49\installcorenamespace{colorgroupsetter}
50
51\newcount\c_colo_groups_n % scratch counter
52
53\unexpanded\def\definecolorgroup % sort of obsolete, just use palets directly
54  {\dotripleempty\colo_groups_define}
55
56\def\colo_groups_define
57  {\ifthirdargument
58     \expandafter\colo_groups_define_normal
59   \else
60     \expandafter\colo_groups_define_checked
61   \fi}
62
63\def\colo_groups_define_normal[#1][#2][#3]%
64  {\c_colo_groups_n\zerocount
65   \processcommalist[#3]{\colo_groups_define_entry{#1}{#2}}}
66
67\def\colo_groups_define_checked[#1][#2][#3]%
68  {\doifelseinstring{:}{#2}
69     {\colo_groups_define_normal[#1][\v!rgb][#2]}
70     {\doloop % inherited
71        {\ifcsname#2:##1\endcsname
72           \definecolor[#1:##1][#2:##1]%
73         \else
74           \exitloop
75         \fi}}}
76
77\def\colo_groups_define_entry#1#2#3% name mode specification
78  {\advance\c_colo_groups_n\plusone
79   \csname\??colorgroupsetter\ifcsname\??colorgroupsetter#2\endcsname#2\else\s!rgb\fi\endcsname[#1:\the\c_colo_groups_n][#3:0:0:0:0]}
80
81\setvalue{\??colorgroupsetter\s!gray}[#1][#2:#3]{\definecolor[#1][s=#2]}
82\setvalue{\??colorgroupsetter\s!rgb }[#1][#2:#3:#4:#5]{\definecolor[#1][r=#2,g=#3,b=#4]}
83\setvalue{\??colorgroupsetter\s!cmyk}[#1][#2:#3:#4:#5:#6]{\definecolor[#1][c=#2,m=#3=,y=#4,k=#5]}
84\setvalue{\??colorgroupsetter\s!spot}[#1][#2:#3:#4]{\definespotcolor[#1][#2][p=#3]}
85
86%D \macros
87%D   {showcolorgroup}
88%D
89%D We can show the group by:
90%D
91%D \startbuffer
92%D \showcolorgroup [blue] [horizontal,name,number,value]
93%D \stopbuffer
94%D
95%D \typebuffer
96%D
97%D or in color:
98%D
99%D \startlinecorrection
100%D \getbuffer
101%D \stoplinecorrection
102%D
103%D which uses:
104%D
105%D \showsetup{showcolorgroup}
106
107\fetchruntimecommand \showcolorgroup \f!colo_run
108
109%D There are ten predefined color groups, like
110%D \color[green]{\em groen}, \color[red]{\em rood},
111%D \color[blue]{\em blauw}, \color[cyan]{\em cyaan},
112%D \color[magenta]{\em magenta} and \color[yellow]{\em geel}.
113%D
114%D \startlinecorrection
115%D \hbox to \hsize
116%D   {\hss
117%D    \showcolorgroup [red]    [vertical,name,number]\hss
118%D    \showcolorgroup [green]  [vertical,name]\hss
119%D    \showcolorgroup [blue]   [vertical,name]\hss
120%D    \showcolorgroup [cyan]   [vertical,name]\hss
121%D    \showcolorgroup [magenta][vertical,name]\hss
122%D    \showcolorgroup [yellow] [vertical,name]\hss}
123%D \stoplinecorrection
124%D
125%D These groups are used to define palets {\em alfa} upto {\em
126%D zeta}. As long as we don't use colors from the same row, we
127%D get ourselves distinctive palets. By activating such a palet
128%D one gains access to its members {\em top} to {\em charm} (of
129%D course one should use more suitable names than these).
130%D
131%D \startlinecorrection
132%D \hbox to \hsize
133%D   {\showpalet [alfa]    [vertical,name,number]\hss
134%D    \showpalet [beta]    [vertical,name]\hss
135%D    \showpalet [gamma]   [vertical,name]\hss
136%D    \showpalet [delta]   [vertical,name]\hss
137%D    \showpalet [epsilon] [vertical,name]\hss
138%D    \showpalet [zeta]    [vertical,name]}
139%D \stoplinecorrection
140%D
141%D By using the keyword \type {value} the individual color
142%D components are shown too. When printed in color, these
143%D showcases show both the colors and the gray value.
144
145%D \macros
146%D   {comparecolorgroup}
147%D
148%D The similar command:
149%D
150%D \startbuffer
151%D \comparecolorgroup [blue]
152%D \stopbuffer
153%D
154%D \typebuffer
155%D
156%D shows color groups:
157%D
158%D \startlinecorrection
159%D \getbuffer
160%D \stoplinecorrection
161%D
162%D this commands are defined as:
163%D
164%D \showsetup{comparecolorgroup}
165
166\fetchruntimecommand \comparecolorgroup \f!colo_run
167
168\protect \endinput
169