colo-ini.mkxl /size: 47 Kb    last modification: 2020-07-01 14:35
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!colors
4
{
#
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
\ifempty
\currentcolorprefix
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
\ifempty
\currentcolorprefix
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
\ifempty
\currentcolorprefix
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
\ifempty
\currentcolorprefix
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
\ifempty
\currentcolorprefix
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
\ifempty
\currentcolorprefix
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
[
\ifempty
\maintextcolor
\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
{
1
0
}
\v!rgb
\fi
335
\ifconditional
\c_colo_cmyk_supported
\colo_helpers_show_message
\m!colors
{
1
0
}
\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
\orelse\ifcsname
\??colorpaletspecification
#
2
\endcsname
500
\normalexpanded
{
\colo_palets_define
[#
1
][
\lastnamedcs
]
}
%
501
\fi
}
502 503
\unexpanded
\def
\colo_palets_define_b
[#
1
][#
2
][#
3
]
%
504
{
\colo_palet_prepare
{
#
1
}
%
505
\setevalue
{
\??colorpaletspecification
#
1
}{
#
2
}
%
506
\colo_palet_extend
{
#
2
}
%
507
\colo_palets_define_assign
{
#
1
}{
#
2
}{
#
3
}}
508 509
\def
\colo_palets_define_one
#
1
#
2
% get rid of { }
510
{
\ifcondition
\validassignment
{
#
2
}
% catch empty entries
511
\colo_palets_define_two
{
#
1
}
[#
2
]
%
512
\else
513
\colo_palets_define_three
{
#
1
}{
#
2
}
%
514
\fi
}
515 516
\def
\colo_palets_define_two
#
1
[#
2
=#
3
]
%
517
{
\colo_palet_extend
{
#
2
}
%
518
\colo_palets_define_set
{
#
1
}{
#
2
}{
#
3
}}
%
519 520
\def
\colo_palets_define_three
#
1
#
2
%
521
{
\ifcsname
\??colorpaletspecification
#
2
\endcsname
522
\processcommacommand
[
\lastnamedcs
]
{
\colo_palets_define_one
{
#
1
}}
%
523
\fi
}
524 525
%D Instead of refering to colors, one can also directly specify a color:
526
%D
527
%D \starttyping
528
%D \definepalet[test][xx=green]
529
%D \definepalet[test][xx={y=.4}]
530
%D \stoptyping
531 532
%D \macros
533
%D {setuppalet}
534
%D
535
%D Colors are taken from the current palet, if defined. Setting the current palet is
536
%D done by:
537
%D
538
%D \showsetup{setuppalet}
539 540
\newtoks
\everysetuppalet
541 542
\unexpanded
\def
\setuppalet
543
{
\dosingleempty
\colo_palets_setup
}
544 545
% \newtoks\t_colo_prefix % used in mp interface
546 547
\def
\colo_palets_setup
[#
1
]
%
548
{
\edef
\currentcolorpalet
{
#
1
}
%
549
\ifempty
\currentcolorpalet
550
% seems to be a reset
551
\let
\currentcolorprefix
\empty
552
%\t_colo_prefix\emptytoks
553
\orelse\ifcsname
\??paletlist
\currentcolorpalet
\endcsname
554
\edef
\currentcolorprefix
{
#
1
:
}
%
555
%\t_colo_prefix\expandafter{\currentcolorprefix}%
556
\else
557
\colo_helpers_show_message
\m!colors
7
\currentcolorpalet
558
\let
\currentcolorpalet
\empty
559
\let
\currentcolorprefix
\empty
560
%\t_colo_prefix\emptytoks
561
\fi
562
\the
\everysetuppalet
563
\colo_helpers_initialize_maintextcolor
}
564 565
%D \macros
566
%D {showpalet}
567
%D
568
%D The previous visualization was typeset with:
569
%D
570
%D \typebuffer[palet]
571
%D
572
%D This commands is defined as:
573
%D
574
%D \showsetup{showpalet}
575 576
\fetchruntimecommand
\showpalet
\f!colo_run
577 578
%D \macros
579
%D {showcolorcomponents}
580
%D
581
%D \starttyping
582
%D \showcolorcomponents[color-1,color-2]
583
%D \stoptyping
584 585
\fetchruntimecommand
\showcolorcomponents
\f!colo_run
586 587
%D \macros
588
%D {comparepalet}
589
%D
590
%D There are some more testing macros available:
591
%D
592
%D \startbuffer
593
%D \comparepalet [alfa]
594
%D \stopbuffer
595
%D
596
%D \typebuffer
597
%D
598
%D shows the palet colors against a background:
599
%D
600
%D \startlinecorrection
601
%D \getbuffer
602
%D \stoplinecorrection
603
%D
604
%D The formal definition is:
605
%D
606
%D \showsetup{comparepalet}
607 608
\fetchruntimecommand
\comparepalet
\f!colo_run
609 610
%D \macros
611
%D {showcolor}
612
%D
613
%D But let's not forget that we also have the more traditional non||related colors.
614
%D These show up after:
615
%D
616
%D \starttyping
617
%D \showcolor [name]
618
%D \stoptyping
619
%D
620
%D Where \type{name} for instance can be \type{rgb}.
621
%D
622
%D \showsetup{showcolor}
623 624
\fetchruntimecommand
\showcolor
\f!colo_run
625 626
%D It would make sense to put the following code in \type {colo-mps}, but it it
627
%D rather low level.
628 629
%D \macros
630
%D {negatecolorcomponent,negatedcolorcomponent}
631
%D
632
%D These speak for themselves. See \type {colo-ext} for usage.
633 634
\unexpanded
\def
\negatecolorcomponent
#
1
% #1 = \macro
635
{
\edef
#
1
{
\clf_negatecolorcomponent
{
#
1
}}}
636 637
\def
\negatedcolorcomponent
#
1
%
638
{
\clf_negatecolorcomponent
{
#
1
}}
639 640
%D \macros
641
%D {MPcolor}
642
%D
643
%D A very special macro is \type{\MPcolor}. This one can be used to pass a \CONTEXT\
644
%D color to \METAPOST.
645
%D
646
%D \starttyping
647
%D \MPcolor{my own red}
648
%D \stoptyping
649
%D
650
%D This macro returns \METAPOST\ code that represents the
651
%D color.
652
%D
653
%D For the moment we keep the next downward compatibility switch, i.e.\ expanded
654
%D colors. However, predefined colors and palets are no longer expanded (which is
655
%D what I wanted in the first place).
656
%D
657
%D In \MKIV\ we don't support color separation as we might now assume that printing
658
%D houses have the right programs to do it themselves. If it's ever needed in \MKIV\
659
%D It is relatively easy to support it in the backend code.
660 661
% todo: palets in definecolor
662
% todo: {\red xx} vs \red{xx}
663 664
% \def\mptexcolor#1{"\dogetattributeid\s!color \somecolorattribute{#1} A"}
665
%
666
% \startMPpage
667
% fill fullcircle scaled 10cm ;
668
% fill fullcircle scaled 5cm withprescript \mptexcolor{red} withpostscript \mptexcolor{black} ;
669
% fill fullcircle scaled 3cm ;
670
% draw btex test etex withprescript \mptexcolor{blue} ;
671
% \stopMPpage
672 673
\unexpanded
\def
\setcolormodel
[#
1
]
% % beware, \setupcolors will overload this, so this one is
674
{
\colo_helpers_set_model
{
#
1
}}
% only for local usage
675 676
\def
\colo_helpers_set_model
#
1
% direct
677
{
\edef
\currentcolormodel
{
#
1
}
%
678
\clf_setcolormodel
{
\currentcolormodel
}{
\m_colo_weight_gray
}}
% sets attribute at lua end
679 680
\colo_helpers_set_model
\s!all
681 682
\def
\colo_helpers_set_current_model
683
{
\ifconditional
\c_colo_enabled
684
\ifconditional
\c_colo_rgb_supported
685
\ifconditional
\c_colo_cmyk_supported
686
\colo_helpers_set_model
\s!all
687
\else
688
\colo_helpers_set_model
\s!rgb
689
\fi
690
\else
691
\ifconditional
\c_colo_cmyk_supported
692
\colo_helpers_set_model
\s!cmyk
693
\else
694
\ifconditional
\c_colo_convert_gray
695
\colo_helpers_set_model
\s!gray
696
\else
697
\colo_helpers_set_model
\s!none
698
\fi
699
\fi
700
\fi
701
\else
702
\ifconditional
\c_colo_convert_gray
703
\colo_helpers_set_model
\s!gray
704
\else
705
\colo_helpers_set_model
\s!none
706
\fi
707
\fi
}
708 709
%D Currently in mkiv transparency is implemented independent of color. This costs a
710
%D bit more processing time but gives the possibility to apply transparency
711
%D independently in the future. Is this useful? If not we may as well combine them
712
%D again in the future. By coupling we are downward compatible. When we decouple we
713
%D need to do more tricky housekeeping (e.g. persist color independent
714
%D transparencies when color bound ones are nil.
715 716
% Since we couple definitions, we could stick to one test. Todo. Same for mpcolor.
717 718
\def
\v_colo_dummy_name
{
c
_
o
_
l
_
o
_
r
}
719 720
\letvalue
{
\??colorattribute
\v_colo_dummy_name
}
\empty
721
\letvalue
{
\??transparencyattribute
\v_colo_dummy_name
}
\empty
722
\letvalue
{
\??colorsetter
\v_colo_dummy_name
}
\empty
723
\letvalue
{
\??transparencysetter
\v_colo_dummy_name
}
\empty
724 725
\letvalue
{
\??colorsetter
-
}
\empty
% used?
726
\letvalue
{
\??transparencysetter
-
}
\empty
% used?
727 728
% new: expandable (see tbl)
729 730
\def
\colo_helpers_fast_activate
731
{
\ifempty
\currentcolorprefix
732
\expandafter
\colo_helpers_fast_activate_nop
733
\else
734
\expandafter
\colo_helpers_fast_activate_yes
735
\fi
}
736 737
\def
\colo_helpers_fast_activate_yes
#
1
%
738
{
\ifcsname
\??colorsetter
\currentcolorprefix
#
1
\endcsname
739
\lastnamedcs
740
\begincsname
\??transparencysetter
\currentcolorprefix
#
1
\endcsname
741
\orelse\ifcsname
\??colorsetter
#
1
\endcsname
742
\lastnamedcs
743
\begincsname
\??transparencysetter
#
1
\endcsname
744
\fi
}
745 746
\def
\colo_helpers_fast_activate_nop
#
1
%
747
{
\ifcsname
\??colorsetter
#
1
\endcsname
748
\lastnamedcs
749
\begincsname
\??transparencysetter
#
1
\endcsname
750
\fi
}
751 752
\def
\colo_helpers_activate_dummy
753
{
\begincsname
\??colorsetter
\v_colo_dummy_name
\endcsname
754
\begincsname
\??transparencysetter
\v_colo_dummy_name
\endcsname
}
755 756
\let
\dofastcoloractivation
\colo_helpers_fast_activate
757 758
% so far
759 760
\def
\colo_helpers_activate
#
1
% two-step is not that much faster but less tracing
761
{
\edef
\currentcolorname
{
#
1
}
%
762
\ifempty
\currentcolorprefix
763
%\expandafter
764
\colo_helpers_activate_nop
765
\else
766
%\expandafter
767
\colo_helpers_activate_yes
768
\fi
}
769 770
\def
\colo_helpers_activate_yes
771
{
\ifcsname
\??colorsetter
\currentcolorprefix
\currentcolorname
\endcsname
772
\lastnamedcs
773
\begincsname
\??transparencysetter
\currentcolorprefix
\currentcolorname
\endcsname
774
\orelse\ifcsname
\??colorsetter
\currentcolorname
\endcsname
775
\lastnamedcs
776
\begincsname
\??transparencysetter
\currentcolorname
\endcsname
777
\fi
}
778 779
\def
\colo_helpers_activate_nop
780
{
\ifcsname
\??colorsetter
\currentcolorname
\endcsname
781
\lastnamedcs
782
\begincsname
\??transparencysetter
\currentcolorname
\endcsname
783
\fi
}
784 785
\def
\colo_helpers_activate_yes_only
786
{
\ifcsname
\??colorsetter
\currentcolorprefix
\currentcolorname
\endcsname
787
\lastnamedcs
788
\orelse\ifcsname
\??colorsetter
\currentcolorname
\endcsname
789
\lastnamedcs
790
\fi
}
791 792
\def
\colo_helpers_activate_nop_only
793
{
\ifcsname
\??colorsetter
\currentcolorname
\endcsname
794
\lastnamedcs
795
\fi
}
796 797
\let
\dousecolorparameter
\colo_helpers_activate
798 799
\unexpanded
\def
\dousecolorhashparameter
#
1
#
2
%
800
{
\ifcsname
#
1
#
2
\endcsname
801
\expandafter
\dousecolorparameter
\csname
#
1
#
2
\endcsname
802
\fi
}
803 804
\unexpanded
\def
\dousecurrentcolorparameter
805
{
\let
\currentcolorname
\currentcolorparameter
% maybe only when success
806
\ifcsname
\??colorsetter
\currentcolorprefix
\currentcolorparameter
\endcsname
807
\lastnamedcs
808
\begincsname
\??transparencysetter
\currentcolorprefix
\currentcolorparameter
\endcsname
809
\orelse\ifcsname
\??colorsetter
\currentcolorparameter
\endcsname
810
\lastnamedcs
811
\begincsname
\??transparencysetter
\currentcolorparameter
\endcsname
812
\fi
}
813 814
\let
\dosetcolorattribute
\dousecolorhashparameter
% for a while
815 816
\unexpanded
\def
\deactivatecolor
% sort of public but a bad name
817
{
\let
\currentcolorname
\s!black
818
\c_attr_color
\attributeunsetvalue
819
\c_attr_transparency
\attributeunsetvalue
}
820 821
% todo: check if color is overloading a non-color command
822 823
% \let\colo_basics_synchronize\gobbleoneargument % used in mp interface
824
% \let\colo_basics_inherit \gobbletwoarguments % used in mp interface
825 826
\def
\colo_basics_allocate
#
1
%
827
{
\expandafter
\newcount
\csname
\??colornumber
#
1
\endcsname
828
\clf_synccolorcount
{
#
1
}
\c_syst_last_allocated_count
}
829 830
\def
\colo_basics_synchronize
#
1
%
831
{
\ifcsname
\??colornumber
#
1
\endcsname\else
832
\colo_basics_allocate
{
#
1
}
%
833
\fi
834
\clf_synccolor
{
#
1
}
%
835
%\csname\??colornumber#1\endcsname\csname\??colorattribute#1\endcsname
836
\lastnamedcs\csname
\??colorattribute
#
1
\endcsname
}
837 838
\let
\colo_basics_inherit
\clf_synccolorclone
839 840
\newcount
\c_colo_protection
841 842
\unexpanded
\def
\startprotectedcolors
843
{
\advance
\c_colo_protection
\plusone
}
844 845
\unexpanded
\def
\stopprotectedcolors
846
{
\advance
\c_colo_protection
\minusone
}
847 848
\def
\colo_basics_define
[#
1
][#
2
]
%
849
{
\edef
\m_colo_old
{
#
1
}
%
850
\edef
\m_colo_new
{
#
2
}
%
851
\ifx
\m_colo_old
\m_colo_new
852
% maybe a warning
853
\else
854
\clf_defineprocesscolorlocal
{
#
1
}{
#
2
}
\v_colo_freeze_state
\relax
855
\colo_basics_synchronize
{
#
1
}
%
856
\ifcase
\c_colo_protection
857
\unexpanded\setvalue
{
#
1
}{
\colo_helpers_activate
{
#
1
}}
%
858
\fi
859
\fi
}
860 861
\def
\colo_basics_define_global
[#
1
][#
2
]
%
862
{
\edef
\m_colo_old
{
#
1
}
%
863
\edef
\m_colo_new
{
#
2
}
%
864
\ifx
\m_colo_old
\m_colo_new
865
% maybe a warning
866
\else
867
\clf_defineprocesscolorglobal
{
#
1
}{
#
2
}
\v_colo_freeze_state
\relax
868
\colo_basics_synchronize
{
#
1
}
%
869
\ifcase
\c_colo_protection
870
\unexpanded\setgvalue
{
#
1
}{
\colo_helpers_activate
{
#
1
}}
%
871
\fi
872
\fi
}
873 874
\let
\colo_basics_define_named
\colo_basics_define
875 876
\def
\dodefinefastcolor
[#
1
][#
2
]
% still not fast but ok (might change)
877
{
\clf_defineprocesscolorlocal
{
#
1
}{
#
2
}
\v_colo_freeze_state
\relax
878
\colo_basics_synchronize
{
#
1
}
%
879
\ifcase
\c_colo_protection
880
\unexpanded\setvalue
{
#
1
}{
\colo_helpers_activate
{
#
1
}}
%
881
\fi
}
882 883
\def
\colo_basics_defined_and_activated
#
1
%
884
{
\clf_defineprocesscolordummy
{
#
1
}
% we could pass dummy here too
885
\colo_basics_synchronize
{
\v_colo_dummy_name
}
%
886
\colo_helpers_activate_dummy
}
887 888
\def
\colo_basics_define_process
889
{
\ifthirdargument
890
\expandafter
\colo_basics_define_process_yes
891
\else
892
\expandafter
\colo_basics_define_process_nop
893
\fi
}
894 895
\def
\colo_basics_define_process_yes
[#
1
][#
2
][#
3
]
%
896
{
\clf_defineprocesscolorlocal
{
#
1
}{
\processcolorcomponents
{
#
2
}
,
#
3
}
\v_colo_freeze_state
\relax
897
\colo_basics_synchronize
{
#
1
}
%
898
\ifcase
\c_colo_protection
899
\unexpanded\setvalue
{
#
1
}{
\colo_helpers_activate
{
#
1
}}
%
900
\fi
}
901 902
\def
\colo_basics_define_process_nop
[#
1
][#
2
][#
3
]
%
903
{
\clf_defineprocesscolorlocal
{
#
1
}{
#
2
}
\v_colo_freeze_state
\relax
904
\colo_basics_synchronize
{
#
1
}
%
905
\ifcase
\c_colo_protection
906
\unexpanded\setvalue
{
#
1
}{
\colo_helpers_activate
{
#
1
}}
%
907
\fi
}
908 909
%D Spotcolors used setxvalue but that messes up currentcolor and probably no global
910
%D is needed either but they are global at the lua end (true argument) so we keep
911
%D that if only because spot colors often are a document wide property
912 913
\def
\colo_basics_define_spot
[#
1
][#
2
][#
3
]
%
914
{
\clf_definespotcolorglobal
{
#
1
}{
#
2
}{
#
3
}
%
915
\colo_basics_synchronize
{
#
1
}
%
916
\ifcase
\c_colo_protection
917
\unexpanded\setgvalue
{
#
1
}{
\colo_helpers_activate
{
#
1
}}
%
918
\fi
}
919 920
\def
\colo_basics_define_multitone
[#
1
][#
2
][#
3
][#
4
]
%
921
{
\clf_definemultitonecolorglobal
{
#
1
}{
#
2
}{
#
3
}{
#
4
}
%
922
\colo_basics_synchronize
{
#
1
}
%
923
\ifcase
\c_colo_protection
924
\unexpanded\setgvalue
{
#
1
}{
\colo_helpers_activate
{
#
1
}}
%
925
\fi
}
926 927
%D Transparencies (only):
928 929
\def
\colo_basics_define_transpancy
[#
1
][#
2
]
%
930
{
\clf_definetransparency
{
#
1
}{
#
2
}}
931 932
\def
\colo_basics_define_transpancy_global
[#
1
][#
2
]
%
933
{
\clf_definetransparencyglobal
{
#
1
}{
#
2
}}
934 935
% A goodie that replaces the startMPcolor hackery
936 937
% \definecolor[red-t] [r=1,t=0.5,a=1]
938
% \definecolor[green-t][g=1,t=0.5,a=1]
939
%
940
% \defineintermediatecolor[mycolora][0.5,red,green]
941
% \defineintermediatecolor[mycolorb][0.5,red-t,green-t]
942
%
943
% \definecolor[mycolorc][.5(blue,red)]
944
% \definecolor[mycolord][.5(blue)]
945
% \definecolor[mycolord][-.5(blue,red)] % complement
946
% \definecolor[mycolord][-(blue)] % complement
947
%
948
% \enabledirectives[colors.pgf]
949
% \definecolor[mycolorx][magenta!50!yellow]
950
%
951
% \starttext
952
% test {\mycolora OEPS} test
953
% test {\mycolorb OEPS} test
954
% test {\mycolorc OEPS} test
955
% test {\mycolord OEPS} test
956
% test {\mycolorx OEPS} test
957
% \stoptext
958
%
959
% Beware: if we say:
960
%
961
% \definecolor[one][two]
962
%
963
% Only color one is actually defined and two is not seen at the \LUA\ end. This
964
% means that this doesn't work:
965
%
966
% \definecolor[ColorA][red]
967
% \definecolor[ColorB][.5(ColorA)]
968
% \definecolor[ColorC][.5(ColorB,white)]
969
%
970
% But this does work:
971
%
972
% \definecolor[ColorA][1.0(red)]
973
% \definecolor[ColorB][0.5(ColorA)]
974
% \definecolor[ColorC][0.5(ColorB,white)]
975
%
976
% because the fractional definition results in a new definition.
977 978
\unexpanded
\def
\defineintermediatecolor
979
{
\dotripleempty
\colo_basics_define_intermediate
}
980 981
\def
\colo_basics_define_intermediate
[#
1
][#
2
][#
3
]
% \dotripleempty adds {} inside []
982
{
\colo_basics_define_intermediate_indeed
[#
1
][#
2
][#
3
]
}
983 984
\def
\colo_basics_define_intermediate_indeed
[#
1
][#
2
,
#
3
,
#
4
][#
5
]
%
985
{
\clf_defineintermediatecolor
% not global
986
{
#
1
}
%
987
{
#
2
}
%
988
\rawcolorattribute
{
#
3
}
%
989
\rawcolorattribute
{
#
4
}
%
990
\rawtransparencyattribute
{
#
3
}
%
991
\rawtransparencyattribute
{
#
4
}
%
992
{
#
5
}
%
993
\v_colo_freeze_state
994
\relax
995
\colo_basics_synchronize
{
#
1
}
%
996
\unexpanded\setvalue
{
#
1
}{
\colo_helpers_activate
{
#
1
}}}
997 998
%D Here is a more efficient helper for pgf:
999
%D
1000
%D \starttyping
1001
%D \startluacode
1002
%D function commands.pgfxcolorspec(ca) -- {}{}{colorspace}{list}
1003
%D local cv = attributes.colors.values[ca]
1004
%D if cv then
1005
%D local model = cv[1]
1006
%D if model == 2 then
1007
%D context("{}{}{gray}{%1.3f}",cv[2])
1008
%D elseif model == 3 then
1009
%D context("{}{}{rgb}{%1.3f,%1.3f,%1.3f}",cv[3],cv[4],cv[5])
1010
%D elseif model == 4 then
1011
%D context("{}{}{cmyk}{%1.3f,%1.3f,%1.3f,%1.3f}",cv[6],cv[7],cv[8],cv[9])
1012
%D else
1013
%D context("{}{}{gray}{%1.3f}",cv[2])
1014
%D end
1015
%D else
1016
%D context("{}{}{gray}{0}")
1017
%D end
1018
%D end
1019
%D \stopluacode
1020
%D
1021
%D \def\pgfutil@registercolor#1%
1022
%D {\setevalue{\string\color@#1}{\noexpand\xcolor@\ctxcommand{pgfxcolorspec(\thecolorattribute{#1})}}}
1023
%D
1024
%D \definecolor [darkblue] [r=0,g=0,b=0.5]
1025
%D
1026
%D \starttikzpicture
1027
%D \fill [blue] (0,0) circle(1);
1028
%D \fill [darkblue] (0,0) circle(1);
1029
%D \stoptikzpicture
1030
%D \stoptyping
1031
%D
1032
%D \stopmode
1033 1034
\def
\pgf@context@registercolor
#
1
{
\setevalue
{
\string
\color@
#
1
}{
\noexpand
\xcolor@
{}{}
\clf_pgfxcolorspec
\zerocount
\thecolorattribute
{
#
1
}}}
1035
\def
\pgf@context@registergray
#
1
{
\setevalue
{
\string
\color@
#
1
}{
\noexpand
\xcolor@
{}{}
\clf_pgfxcolorspec
\plustwo
\thecolorattribute
{
#
1
}}}
1036
\def
\pgf@context@registerrgb
#
1
{
\setevalue
{
\string
\color@
#
1
}{
\noexpand
\xcolor@
{}{}
\clf_pgfxcolorspec
\plusthree
\thecolorattribute
{
#
1
}}}
1037
\def
\pgf@context@registercmyk
#
1
{
\setevalue
{
\string
\color@
#
1
}{
\noexpand
\xcolor@
{}{}
\clf_pgfxcolorspec
\plusfour
\thecolorattribute
{
#
1
}}}
1038 1039
%D \starttyping
1040
%D \ifdefined\pgf@context@registercolor
1041
%D \let\pgfutil@registercolor\pgf@context@registercolor
1042
%D \fi
1043
%D \stoptyping
1044 1045
%D \macros
1046
%D {doifcolorelse, doifcolor}
1047
%D
1048
%D Switching to a color is done by means of the following command. Later on we will
1049
%D explain the use of palets. We define ourselves a color conditional first.
1050 1051
\def
\doifelsecolor
#
1
%
1052
{
\ifcsname
\??colorattribute
\currentcolorprefix
#
1
\endcsname
1053
\expandafter
\firstoftwoarguments
1054
\orelse\ifcsname
\??colorattribute
#
1
\endcsname
1055
\expandafter
\firstoftwoarguments
1056
\else
1057
\expandafter
\secondoftwoarguments
1058
\fi
}
1059 1060
\let
\doifcolorelse\doifelsecolor
1061 1062
\def
\doifcolor
#
1
%
1063
{
\ifcsname
\??colorattribute
\currentcolorprefix
#
1
\endcsname
1064
\expandafter
\firstofoneargument
1065
\orelse\ifcsname
\??colorattribute
#
1
\endcsname
1066
\expandafter
\firstofoneargument
1067
\else
1068
\expandafter
\gobbleoneargument
1069
\fi
}
1070 1071
%D \macros
1072
%D {startregistercolor,stopregistercolor,permitcolormode}
1073
%D
1074
%D If you only want to register a color, the switch \type {\ifpermitcolormode} can
1075
%D be used. That way the nested colors know where to go back to.
1076
%D
1077
%D We use these macros for implementing text colors (actually, the first application
1078
%D was in foreground colors).
1079
%D
1080
%D \starttyping
1081
%D \starttextcolor[red]
1082
%D \dorecurse{10}{\input tufte \color[green]{oeps} \par}
1083
%D \stoptextcolor
1084
%D \stoptyping
1085
%D
1086
%D This is more efficient than the alternative:
1087
%D
1088
%D \starttyping
1089
%D \setupbackgrounds[text][foregroundcolor=red]
1090
%D \startregistercolor[red]
1091
%D \dorecurse{10}{\input tufte \color[green]{oeps} \par}
1092
%D \stopregistercolor
1093
%D \stoptyping
1094 1095
\let
\maintextcolor
\empty
1096
\def
\defaulttextcolor
{
black
}
1097
\def
\s!themaintextcolor
{
themaintextcolor
}
1098 1099
\unexpanded
\def
\inheritmaintextcolor
1100
{
\ifempty
\maintextcolor
\else
\colo_helpers_activate
\maintextcolor
\fi
}
1101 1102
\unexpanded
\def
\onlyinheritmaintextcolor
1103
{
\ifempty
\maintextcolor
1104
\deactivatecolor
1105
\else
1106
\colo_helpers_activate
\maintextcolor
1107
\fi
}
1108 1109
\appendtoks
1110
\deactivatecolor
% public?
1111
\inheritmaintextcolor
1112
\to
\everybeforeoutput
1113 1114
\def
\colo_helpers_switch_to_maintextcolor
#
1
%
1115
{
\let
\maintextcolor
\s!themaintextcolor
1116
\definecolor
[
\maintextcolor
][#
1
]
% can be fast one
1117
\colo_helpers_activate
\maintextcolor
1118
\clf_registermaintextcolor
\thecolorattribute
\maintextcolor
\relax
}
1119 1120
\unexpanded
\def
\starttextcolor
[#
1
]
%
1121
{
\doifsomething
{
#
1
}
1122
{
\colo_helpers_switch_to_maintextcolor
{
#
1
}}}
1123 1124
\let
\stoptextcolor
\relax
1125 1126
\let
\p_colo_textcolor
\empty
1127 1128
\def
\colo_helpers_initialize_maintextcolor
1129
{
\edef
\p_colo_textcolor
{
\directcolorsparameter
\c!textcolor
}
%
1130
\ifempty
\p_colo_textcolor
1131
\colo_helpers_switch_to_maintextcolor
\defaulttextcolor
1132
\else
1133
\colo_helpers_switch_to_maintextcolor
\p_colo_textcolor
1134
\fi
}
1135 1136
\appendtoks
\colo_helpers_initialize_maintextcolor
\to
\everyjob
1137
\appendtoks
\colo_helpers_initialize_maintextcolor
\to
\everysetupcolors
1138 1139
\letvalue
{
\??colorsetter
}
\empty
\letvalue
{
\??colorattribute
}
\!!zerocount
1140
\letvalue
{
\??transparencysetter
}
\empty
\letvalue
{
\??transparencyattribute
}
\!!zerocount
1141 1142
\def
\colo_helpers_inherited_direct_cs
#
1
{
\ifcsname
\??colorsetter
#
1
\endcsname\lastnamedcs\fi
}
1143
\def
\colo_helpers_inherited_direct_ca
#
1
{
\ifcsname
\??colorattribute
#
1
\endcsname\lastnamedcs\else
\!!zerocount
\fi
}
1144
\def
\colo_helpers_inherited_direct_ts
#
1
{
\ifcsname
\??transparencysetter
#
1
\endcsname\lastnamedcs\fi
}
1145
\def
\colo_helpers_inherited_direct_ta
#
1
{
\ifcsname
\??transparencyattribute
#
1
\endcsname\lastnamedcs\else
\!!zerocount
\fi
}
1146 1147
% %def\colo_helpers_inherited_palet_cs#1#2{\csname\??colorsetter \ifcsname\??colorsetter \??colorpalet#1:#2\endcsname\??colorpalet#1:#2\fi\endcsname}
1148
% %def\colo_helpers_inherited_palet_ca#1#2{\csname\??colorattribute \ifcsname\??colorattribute \??colorpalet#1:#2\endcsname\??colorpalet#1:#2\fi\endcsname}
1149
% %def\colo_helpers_inherited_palet_ts#1#2{\csname\??transparencysetter \ifcsname\??transparencysetter \??colorpalet#1:#2\endcsname\??colorpalet#1:#2\fi\endcsname}
1150
% %def\colo_helpers_inherited_palet_ta#1#2{\csname\??transparencyattribute\ifcsname\??transparencyattribute\??colorpalet#1:#2\endcsname\??colorpalet#1:#2\fi\endcsname}
1151
%
1152
% \def\colo_helpers_inherited_palet_cs#1#2{\ifcsname\??colorsetter \??colorpalet#1:#2\endcsname\lastnamedcs\fi}
1153
% \def\colo_helpers_inherited_palet_ca#1#2{\ifcsname\??colorattribute \??colorpalet#1:#2\endcsname\lastnamedcs\else\!!zerocount\fi}
1154
% \def\colo_helpers_inherited_palet_ts#1#2{\ifcsname\??transparencysetter \??colorpalet#1:#2\endcsname\lastnamedcs}
1155
% \def\colo_helpers_inherited_palet_ta#1#2{\ifcsname\??transparencyattribute\??colorpalet#1:#2\endcsname\lastnamedcs\else\!!zerocount\fi}
1156 1157
\let
\colo_helpers_set_value
\setvalue
1158 1159
\appendtoks
1160
\ifconditional
\c_colo_expanded
1161
\let
\colo_helpers_set_value
\setevalue
1162
\else
1163
\let
\colo_helpers_set_value
\setvalue
1164
\fi
1165
\to
\everysetupcolors
1166 1167
\def
\colo_palets_define_set
#
1
#
2
#
3
%
1168
{
\ifcondition
\validassignment
{
#
3
}
% \definepalet[test][xx={y=.4}]
1169
\expandafter
\colo_palets_define_assign
1170
\orelse\ifcsname
\??colorsetter
#
3
\endcsname
1171
% \definepalet[test][xx=green]
1172
\expandafter
\colo_palets_define_inherit
1173
\else
1174
% not entered when making format
1175
\expandafter
\colo_palets_define_undefine
1176
\fi
1177
{
#
1
}{
#
2
}{
#
3
}}
1178 1179
\def
\colo_palets_define_inherit
#
1
#
2
#
3
%
1180
{
\colo_basics_inherit
{
#
1
:
#
2
}{
#
3
}
%
1181
\colo_helpers_set_value
{
\??colorsetter
#
1
:
#
2
}{
\colo_helpers_inherited_direct_cs
{
#
3
}}
%
1182
\colo_helpers_set_value
{
\??colorattribute
#
1
:
#
2
}{
\colo_helpers_inherited_direct_ca
{
#
3
}}
%
1183
\colo_helpers_set_value
{
\??transparencysetter
#
1
:
#
2
}{
\colo_helpers_inherited_direct_ts
{
#
3
}}
%
1184
\colo_helpers_set_value
{
\??transparencyattribute
#
1
:
#
2
}{
\colo_helpers_inherited_direct_ta
{
#
3
}}}
1185 1186
\def
\colo_palets_define_undefine
#
1
#
2
#
3
%
1187
{
\localundefine
{
\??colorsetter
#
1
:
#
2
}
%
1188
\localundefine
{
\??colorattribute
#
1
:
#
2
}
%
1189
\localundefine
{
\??transparencysetter
#
1
:
#
2
}
%
1190
\localundefine
{
\??transparencyattribute
#
1
:
#
2
}}
1191 1192
\def
\colo_palets_define_assign
#
1
#
2
#
3
%
1193
{
\definecolor
[
\??colorpalet
#
1
:
#
2
][#
3
]
%
1194
\colo_helpers_set_value
{
\??colorsetter
#
1
:
#
2
}{
\colo_helpers_inherited_direct_cs
{
\??colorpalet
#
1
:
#
2
}}
%
1195
\colo_helpers_set_value
{
\??colorattribute
#
1
:
#
2
}{
\colo_helpers_inherited_direct_ca
{
\??colorpalet
#
1
:
#
2
}}
%
1196
\colo_helpers_set_value
{
\??transparencysetter
#
1
:
#
2
}{
\colo_helpers_inherited_direct_ts
{
\??colorpalet
#
1
:
#
2
}}
%
1197
\colo_helpers_set_value
{
\??transparencyattribute
#
1
:
#
2
}{
\colo_helpers_inherited_direct_ta
{
\??colorpalet
#
1
:
#
2
}}}
1198 1199
\setvalue
{
\??colorattribute
currentcolor
}{
\the
\c_attr_color
}
% for mpcolor
1200
\setvalue
{
\??transparencyattribute
currentcolor
}{
\the
\c_attr_transparency
}
% for mpcolor
1201 1202
%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}
1203
%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}
1204
%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}
1205
%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}
1206 1207
\def
\colo_helpers_inherited_current_ca
#
1
{
\ifcsname
\??colorattribute
\currentcolorprefix
#
1
\endcsname\lastnamedcs\else\ifcsname
\??colorattribute
#
1
\endcsname\lastnamedcs\else
\!!zerocount
\fi\fi
}
1208
\def
\colo_helpers_inherited_current_cs
#
1
{
\ifcsname
\??colorsetter
\currentcolorprefix
#
1
\endcsname\lastnamedcs\else\ifcsname
\??colorsetter
#
1
\endcsname\lastnamedcs\else\fi\fi
}
1209
\def
\colo_helpers_inherited_current_ta
#
1
{
\ifcsname
\??transparencyattribute
\currentcolorprefix
#
1
\endcsname\lastnamedcs\else\ifcsname
\??transparencyattribute
#
1
\endcsname\lastnamedcs\else
\!!zerocount
\fi\fi
}
1210
\def
\colo_helpers_inherited_current_ts
#
1
{
\ifcsname
\??transparencysetter
\currentcolorprefix
#
1
\endcsname\lastnamedcs\else\ifcsname
\??transparencysetter
#
1
\endcsname\lastnamedcs\else\fi\fi
}
1211 1212
%D Low level defs:
1213 1214
\unexpanded
\def
\colordefalc
#
1
#
2
{
\setevalue
{
\??colorattribute
#
1
}{
#
2
}
\setvalue
{
\??colorsetter
#
1
}{
\c_attr_color
#
2
}}
1215
\unexpanded
\def
\colordefagc
#
1
#
2
{
\setxvalue
{
\??colorattribute
#
1
}{
#
2
}
\setgvalue
{
\??colorsetter
#
1
}{
\c_attr_color
#
2
}}
% was not g
1216
\unexpanded
\def
\colordefalt
#
1
#
2
{
\setevalue
{
\??transparencyattribute
#
1
}{
#
2
}
\setvalue
{
\??transparencysetter
#
1
}{
\c_attr_transparency
#
2
}}
1217
\unexpanded
\def
\colordefagt
#
1
#
2
{
\setxvalue
{
\??transparencyattribute
#
1
}{
#
2
}
\setgvalue
{
\??transparencysetter
#
1
}{
\c_attr_transparency
#
2
}}
1218 1219
\unexpanded
\def
\colordefflc
#
1
#
2
{
\setvalue
{
\??colorattribute
#
1
}{
\colo_helpers_inherited_current_ca
{
#
2
}}
\setvalue
{
\??colorsetter
#
1
}{
\colo_helpers_inherited_current_cs
{
#
2
}}}
1220
\unexpanded
\def
\colordeffgc
#
1
#
2
{
\setgvalue
{
\??colorattribute
#
1
}{
\colo_helpers_inherited_current_ca
{
#
2
}}
\setvalue
{
\??colorsetter
#
1
}{
\colo_helpers_inherited_current_cs
{
#
2
}}}
1221
\unexpanded
\def
\colordefflt
#
1
#
2
{
\setvalue
{
\??transparencyattribute
#
1
}{
\colo_helpers_inherited_current_ta
{
#
2
}}
\setvalue
{
\??transparencysetter
#
1
}{
\colo_helpers_inherited_current_ts
{
#
2
}}}
1222
\unexpanded
\def
\colordeffgt
#
1
#
2
{
\setgvalue
{
\??transparencyattribute
#
1
}{
\colo_helpers_inherited_current_ta
{
#
2
}}
\setgvalue
{
\??transparencysetter
#
1
}{
\colo_helpers_inherited_current_ts
{
#
2
}}}
1223 1224
\unexpanded
\def
\colordefrlc
#
1
{
\localundefine
{
\??colorattribute
#
1
}
\localundefine
{
\??colorsetter
#
1
}}
1225
\unexpanded
\def
\colordefrgc
#
1
{
\globalundefine
{
\??colorattribute
#
1
}
\globalundefine
{
\??colorsetter
#
1
}}
1226
\unexpanded
\def
\colordefrlt
#
1
{
\localundefine
{
\??transparencyattribute
#
1
}
\localundefine
{
\??transparencysetter
#
1
}}
1227
\unexpanded
\def
\colordefrgt
#
1
{
\globalundefine
{
\??transparencyattribute
#
1
}
\globalundefine
{
\??transparencysetter
#
1
}}
1228 1229
%D \macros
1230
%D {colorvalue, grayvalue}
1231
%D
1232
%D We can typeset the color components using \type {\colorvalue} and \type
1233
%D {\grayvalue}. The commands:
1234
%D
1235
%D \startbuffer
1236
%D color value of SomeKindOfRed: \colorvalue{SomeKindOfRed} \crlf
1237
%D gray value of SomeKindOfRed: \grayvalue{SomeKindOfRed}
1238
%D \stopbuffer
1239
%D
1240
%D \typebuffer
1241
%D
1242
%D show us:
1243
%D
1244
%D \startexample
1245
%D \getbuffer
1246
%D \stopexample
1247 1248
\let
\currentcolorname
\s!black
% todo
1249
\let
\outercolorname
\s!black
% todo
1250 1251
\let
\colorformatseparator
\space
1252 1253
\def
\MPcolor
#
1
%
1254
{
\clf_mpcolor
1255
\c_attr_colormodel
1256
\colo_helpers_inherited_current_ca
{
#
1
}
%
1257
\colo_helpers_inherited_current_ta
{
#
1
}
}
1258 1259
\def
\MPcoloronly
#
1
%
1260
{
\clf_mpcolor
1261
\c_attr_colormodel
1262
\colo_helpers_inherited_current_ca
{
#
1
}
%
1263
\zerocount
}
1264 1265
\def
\MPtransparency
#
1
%
1266
{
\clf_mpcolor
1267
\zerocount
1268
\zerocount
1269
\colo_helpers_inherited_current_ta
{
#
1
}
}
1270 1271
\def
\MPoptions
#
1
%
1272
{
\clf_mpoptions
1273
\c_attr_colormodel
1274
\colo_helpers_inherited_current_ca
{
#
1
}
%
1275
\colo_helpers_inherited_current_ta
{
#
1
}
}
1276 1277
\def
\thecolormodelattribute
{
\the
\c_attr_colormodel
}
1278 1279
%def\thecolorattribute #1{\number\csname\??colorattribute \ifcsname\??colorattribute \currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??colorattribute #1\endcsname#1\fi\fi\endcsname}
1280
%def\thetransparencyattribute#1{\number\csname\??transparencyattribute\ifcsname\??transparencyattribute\currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??transparencyattribute#1\endcsname#1\fi\fi\endcsname}
1281 1282
\def
\rawcolorattribute
#
1
{
\ifcsname
\??colorattribute
\currentcolorprefix
#
1
\endcsname\lastnamedcs\orelse\ifcsname
\??colorattribute
#
1
\endcsname\lastnamedcs\else
\zerocount
\fi
}
1283
\def
\rawtransparencyattribute
#
1
{
\ifcsname
\??transparencyattribute
\currentcolorprefix
#
1
\endcsname\lastnamedcs\orelse\ifcsname
\??transparencyattribute
#
1
\endcsname\lastnamedcs\else
\zerocount
\fi
}
1284 1285
\def
\thecolorattribute
#
1
{
\number\ifcsname
\??colorattribute
\currentcolorprefix
#
1
\endcsname\lastnamedcs\orelse\ifcsname
\??colorattribute
#
1
\endcsname\lastnamedcs\else
\zerocount
\fi
}
1286
\def
\thetransparencyattribute
#
1
{
\number\ifcsname
\??transparencyattribute
\currentcolorprefix
#
1
\endcsname\lastnamedcs\orelse\ifcsname
\??transparencyattribute
#
1
\endcsname\lastnamedcs\else
\zerocount
\fi
}
1287
\def
\internalspotcolorname
#
1
{
\clf_spotcolorname
\thecolorattribute
{
#
1
}
}
1288
\def
\internalspotcolorparent
#
1
{
\clf_spotcolorparent
\thecolorattribute
{
#
1
}
}
1289
\def
\internalspotcolorsize
#
1
{
\clf_spotcolorvalue
\thecolorattribute
{
#
1
}
}
1290 1291
\def
\colorcomponents
#
1
{
\clf_colorcomponents
\thecolorattribute
{
#
1
}
}
1292
\def
\transparencycomponents
#
1
{
\clf_transparencycomponents
\thetransparencyattribute
{
#
1
}
}
1293
\def
\processcolorcomponents
#
1
{
\clf_processcolorcomponents
\thecolorattribute
{
#
1
}
}
1294 1295
\def
\colorvalue
#
1
{
\clf_formatcolor
\thecolorattribute
{
#
1
}{
\colorformatseparator
}}
1296
\def
\grayvalue
#
1
{
\clf_formatgray
\thecolorattribute
{
#
1
}{
\colorformatseparator
}}
1297 1298
\def
\doifelseblack
#
1
{
\clf_doifelseblack
\thecolorattribute
{
#
1
}
}
1299
\def
\doifelsedrawingblack
{
\clf_doifelsedrawingblack
}
1300 1301
\let
\doifblackelse
\doifelseblack
1302
\let
\doifdrawingblackelse
\doifelsedrawingblack
1303 1304
\let
\doifblackelse
\doifelseblack
1305
\let
\doifdrawingblackelse\doifelsedrawingblack
1306 1307
%D \macros
1308
%D {forcecolorhack}
1309
%D
1310
%D We can out this in front of (for instance) a special and so force color to be
1311
%D applied (only glyphs, rules and leaders are handled).
1312
%D
1313
%D \startbuffer
1314
%D \framed
1315
%D [background=color,backgroundcolor=yellow,framecolor=red,corner=round]
1316
%D {test}
1317
%D \stopbuffer
1318
%D
1319
%D \typebuffer \getbuffer
1320 1321
% ignores in attribute handler
1322
%
1323
% \def\forcecolorhack{\vrule\s!width\zeropoint\s!height\zeropoint\s!depth\zeropoint}
1324 1325
% \normal added else fails in metafun manual (leaders do a hard scan)
1326 1327
% \unexpanded\def\forcecolorhack{\leaders\hrule\hskip\zeropoint\relax} % relax is needed !
1328
%
1329
% I really need to sort this out!
1330 1331
\unexpanded
\def
\forcecolorhack
{
\leaders\hrule
height
\zeropoint
depth
\zeropoint
\hskip
\zeropoint
\relax
}
% relax is needed !
1332 1333
%D We default to the colors defined in \type {colo-imp-rgb} and
1334
%D support both \RGB\ and \CMYK\ output. Transparencies are defined
1335
%D here:
1336 1337
\definecolor
[
black
][
s
=
0
]
1338
\definecolor
[
white
][
s
=
1
]
1339 1340
\definetransparency
[
none
]
[
0
]
1341
\definetransparency
[
normal
]
[
1
]
1342
\definetransparency
[
multiply
]
[
2
]
1343
\definetransparency
[
screen
]
[
3
]
1344
\definetransparency
[
overlay
]
[
4
]
1345
\definetransparency
[
softlight
]
[
5
]
1346
\definetransparency
[
hardlight
]
[
6
]
1347
\definetransparency
[
colordodge
]
[
7
]
1348
\definetransparency
[
colorburn
]
[
8
]
1349
\definetransparency
[
darken
]
[
9
]
1350
\definetransparency
[
lighten
]
[
1
0
]
1351
\definetransparency
[
difference
]
[
1
1
]
1352
\definetransparency
[
exclusion
]
[
1
2
]
1353
\definetransparency
[
hue
]
[
1
3
]
1354
\definetransparency
[
saturation
]
[
1
4
]
1355
\definetransparency
[
color
]
[
1
5
]
1356
\definetransparency
[
luminosity
]
[
1
6
]
1357 1358
%D Some common ones:
1359 1360
\definecolor
[
trace
:
0
][
s
=
.
4
]
1361
\definecolor
[
trace
:
1
][
r
=
.
6
]
1362
\definecolor
[
trace
:
2
][
g
=
.
6
]
1363
\definecolor
[
trace
:
3
][
b
=
.
6
]
1364
\definecolor
[
trace
:
4
][
r
=
.
6
,
g
=
.
6
]
1365
\definecolor
[
trace
:
5
][
r
=
.
6
,
b
=
.
6
]
1366
\definecolor
[
trace
:
6
][
g
=
.
6
,
b
=
.
6
]
1367
\definecolor
[
trace
:
7
][
r
=
.
8
,
g
=
.
4
]
1368
\definecolor
[
trace
:
8
][
r
=
.
8
,
b
=
.
4
]
1369
\definecolor
[
trace
:
9
][
g
=
.
4
,
b
=
.
8
]
1370 1371
\definecolor
[
trace
:
w
][
s
=
1
]
1372
\definecolor
[
trace
:
r
][
r
=
.
7
5
,
t
=
.
5
,
a
=
1
]
1373
\definecolor
[
trace
:
g
][
g
=
.
7
5
,
t
=
.
5
,
a
=
1
]
1374
\definecolor
[
trace
:
b
][
b
=
.
7
5
,
t
=
.
5
,
a
=
1
]
1375
%definecolor[trace:c][c=.75,t=.5,a=1]
1376
%definecolor[trace:m][m=.75,t=.5,a=1]
1377
%definecolor[trace:y][y=.75,t=.5,a=1]
1378
\definecolor
[
trace
:
c
][
g
=
.
7
5
,
b
=
.
7
5
,
t
=
.
5
,
a
=
1
]
1379
\definecolor
[
trace
:
m
][
r
=
.
7
5
,
b
=
.
7
5
,
t
=
.
5
,
a
=
1
]
1380
\definecolor
[
trace
:
y
][
r
=
.
7
5
,
g
=
.
7
5
,
t
=
.
5
,
a
=
1
]
1381
\definecolor
[
trace
:
s
][
s
=
.
7
5
,
t
=
.
5
,
a
=
1
]
1382
\definecolor
[
trace
:
d
][
s
=
.
2
5
,
t
=
.
5
,
a
=
1
]
1383
\definecolor
[
trace
:
o
][
r
=
1
,
g
=
.
6
,
b
=
.
1
,
t
=
.
5
,
a
=
1
]
1384 1385
\definecolor
[
trace
:
dw
][
s
=
1
]
1386
\definecolor
[
trace
:
dr
][
r
=
.
7
5
,
t
=
.
7
5
,
a
=
1
]
1387
\definecolor
[
trace
:
dg
][
g
=
.
7
5
,
t
=
.
7
5
,
a
=
1
]
1388
\definecolor
[
trace
:
db
][
b
=
.
7
5
,
t
=
.
7
5
,
a
=
1
]
1389
%definecolor[trace:dc][c=.75,t=.75,a=1]
1390
%definecolor[trace:dm][m=.75,t=.75,a=1]
1391
%definecolor[trace:dy][y=.75,t=.75,a=1]
1392
\definecolor
[
trace
:
dc
][
g
=
.
7
5
,
b
=
.
7
5
,
t
=
.
7
5
,
a
=
1
]
1393
\definecolor
[
trace
:
dm
][
r
=
.
7
5
,
b
=
.
7
5
,
t
=
.
7
5
,
a
=
1
]
1394
\definecolor
[
trace
:
dy
][
r
=
.
7
5
,
g
=
.
7
5
,
t
=
.
7
5
,
a
=
1
]
1395
\definecolor
[
trace
:
ds
][
s
=
.
7
5
,
t
=
.
7
5
,
a
=
1
]
1396
\definecolor
[
trace
:
dd
][
s
=
.
2
5
,
t
=
.
7
5
,
a
=
1
]
1397
\definecolor
[
trace
:
do
][
r
=
1
,
g
=
.
6
,
b
=
.
1
,
t
=
.
7
5
,
a
=
1
]
1398 1399
\setupcolors
1400
[
\c!state
=
\v!stop
,
% color will be enabled later on
1401
\c!conversion
=
\v!yes
,
1402
\c!rgb
=
\v!yes
,
1403
\c!cmyk
=
\v!yes
,
1404
\c!spot
=
\v!yes
,
1405
\c!pagecolormodel
=
\v!none
,
1406
\c!expansion
=
\v!no
,
1407
\c!textcolor
=
,
1408
\c!factor
=
\v!yes
]
1409 1410
\setupcolor
1411
[
\v!rgb
]
1412 1413
\protect
\endinput
1414