summaryrefslogtreecommitdiff
path: root/tex/context/base/attr-ini.mkiv
blob: 578d02c27726d5ba9ddf3fde8cce66032206c551 (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
84
85
86
87
88
89
90
91
92
93
94
95
%D \module
%D   [       file=attr-ini,
%D        version=2007.06.06,
%D          title=\CONTEXT\ Attribute Macros,
%D       subtitle=Initialization,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%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 / Initialization}

%D Although it's still somewhat experimental, here we introduce code
%D related to attributes. Housekeeping will move completely to Lua
%D and \newattribute will go away.

\unprotect

\registerctxluafile{attr-ini}{1.001}

\def\pushattribute#1%
  {\global\advance\csname\??ae:\string#1\endcsname\plusone
   \global\expandafter\mathchardef\csname\??ae:\string#1:\number\csname\??ae:\string#1\endcsname\endcsname\attribute#1}

\def\popattribute#1%
  {\attribute#1\csname\??ae:\string#1:\number\csname\??ae:\string#1\endcsname\endcsname
   \global\advance\csname\??ae:\string#1\endcsname\minusone}

\def\installattributestack#1%
  {\expandafter\newcount\csname\??ae:\string#1\endcsname}

\newtoks \attributesresetlist

\ifdefined \s!global \else \def\s!global{global} \fi % for metatex % or hard check later
\ifdefined \s!public \else \def\s!public{public} \fi % for metatex % or hard check later

\unexpanded\def\defineattribute
  {\dodoubleempty\dodefineattribute}

\def\dodefineattribute[#1][#2]% alternatively we can let lua do the housekeeping
  {\expandafter\newattribute\csname @attr@#1\endcsname
   \expandafter\newconstant \csname :attr:#1\endcsname
   \csname :attr:#1\endcsname\lastallocatedattribute
   \ctxcommand{defineattribute("#1",\number\lastallocatedattribute)}%
  %\writestatus\m!system{defining attribute #1 with number \number\lastallocatedattribute}%
   \doifnotinset\s!global{#2}{\appendetoks\csname @attr@#1\endcsname\attributeunsetvalue\to\attributesresetlist}%
   \doifinset   \s!public{#2}{\expandafter\let\csname#1attribute\expandafter\endcsname\csname :attr:#1\endcsname}}

\unexpanded\def\definesystemattribute
  {\dodoubleempty\dodefinesystemattribute}

\def\dodefinesystemattribute[#1][#2]% alternatively we can let lua do the housekeeping
  {\scratchcounter\ctxcommand{getprivateattribute("#1")}\relax
   \expandafter\attributedef\csname @attr@#1\endcsname\scratchcounter
   \expandafter\newconstant \csname :attr:#1\endcsname
   \csname :attr:#1\endcsname\scratchcounter
  %\writestatus\m!system{defining system attribute #1 with number \number\scratchcounter}%
   \doifnotinset\s!global{#2}{\appendetoks\csname @attr@#1\endcsname\attributeunsetvalue\to\attributesresetlist}%
   \doifinset   \s!public{#2}{\expandafter\let\csname#1attribute\expandafter\endcsname\csname :attr:#1\endcsname}}

% expandable so we can \edef them for speed

\def\dosetattribute#1#2{\csname @attr@#1\endcsname#2\relax}
\def\doresetattribute#1{\csname @attr@#1\endcsname\attributeunsetvalue}
\def\dogetattribute  #1{\number\csname @attr@#1\endcsname}
\def\dogetattributeid#1{\number\csname :attr:#1\endcsname}

\let\dompattribute\gobbletwoarguments

\def\resetallattributes{\the\attributesresetlist}

%D For the moment we put this here (later it will move to where it's used):

\definesystemattribute [state]
\definesystemattribute [skip]
\definesystemattribute [penalty]
\definesystemattribute [colormodel]      [public,global]
\definesystemattribute [color]           [public]
\definesystemattribute [transparency]    [public]
\definesystemattribute [background]      [public]
\definesystemattribute [colorintent]     [public]
\definesystemattribute [negative]        [public]
\definesystemattribute [effect]          [public]
\definesystemattribute [viewerlayer]     [public]
\definesystemattribute [layoutcomponent] [public]
\definesystemattribute [reference]       [public]
\definesystemattribute [destination]     [public]
\definesystemattribute [internal]        [public]
\definesystemattribute [ruled]           [public]
\definesystemattribute [shifted]         [public]

\protect \endinput