s-colors-show.mkxl /size: 9939 b    last modification: 2023-12-21 09:45
1%D \module
2%D   [       file=colo-run,
3%D        version=1997.04.01,
4%D          title=\CONTEXT\ Color Macros,
5%D       subtitle=Runtime loaded commands,
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\registerctxluafile{colo-run}{}
15
16\unprotect
17
18%D Colors
19
20%D These are nicer in \LUA\ code than in \TEX\ code but not more efficient.
21
22\permanent\protected\gdef\showcolorbar[#1]%
23  {\backgroundline[#1]{\strut\enspace\color[white]{white}\enspace\color[black]{black}\enspace}}
24
25\permanent\protected\tolerant\gdef\showcolorset[#1]%
26  {\ctxcommand{showcolorset("#1")}}
27
28\permanent\protected\tolerant\gdef\showcolorcomponents[#1]%
29  {\ctxcommand{showcolorcomponents("#1")}}
30
31\permanent\protected\tolerant\gdef\showcolor[#1]%
32  {\ifparameter#1\or
33     \usecolors   [#1]% delayed and we can only ask for the set if
34     \showcolorset[#1]% loading has happened
35   \fi}
36
37%D The rest might also be done in \LUA\ although there is not much beauty to gain
38%D here (too much typesetting specific). Also, these macros are pretty old and
39%D hardly used so best keep them as they are. But we keep them because they always
40%D worked and it doesn't hurt to see some \MKII|-|code every now and then.
41
42%D Palets
43
44\permanent\protected\tolerant\gdef\showpalet[#1]#*[#2]%
45  {\doifelsecolorpalet{#1}
46     {\doifelseinset\v!vertical{#2}\colo_palets_show_vertical\colo_palets_show_horizontal{#1}{#2}}%
47     {}}
48
49\gdef\colo_palets_show_vertical#1#2%
50  {\begingroup
51   \forgetall
52   \setlocalhsize
53   \hsize\localhsize
54   \offinterlineskip
55   \setuppalet[#1]
56   \tabskip\zeroskip
57   \def\colo_palets_show_palet##1%
58     {\doifelseinset\v!number{#2}{##1\hskip.5\emwidth}{}%
59      \aligntab
60      \color    [##1]{\vrule\s!width3\emwidth\s!height\strutht\s!depth\strutdp}%
61      \graycolor[##1]{\vrule\s!width3\emwidth\s!height\strutht\s!depth\strutdp}%
62      \aligntab
63      \doifinset\v!value{#2}{\hskip.5\emwidth\colorvalue{##1}}%
64      \crcr}
65   \halign
66     {\hss\alignmark\alignmark\aligntab\hss\alignmark\alignmark\hss\aligntab\alignmark\alignmark\cr
67      \aligntab\doifinset\v!name{#2}{\strut#1}\aligntab\cr
68      \colo_palets_process[#1]\colo_palets_show_palet\crcr}%
69  \endgroup}
70
71\gdef\colo_palets_show_horizontal#1#2% todo: bTABLE etc
72  {\vbox
73     {\forgetall
74      \setlocalhsize
75      \hsize\localhsize
76      \offinterlineskip
77      \setuppalet[#1]
78      \tabskip\zeroskip
79      \scratchwidth\zeropoint
80      \doifinset\v!number{#2}
81        {\def\colo_palets_show_palet##1%
82           {\setbox\scratchbox\hbox{##1}%
83            \ifdim\scratchwidth<\wd\scratchbox
84              \scratchwidth\wd\scratchbox
85            \fi}%
86         \colo_palets_process[#1]\colo_palets_show_palet}%
87      \advanceby\scratchwidth\emwidth
88      \ifdim\scratchwidth<5\emwidth
89        \scratchwidth5\emwidth
90      \fi
91      \halign
92        {\alignmark\alignmark\aligntab\aligntab\hbox to \scratchwidth{\hss\alignmark\alignmark\hss}\cr
93         \doifinset\v!number{#2}
94           {\def\colo_palets_show_palet##1{\aligntab\strut##1}%
95            \colo_palets_process[#1]\colo_palets_show_palet}\cr
96         \doifinset\v!name{#2}{#1\hskip.5\emwidth}%
97         \def\colo_palets_show_palet##1%
98           {\aligntab\strut\color[##1]{\vrule\s!width\scratchwidth\s!height\strutht\s!depth\zeropoint}}%
99         \colo_palets_process[#1]\colo_palets_show_palet\crcr
100         \noalign{\vskip-\strutdepth}%
101         \def\colo_palets_show_palet##1%
102           {\aligntab\graycolor[##1]{\vrule\s!width\scratchwidth\s!height\zeropoint\s!depth\strutdp}}%
103         \colo_palets_process[#1]\colo_palets_show_palet\crcr
104         \doifinset\v!value{#2}
105           {\def\colo_palets_show_palet##1%
106             {\aligntab\vbox
107                {\hsize\scratchwidth
108                 \vskip.25\exheight
109                 \everypar{\strut}
110                 \veryraggedcenter
111                 \let\colorformatseparator\endgraf
112                 \colorvalue{##1}}}%
113            \colo_palets_process[#1]\colo_palets_show_palet}%
114         \crcr}}}
115
116\gdef\colo_palets_process[#1]%
117  {\getpaletlist[#1]%
118   \normalexpanded{\globalprocesscommalist[\paletlist]}}
119
120\permanent\protected\tolerant\gdef\comparepalet[#1]%
121  {\doifelsecolorpalet{#1}%
122     {\hbox
123        {\colo_palets_compare_indeed\color{#1}%
124         \quad
125         \colo_palets_compare_indeed\graycolor{#1}}}%
126     {}}
127
128\gdef\colo_palets_compare_indeed#1#2%
129  {\vbox
130     {\forgetall
131      \setlocalhsize
132      \hsize\localhsize
133      \offinterlineskip
134      \setuppalet[#2]
135      \getpaletsize[#2]%
136      \getpaletlist[#2]%
137      \scratchwidth2\emwidth\relax
138      \hsize\paletsize\scratchwidth
139      \def\colo_palets_compare##1%
140        {\hbox
141           {\setbox0\hbox
142              {#1[##1]{\vrule\s!width\hsize\s!height3ex}}%
143            \wd0\zeropoint
144            \box0
145            \hbox to \hsize
146              {\def\colo_palets_compare####1%
147                 {\hbox to \scratchwidth
148                    {\hss#1[####1]{\vrule\s!width.5\scratchwidth\s!height2.25\exheight\s!depth-.75\exheight}\hss}}%
149               \processcommacommand[\paletlist]\colo_palets_compare}}
150         \endgraf}
151      \processcommacommand[\paletlist]\colo_palets_compare}}
152
153%D Groups
154
155\permanent\protected\tolerant\gdef\showcolorgroup[#1]#*[#2]%
156  {\doifcolor{#1:1}
157     {\doifelseinset\v!vertical{#2}\colo_groups_show_vertical\colo_groups_show_horizontal{#1}{#2}}}
158
159\gdef\colo_groups_show_horizontal#1#2%
160  {\vbox
161     {\forgetall
162      \setlocalhsize
163      \hsize\localhsize
164      \offinterlineskip
165      \setuppalet
166      \tabskip\zeroskip
167      \def\colorformatseparator{\strut\cr}
168      \def\colo_groups_show_group##1%
169        {\doifcolor{#1:##1}{\vbox
170           {\halign
171              {\hss\alignmark\alignmark\alignmark\alignmark\hss\cr
172               \doifinset\v!number{#2}{\strut##1}\cr
173               \color    [#1:##1]{\vrule\s!width4\emwidth\s!height\strutht  \s!depth\zeropoint}\cr
174               \graycolor[#1:##1]{\vrule\s!width4\emwidth\s!height\zeropoint\s!depth\strutdp  }\cr
175               \doifinset\v!value{#2}{\colorvalue{#1:##1}\strut}\crcr}}}}%
176      \hbox
177        {\doifinset\v!name{#2}
178           {\strut
179            \doifelseinset\v!value{#2}
180              {\raise3\lineheight\hbox{#1\hskip.5\emwidth}}
181              {#1}%
182            \hskip.5\emwidth}%
183         \colo_groups_show_group1\colo_groups_show_group2\colo_groups_show_group3\colo_groups_show_group4%
184         \colo_groups_show_group5\colo_groups_show_group6\colo_groups_show_group7\colo_groups_show_group8}}}
185
186\gdef\colo_groups_show_vertical#1#2%
187  {\vbox
188     {\forgetall
189      \setlocalhsize
190      \hsize\localhsize
191      \offinterlineskip
192      \setuppalet
193      \tabskip\zeroskip
194      \def\colo_groups_show_group##1%
195        {\doifcolor{#1:##1}
196           {\doifinset\v!number{#2}
197              {##1\hskip.5\emwidth}%
198            \aligntab
199            \color    [#1:##1]{\vrule\s!width2.5\emwidth\s!height\strutht\s!depth\strutdp}%
200            \graycolor[#1:##1]{\vrule\s!width2.5\emwidth\s!height\strutht\s!depth\strutdp}
201            \aligntab
202            \doifinset\v!value{#2}{\hskip.5\emwidth\colorvalue{#1:##1}}%
203            \crcr}}%
204      \halign
205        {\hss\alignmark\alignmark\aligntab\hss\alignmark\alignmark\hss\aligntab\alignmark\alignmark\hss\cr
206         \aligntab\doifinset\v!name{#2}{\strut#1}\aligntab\crcr
207         \colo_groups_show_group1\colo_groups_show_group2\colo_groups_show_group3\colo_groups_show_group4%
208         \colo_groups_show_group5\colo_groups_show_group6\colo_groups_show_group7\colo_groups_show_group8}}}
209
210\permanent\protected\tolerant\gdef\comparecolorgroup[#1]%
211  {\doifcolor{#1:1}
212     {\hbox
213        {\colo_groups_compare_indeed\color    {#1}\quad
214         \colo_groups_compare_indeed\graycolor{#1}}}}
215
216\gdef\colo_groups_compare_indeed#1#2%
217  {\vbox
218     {\forgetall
219      \setlocalhsize
220      \hsize\localhsize
221      \scratchcounter\zerocount
222      \dorecurse{15}{\doifcolor{#2:\recurselevel}{\advanceby\scratchcounter\plusone}}
223      \scratchwidth2\emwidth\relax
224      \hsize\scratchcounter\scratchwidth
225      \dorecurse\scratchcounter{\colo_groups_compare_step{#1}{#2}\recurselevel}}}
226
227\def\colo_groups_compare_step#1#2#3%
228  {\hbox to \hsize
229     {\setbox\scratchbox\hbox
230        {#1[#2:#3]{\vrule\s!width\hsize\s!height3\exheight}}%
231      \wd\scratchbox\zeropoint
232      \box\scratchbox
233      \hbox to \hsize
234        {\hss
235         \dorecurse\scratchcounter
236            {#1[#2:\recurselevel]{\vrule\s!width.5\scratchwidth\s!height2.25\exheight\s!depth-.75\exheight}%
237         \hss}}}
238   \endgraf}
239
240\permanent\tolerant\protected\def\compareluminance[#1]#*[#2]% by MS
241  {\dontleavehmode\hpack\bgroup
242     \unframed
243       [\c!background=\v!color,\c!backgroundcolor=#2,\c!foregroundcolor=#1,\c!loffset=.25\exheight,\c!roffset=.25\exheight]%
244       {#1\enspace#2\quad\colorluminanceratio{#1}{#2}}%
245     \unframed
246       [\c!background=\v!color,\c!backgroundcolor=#1,\c!foregroundcolor=#2,\c!loffset=.25\exheight,\c!roffset=.25\exheight]%
247       {#2\enspace#1\quad\colorluminanceratio{#2}{#1}}%
248   \egroup}
249
250\protect
251
252\continueifinputfile{s-colors-show.mkxl}
253
254\setupwhitespace[big]
255
256\usecolors[dem]
257
258\starttext
259
260\startsubject[title=\type{\showpalet}]
261    \showpalet [alfa] [horizontal,name,number,value]
262\stopsubject
263
264\startsubject[title=\type{\showcolorcomponents}]
265    \showcolorcomponents[red,green,blue]
266\stopsubject
267
268\startsubject[title=\type{\comparepalet}]
269    \comparepalet[alfa]
270\stopsubject
271
272\startsubject[title=\type{\showcolor}]
273    \showcolor[rgb]
274\stopsubject
275
276\startsubject[title=\type{\showcolorgroup}]
277    \showcolorgroup[magenta]
278    \showcolorgroup[cyan]
279    \showcolorgroup[yellow]
280\stopsubject
281
282\startsubject[title=\type{\comparecolorgroup}]
283    \comparecolorgroup[magenta]
284\stopsubject
285
286\stoptext
287