attr-ini.mkiv /size: 7607 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=attr-ini,
3%D        version=2007.06.06,
4%D          title=\CONTEXT\ Attribute 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\writestatus{loading}{ConTeXt Attribute Macros / Initialization}
15
16%D Although it's still somewhat experimental, here we introduce code
17%D related to attributes. Housekeeping will move completely to \LUA\
18%D and \type {\newattribute} will go away.
19
20\unprotect
21
22\registerctxluafile{attr-ini}{}
23
24\installcorenamespace{attributecount}  % the counter representing the attribute (attrdef'd)
25\installcorenamespace{attributeid}     % the internal number
26\installcorenamespace{attributestack}  % the attribute specific stack
27\installcorenamespace{attributepickup}
28
29\unexpanded\def\pushattribute#1%
30  {\global\advance\csname\??attributestack\string#1\endcsname\plusone
31   \expandafter\xdef\csname\??attributestack\string#1:\number\csname\??attributestack\string#1\endcsname\endcsname{\number\attribute#1}}
32
33\unexpanded\def\popattribute#1%
34  {\attribute#1\csname\??attributestack\string#1:\number\csname\??attributestack\string#1\endcsname\endcsname\relax
35   \global\advance\csname\??attributestack\string#1\endcsname\minusone}
36
37\unexpanded\def\installattributestack#1%
38  {\ifcsname\??attributestack\string#1\endcsname \else
39     \expandafter\newcount\csname\??attributestack\string#1\endcsname
40   \fi}
41
42\newtoks \t_attr_list_global
43\newtoks \t_attr_list_local
44\newtoks \t_attr_list_pickup
45\newtoks \t_attr_list_nomath
46
47\ifdefined \s!global    \else \def\s!global   {global}    \fi % for metatex % or hard check later
48\ifdefined \s!public    \else \def\s!public   {public}    \fi % for metatex % or hard check later
49\ifdefined \s!private   \else \def\s!private  {private}   \fi % for metatex % or hard check later
50\ifdefined \s!attribute \else \def\s!attribute{attribute} \fi % for metatex % or hard check later
51\ifdefined \s!pickup    \else \def\s!pickup   {pickup}    \fi % for metatex % or hard check later
52\ifdefined \s!forget    \else \def\s!forget   {forget}    \fi % for metatex % or hard check later
53
54\unexpanded\def\defineattribute      {\dodoubleempty\attr_basics_define}
55\unexpanded\def\definesystemattribute{\dodoubleempty\attr_basics_define_system}
56
57\def\attr_basics_define       {\attr_basics_define_indeed\s!public}
58\def\attr_basics_define_system{\attr_basics_define_indeed\s!private}
59
60% todo: define global !
61
62% here public means 'visible' so it's not to be confused with 'public' at the lua end
63
64% \let\attr_prefix\??attributecount
65\def\attr_prefix{c_attr_}
66
67\def\attr_basics_define_indeed#1[#2][#3]%
68  {\ifcsname\attr_prefix#2\endcsname\else
69     \scratchcounter\clf_defineattribute{#2}{#1}\relax
70    %\writestatus\m!system{defining #1 attribute #2 with number \number\scratchcounter}%
71     \global\expandafter\attributedef\csname\attr_prefix#2\endcsname\scratchcounter
72     \global\expandafter\newconstant \csname\??attributeid#2\endcsname
73     \global\csname\??attributeid#2\endcsname\scratchcounter
74     % some attributes are always global
75     \doifelseinset\s!global{#3}%
76       {\xtoksapp\t_attr_list_global{\csname\attr_prefix#2\endcsname\attributeunsetvalue}}%
77       {\xtoksapp\t_attr_list_local {\csname\attr_prefix#2\endcsname\attributeunsetvalue}}%
78     \doifinset\s!nomath{#3}%
79       {\xtoksapp\t_attr_list_nomath{\csname\attr_prefix#2\endcsname\attributeunsetvalue}}%
80     \doifinset\s!public{#3}%
81       {\expandafter\glet\csname#2\s!attribute\expandafter\endcsname\csname\??attributeid#2\endcsname}%
82     \doifinset\s!pickup{#3}%
83       {\global\expandafter\newconstant\csname\??attributepickup#2\endcsname
84        \global\csname\??attributepickup#2\endcsname\attributeunsetvalue
85        \xtoksapp\t_attr_list_pickup{\csname\attr_prefix#2\endcsname\csname\??attributepickup#2\endcsname}%
86        \ifcsname#2\s!attribute\endcsname
87          \expandafter\xdef\csname\s!pickup#2\s!attribute\endcsname
88            {\csname\??attributepickup#2\endcsname\csname\attr_prefix#2\endcsname}%
89          \expandafter\xdef\csname\s!forget#2\s!attribute\endcsname
90            {\csname\??attributepickup#2\endcsname\attributeunsetvalue}%
91        \fi}%
92   \fi}
93
94\unexpanded\def\pickupattributes
95  {\the\t_attr_list_pickup\relax}
96
97% \unexpanded\def\pickupattribute#1%
98%   {\csname\attr_prefix#1\endcsname\csname\??attributepickup#1\endcsname}
99
100% \unexpanded\def\pickupattributelater#1%
101%   {\csname\??attributepickup#1\endcsname\csname\attr_prefix#1\endcsname}
102
103% \unexpanded\def\newattribute#1%
104%   {\attr_basics_define_indeed\s!public[\csstring#1][]%
105%    \expandafter\let\expandafter#1\csname\??attributeid\csstring#1\endcsname}
106
107\unexpanded\def\newattribute#1%
108  {\attr_basics_define_indeed\s!public[\csstring#1][]%
109   \expandafter\glet\expandafter#1\csname\??attributeid\csstring#1\endcsname}
110
111% expandable so we can \edef them for speed
112
113\def\dosetattribute#1#2{\csname\attr_prefix#1\endcsname#2\relax}
114\def\doresetattribute#1{\csname\attr_prefix#1\endcsname\attributeunsetvalue}
115\def\dogetattribute  #1{\number\csname\attr_prefix#1\endcsname}
116\def\dogetattributeid#1{\number\csname\??attributeid#1\endcsname}
117
118\let\dompattribute\gobbletwoarguments
119
120\ifcase\contextlmtxmode
121    \unexpanded\def\resetglobalattributes{\the\t_attr_list_global\attribute\zerocount\zerocount}
122    \unexpanded\def\resetlocalattributes {\the\t_attr_list_local \attribute\zerocount\zerocount}
123\else
124    \unexpanded\def\resetglobalattributes{\the\t_attr_list_global\glyphdatafield\zerocount\glyphscriptfield\zerocount}
125    \unexpanded\def\resetlocalattributes {\the\t_attr_list_local \glyphdatafield\zerocount\glyphscriptfield\zerocount}
126\fi
127
128\let\resetallattributes\resetlocalattributes
129
130%D Rather special.
131
132\unexpanded\def\savecurrentattributes   #1{\clf_savecurrentattributes   {#1}}
133\unexpanded\def\restorecurrentattributes#1{\clf_restorecurrentattributes{#1}}
134
135%D For the moment we put this here. The order of definition matters a bit because
136%D performance is better when we put frequently accessed attributes at the front.
137%D So, we might move more here.
138
139%definesystemattribute [state]                                  % nomath
140\definesystemattribute [color]               [public]           % global
141\definesystemattribute [colormodel]          [public,global]
142%definesystemattribute [skip]
143%definesystemattribute [penalty]
144\definesystemattribute [transparency]        [public]
145\definesystemattribute [reference]           [public]
146\definesystemattribute [destination]         [public]
147\definesystemattribute [case]                [public]
148\definesystemattribute [visual]              [public,global]
149\definesystemattribute [viewerlayer]         [public]
150\definesystemattribute [background]          [public]
151\definesystemattribute [alignbackground]     [public]
152\definesystemattribute [colorintent]         [public]
153\definesystemattribute [negative]            [public]
154\definesystemattribute [effect]              [public]
155\definesystemattribute [layoutcomponent]     [public]
156\definesystemattribute [internal]            [public]
157\definesystemattribute [ruled]               [public]
158\definesystemattribute [shifted]             [public]
159\definesystemattribute [checkedbreak]        [public]
160\definesystemattribute [vboxtohboxseparator] [public]
161
162\unexpanded\def\showattributes{\clf_showattributes}
163
164%D Todo:
165
166% \appendtoks
167%     \clf_cleanupattributes
168% \to \everyafterpagebreak
169
170\protect \endinput
171