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