summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/colo-grp.mkxl
blob: 9237952d75079dff636c48e562702f2200ced087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
%D \module
%D   [       file=colo-grp,
%D        version=2011.12.27, % moved from colo-ini
%D          title=\CONTEXT\ Color Macros,
%D       subtitle=Groups,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D Regular colors and palets are used most, contrary to groups which is why we
%D define their support in a separate module.

\writestatus{loading}{ConTeXt Color Macros / Groups}

\unprotect

%D \macros
%D   {definecolorgroup}
%D
%D The naming of the colors in this palet suggests some ordening, which in turn is
%D suported by color grouping.
%D
%D \starttyping
%D \definecolorgroup
%D   [red]
%D   [1.00:0.90:0.90,
%D    1.00:0.80:0.80,
%D    1.00:0.70:0.70,
%D    1.00:0.55:0.55,
%D    1.00:0.40:0.40,
%D    1.00:0.25:0.25,
%D    1.00:0.15:0.15,
%D    0.90:0.00:0.00]
%D \stoptyping
%D
%D In such a color group colors are numbered from~$1$ to~$n$.
%D
%D \showsetup{definecolorgroup}
%D
%D This kind of specification is not only more compact than defining each color
%D separate, it also loads faster and takes less bytes.

\installcorenamespace{colorgroup}
\installcorenamespace{colorgroupsetter}

\newcount\c_colo_groups_n % scratch counter

\permanent\tolerant\protected\def\definecolorgroup[#1]#*[#2]#*[#3]% % sort of obsolete, just use palets directly
  {\ifarguments\or\or
     \ifhastok:{#2}%
       \colo_groups_define_normal[#1][\v!rgb][#2]
     \else
       \colo_groups_define_checked[#1][#2][]%
     \fi
   \else
     \colo_groups_define_normal[#1][#2][#3]%
   \fi}

\def\colo_groups_define_normal[#1][#2][#3]%
  {\c_colo_groups_n\zerocount
   \processcommalist[#3]{\colo_groups_define_entry{#1}{#2}}}

\def\colo_groups_define_checked[#1][#2][#3]%
  {\doloop % inherited
     {\ifcsname#2:##1\endcsname
        \definecolor[#1:##1][#2:##1]%
      \else
        \exitloop
      \fi}}

\def\colo_groups_define_entry#1#2#3% name mode specification
  {\advance\c_colo_groups_n\plusone
   \csname\??colorgroupsetter\ifcsname\??colorgroupsetter#2\endcsname#2\else\s!rgb\fi\endcsname[#1:\the\c_colo_groups_n][#3:0:0:0:0]}

\setvalue{\??colorgroupsetter\s!gray}[#1][#2:#3]{\definecolor[#1][s=#2]}
\setvalue{\??colorgroupsetter\s!rgb }[#1][#2:#3:#4:#5]{\definecolor[#1][r=#2,g=#3,b=#4]}
\setvalue{\??colorgroupsetter\s!cmyk}[#1][#2:#3:#4:#5:#6]{\definecolor[#1][c=#2,m=#3=,y=#4,k=#5]}
\setvalue{\??colorgroupsetter\s!spot}[#1][#2:#3:#4]{\definespotcolor[#1][#2][p=#3]}

%D \macros
%D   {showcolorgroup}
%D
%D We can show the group by:
%D
%D \startbuffer
%D \showcolorgroup [blue] [horizontal,name,number,value]
%D \stopbuffer
%D
%D \typebuffer
%D
%D or in color:
%D
%D \startlinecorrection
%D \getbuffer
%D \stoplinecorrection
%D
%D which uses:
%D
%D \showsetup{showcolorgroup}

\fetchmodulecommand \showcolorgroup \f!colo_run

%D There are ten predefined color groups, like \color [green] {\em groen}, \color
%D [red] {\em rood}, \color [blue] {\em blauw}, \color [cyan] {\em cyaan}, \color
%D [magenta] {\em magenta} and \color [yellow] {\em geel}.
%D
%D \startlinecorrection
%D \hbox to \hsize
%D   {\hss
%D    \showcolorgroup [red]    [vertical,name,number]\hss
%D    \showcolorgroup [green]  [vertical,name]\hss
%D    \showcolorgroup [blue]   [vertical,name]\hss
%D    \showcolorgroup [cyan]   [vertical,name]\hss
%D    \showcolorgroup [magenta][vertical,name]\hss
%D    \showcolorgroup [yellow] [vertical,name]\hss}
%D \stoplinecorrection
%D
%D These groups are used to define palets {\em alfa} upto {\em zeta}. As long as we
%D don't use colors from the same row, we get ourselves distinctive palets. By
%D activating such a palet one gains access to its members {\em top} to {\em charm}
%D (of course one should use more suitable names than these).
%D
%D \startlinecorrection
%D \hbox to \hsize
%D   {\showpalet [alfa]    [vertical,name,number]\hss
%D    \showpalet [beta]    [vertical,name]\hss
%D    \showpalet [gamma]   [vertical,name]\hss
%D    \showpalet [delta]   [vertical,name]\hss
%D    \showpalet [epsilon] [vertical,name]\hss
%D    \showpalet [zeta]    [vertical,name]}
%D \stoplinecorrection
%D
%D By using the keyword \type {value} the individual color components are shown too.
%D When printed in color, these showcases show both the colors and the gray value.

%D \macros
%D   {comparecolorgroup}
%D
%D The similar command:
%D
%D \startbuffer
%D \comparecolorgroup [blue]
%D \stopbuffer
%D
%D \typebuffer
%D
%D shows color groups:
%D
%D \startlinecorrection
%D \getbuffer
%D \stoplinecorrection
%D
%D this commands are defined as:
%D
%D \showsetup{comparecolorgroup}

\fetchmodulecommand \comparecolorgroup \f!colo_run

\protect \endinput