colo-ext.mkxl /size: 3207 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=colo-ext, % mostof thsi code used to be in colo-ini.tex
3%D        version=1997.04.01,
4%D          title=\CONTEXT\ Color Macros,
5%D       subtitle=Extras,
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\writestatus{loading}{ConTeXt Color Macros / Extras}
15
16\unprotect
17
18%D \macros
19%D   {negatecolorcomponent, negativecolorbox}
20%D
21%D Sometimes, especially when we deal with typesetting devices, we want to reverse
22%D the color scheme. Instead of recalculating all those colors, we use a quick and
23%D dirty approach:
24%D
25%D \starttyping
26%D \negativecolorbox0
27%D \stoptyping
28%D
29%D will negate the colors in box zero.
30
31\permanent\protected\def\negatecolorbox#1% or just set attr of #1
32  {\setbox#1\hpack to \wd#1%
33     {\scratchdimen\wd#1\relax
34      \startnegative % might change
35      \blackrule[\c!color=\s!white,\c!height=\ht#1,\c!depth=\dp#1,\c!width=\scratchdimen]%
36      \hskip-\scratchdimen
37      \leaders\box#1\hfill% this triggers application to the box .. a real dirty hack!
38      \stopnegative}}
39
40%D There are in principle two ways to handle overprint: bound to colors or
41%D independent. For the moment we only support independent overprint handling. Here
42%D we deal with a per-document setting.
43
44%D We can move the stack and attribute setting to the \LUA\ end.
45
46\installcorenamespace{colorintent}
47
48\permanent\protected\def\registercolorintent#1#2% \relax is needed !
49  {\edefcsname\??colorintent#1\endcsname{\c_attr_colorintent\clf_registercolorintent{#2}\relax}}
50
51\protected\def\colo_intents_set
52  {\clf_enablecolorintents
53   \protected\gdef\colo_intents_set##1{\csname\??colorintent##1\endcsname}%
54   \colo_intents_set}
55
56\registercolorintent{knockout} {knockout}
57\registercolorintent{overprint}{overprint}
58
59\installattributestack\colorintentattribute
60
61\edefcsname\??colorintent\v!none\endcsname{\c_attr_colorintent\attributeunsetvalue} % or reset? used at all?
62
63\permanent\protected\def\startcolorintent[#1]%
64  {\pushattribute\colorintentattribute
65   \colo_intents_set{#1}}
66
67\permanent\protected\def\stopcolorintent
68  {\popattribute\colorintentattribute}
69
70\permanent\protected\def\startoverprint{\startcolorintent[\v!overprint]}
71\permanent\protected\def\startknockout {\startcolorintent[\v!knockout ]}
72
73\aliased\let\stopoverprint\stopcolorintent
74\aliased\let\stopknockout \stopcolorintent
75
76\permanent\protected\lettonothing\starttextcolorintent
77\permanent\protected\lettonothing\stoptextcolorintent
78
79\appendtoks
80    \colo_intents_set_text
81\to \everysetupcolors
82
83\lettonothing\p_colo_intent
84
85\def\colo_intents_set_text
86  {\edef\p_colo_intent{\colorsparameter\c!intent}%
87   \ifx\p_colo_intent\v!none \else
88     \enforced\protected\xdef\starttextcolorintent{\colo_intents_set{\p_colo_intent}}%
89     \glet\colo_intents_set_text\relax
90     \colo_intents_set\p_colo_intent
91   \fi}
92
93\appendtoks \starttextcolorintent \to \everystarttextproperties
94\appendtoks \stoptextcolorintent  \to \everystoptextproperties
95
96\setupcolors
97  [\c!intent=\v!none]
98
99\protect \endinput
100