summaryrefslogtreecommitdiff
path: root/tex/context/base/attr-col.mkiv
blob: 5dc0e477e2050eb6980ec88c9f1430aeb184c468 (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
%D \module
%D   [       file=attr-col,
%D        version=2007.06.06,
%D          title=\CONTEXT\ Attribute Macros,
%D       subtitle=Color,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=PRAGMA-ADE]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

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

\registerctxluafile{attr-col}{1.001}

\unprotect

% todo: no need for 'color' argument, we can set that once at startup; currently
% a bit inconsistent

% 1=off  2=gray  3=spot  4=rgb  5=cmyk  6=cmy % only 1/2/4/5 are supported
%
% We could combine this in one attribute but this is not faster and also
% less flexible because sometimes we want to freeze the attribute bit.
%
% Watch out: real color support will be implemented later.

\newcount\currentcolormodel

\def\dosetcolormodel#1%
  {\currentcolormodel\ctxlua{tex.print(_clib_.setmodel('#1'))}%
   \attribute\colormodelattribute\currentcolormodel}

\dosetcolormodel{all}

\appendtoks
    \dosetcolormodel{all}% redundant?
\to \everyjob

\def\registerrgbcolor   #1#2#3#4{\ctxlua{_clib_.register('#1','rgb' ,#2,#3,#4)}}
\def\registercmykcolor#1#2#3#4#5{\ctxlua{_clib_.register('#1','cmyk',#2,#3,#4,#5)}}
\def\registergraycolor      #1#2{\ctxlua{_clib_.register('#1','gray',#2)}}

% transparency

\def\registertransparency#1#2#3%
  {\setevalue{(ts:#1)}{\attribute\transparencyattribute\ctxlua{tex.write(_tlib_.register(#2,#3))} }}

\def\sometransparencyswitch#1{\csname(ts:#1)\endcsname}

\def\sometransparencyswitch
  {\ctxlua{_tlib_.enable()}%
   \gdef\sometransparencyswitch##1{\csname(ts:##1)\endcsname}%
   \sometransparencyswitch}

% \registertransparency {one} {1} {.5}
% \registertransparency {two} {1} {.6}

% overprint

\def\registercolorintent#1#2%
  {\setevalue{(os:#1)}{\attribute\colorintentattribute\ctxlua{tex.write(attributes.colorintents.register('#2'))} }}

\def\dotriggercolorintent
  {\ctxlua{attributes.colorintents.enable()}%
   \gdef\dotriggercolorintent##1{\csname(os:##1)\endcsname}%
   \dotriggercolorintent}

\registercolorintent{knockout} {knockout}
\registercolorintent{overprint}{overprint}

\installattributestack\colorintentattribute

\setevalue{(os:#\v!none}{\attribute\colorintentattribute\attributeunsetvalue} % does this work out ok?

\protect \endinput

% test case
%
% {\green \hbox to \hsize{\leaders\hrule  \hfill a}\par}
% {\red   \hbox to \hsize{\leaders\hbox{x}\hfill a}\par}