attr-ini.mkxl /size: 7071 b    last modification: 2023-12-21 09:44
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\unprotect
17
18\registerctxluafile{attr-ini}{autosuffix}
19
20\installcorenamespace{attributecount}  % the counter representing the attribute (attrdef'd)
21\installcorenamespace{attributeid}     % the internal number
22\installcorenamespace{attributestack}  % the attribute specific stack
23\installcorenamespace{attributepickup}
24
25\permanent\protected\def\pushattribute#1%
26  {\global\advanceby\csname\??attributestack\string#1\endcsname\plusone
27   \gdefcsname\??attributestack\string#1:\number\csname\??attributestack\string#1\endcsname\endcsname{\number\attribute#1}}
28
29\permanent\protected\def\popattribute#1%
30  {\attribute#1\csname\??attributestack\string#1:\number\csname\??attributestack\string#1\endcsname\endcsname\relax
31   \global\advanceby\csname\??attributestack\string#1\endcsname\minusone}
32
33\permanent\protected\def\installattributestack#1%
34  {\ifcsname\??attributestack\string#1\endcsname \else
35     \expandafter\newinteger\csname\??attributestack\string#1\endcsname
36   \fi}
37
38\newtoks \t_attr_list_global
39\newtoks \t_attr_list_local
40\newtoks \t_attr_list_pickup
41\newtoks \t_attr_list_nomath
42
43\ifdefined \s!global    \else \immutable\def\s!global   {global}    \fi % for metatex % or hard check later
44\ifdefined \s!public    \else \immutable\def\s!public   {public}    \fi % for metatex % or hard check later
45\ifdefined \s!private   \else \immutable\def\s!private  {private}   \fi % for metatex % or hard check later
46\ifdefined \s!attribute \else \immutable\def\s!attribute{attribute} \fi % for metatex % or hard check later
47\ifdefined \s!pickup    \else \immutable\def\s!pickup   {pickup}    \fi % for metatex % or hard check later
48\ifdefined \s!forget    \else \immutable\def\s!forget   {forget}    \fi % for metatex % or hard check later
49
50\immutable\def\??attributeprefix{c_attr_}
51
52\permanent\protected\def\defineattribute      {\attr_basics_define_indeed[\s!public ]}
53\permanent\protected\def\definesystemattribute{\attr_basics_define_indeed[\s!private]}
54
55\tolerant\def\attr_basics_define_indeed[#1]#*[#2]#*[#3]%
56  {\ifcsname\??attributeprefix#2\endcsname\else
57     \scratchcounter\clf_defineattribute{#2}{#1}\relax
58    %\writestatus\m!system{defining #1 attribute #2 with number \number\scratchcounter}%
59     \global\permanent\expandafter\attributedef\csname\??attributeprefix#2\endcsname\scratchcounter %           \foo = 123
60     \global\permanent\expandafter\integerdef  \csname\??attributeid    #2\endcsname\scratchcounter % \attribute\foo = 123
61     % some attributes are always global
62     \ifinset\s!global{#3}%
63       \xtoksapp\t_attr_list_global{\csname\??attributeprefix#2\endcsname\attributeunsetvalue}% \c_attr_foo
64     \else
65       \xtoksapp\t_attr_list_local {\csname\??attributeprefix#2\endcsname\attributeunsetvalue}%
66     \fi
67     \ifinset\s!nomath{#3}%
68       \xtoksapp\t_attr_list_nomath{\csname\??attributeprefix#2\endcsname\attributeunsetvalue}%
69     \fi
70     \ifinset\s!public{#3}%
71       \aliased\gletcsname#2\s!attribute\expandafter\endcsname\csname\??attributeid#2\endcsname% \attribute\fooattribute
72     \fi
73     % used to sync in the page builder .. used for directions and scripts ... i start forgetting these details .. (seldom used)
74     \ifinset\s!pickup{#3}%
75       \global\expandafter\integerdef\csname\??attributepickup#2\endcsname\attributeunsetvalue
76       \xtoksapp\t_attr_list_pickup{\csname\??attributeprefix#2\endcsname\csname\??attributepickup#2\endcsname}%
77       \ifcsname#2\s!attribute\endcsname
78         \permanent\xdefcsname\s!pickup#2\s!attribute\endcsname{\expandafter\integerdef\csname\??attributepickup#2\endcsname\csname\??attributeprefix#2\endcsname}%
79         \permanent\xdefcsname\s!forget#2\s!attribute\endcsname{\expandafter\integerdef\csname\??attributepickup#2\endcsname\attributeunsetvalue}%
80       \fi
81     \fi
82   \fi}
83
84\permanent\protected\def\pickupattributes
85  {\expand\t_attr_list_pickup\relax}
86
87\permanent\protected\def\newattribute#1%
88  {\attr_basics_define_indeed[\s!public][\csstring#1][]%
89   \expandafter\glet\expandafter#1\csname\??attributeid\csstring#1\endcsname}
90
91% expandable so we can \edef them for speed
92
93\permanent\def\dosetattribute#1#2{\csname\??attributeprefix#1\endcsname#2\relax}
94\permanent\def\doresetattribute#1{\csname\??attributeprefix#1\endcsname\attributeunsetvalue}
95\permanent\def\dogetattribute  #1{\number\csname\??attributeprefix#1\endcsname}
96\permanent\def\dogetattributeid#1{\number\csname\??attributeid    #1\endcsname}
97
98\aliased\let\dompattribute\gobbletwoarguments
99
100\permanent\protected\def\resetglobalattributes{\expand\t_attr_list_global\glyphdatafield\zerocount\glyphscriptfield\zerocount}
101\permanent\protected\def\resetlocalattributes {\expand\t_attr_list_local \glyphdatafield\zerocount\glyphscriptfield\zerocount}
102
103\aliased\let\resetallattributes\resetlocalattributes
104
105%D Rather special.
106
107\permanent\protected\def\savecurrentattributes   #1{\clf_savecurrentattributes   {#1}}
108\permanent\protected\def\restorecurrentattributes#1{\clf_restorecurrentattributes{#1}}
109
110%D For the moment we put this here. The order of definition matters a bit because
111%D performance is better when we put frequently accessed attributes at the front.
112%D So, we might move more here.
113
114%definesystemattribute [state]                                  % nomath
115\definesystemattribute [color]               [public]           % global
116\definesystemattribute [colormodel]          [public,global]
117%definesystemattribute [skip]
118%definesystemattribute [penalty]
119\definesystemattribute [transparency]        [public]
120\definesystemattribute [reference]           [public]
121\definesystemattribute [destination]         [public]
122\definesystemattribute [case]                [public]
123\definesystemattribute [visual]              [public,global]
124\definesystemattribute [viewerlayer]         [public]
125\definesystemattribute [background]          [public]
126\definesystemattribute [alignbackground]     [public]
127\definesystemattribute [colorintent]         [public]
128\definesystemattribute [negative]            [public]
129\definesystemattribute [effect]              [public]
130\definesystemattribute [layoutcomponent]     [public]
131\definesystemattribute [internal]            [public]
132\definesystemattribute [ruled]               [public]
133\definesystemattribute [shifted]             [public]
134\definesystemattribute [checkedbreak]        [public]
135\definesystemattribute [alternate]           [public]
136\definesystemattribute [vboxtohboxseparator] [public]
137
138\permanent\protected\let\showattributes\clf_showattributes % maybe at lua end
139
140%D Todo:
141
142% \appendtoks
143%     \clf_cleanupattributes
144% \to \everyafterpagebreak
145
146\protect \endinput
147