1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Typesetting Macros Adaptive}
15
16
17
18
19
20\unprotect
21
22\ifdefined\d_adaptive_width \else
23 \newdimension\d_adaptive_width
24 \newdimension\d_adaptive_height
25 \newdimension\d_adaptive_depth
26 \newdimension\d_adaptive_line
27 \newdimension\d_adaptive_hsize
28 \newbox \b_adaptive_box
29\fi
30
31\aliasdimension\usedadaptivewidth \d_adaptive_width
32\aliasdimension\usedadaptiveheight\d_adaptive_height
33\aliasdimension\usedadaptivedepth \d_adaptive_depth
34\aliasdimension\usedadaptiveline \d_adaptive_line
35\aliasdimension\usedadaptivehsize \d_adaptive_hsize
36
37\registerctxluafile{typoada}{autosuffix}
38
39\aliased\let\usedadaptivebox\b_adaptive_box
40
41\mutable\lettonothing\m_adaptive_color
42\mutable\lettonothing\m_adaptive_alternative
43
44\permanent\def\usedadaptivecolor {\m_adaptive_color}
45\permanent\def\usedadaptivealternative{\m_adaptive_alternative}
46
47\protected\untraced\def\usedadaptivetotal{\dimexpr\usedadaptiveheight\usedadaptivedepth\relax}
48
49\definesystemattribute[adaptive][public]
50
51\installcorenamespace{adaptive}
52
53\installcommandhandler \??adaptive {adaptive} \??adaptive
54
55
56
57
58
59\setupadaptive
60 [\c!foregroundstyle=,
61 \c!foregroundcolor=,
62 \c!color=gray,
63 \c!alternative=,
64 \c!rulethickness=\linewidth,
65 \c!method=1,
66 \c!stretch=,
67 \c!shrink=,
68
69 \c!margin=2\emwidth]
70
71\permanent\protected\def\adaptivehbox{\typo_adaptive_box\zerocount}
72\permanent\protected\def\adaptivevbox{\typo_adaptive_box\plusone }
73
74\aliased\let\adaptivebox\adaptivehbox
75
76\tolerant\def\typo_adaptive_box#1#*[#S#2]#*[#S#3]
77 {\ifcase#1\dontleavehmode\fi
78 \begingroup
79 \ifhastok={#2}
80 \lettonothing\currentadaptive
81 \setupcurrentadaptive[#2]
82 \else
83 \cdef\currentadaptive{#2}
84 \setupcurrentadaptive[#3]
85 \fi
86 \edef\p_setups{\adaptiveparameter\c!setups}
87 \dowithnextboxcontent
88 {\useadaptivestyleandcolor\c!foregroundstyle\c!foregroundcolor
89 \ifcstok{\adaptiveparameter\c!strut}\v!yes
90 \ifcase#1
91 \strut
92 \else
93
94 \fi
95 \fi}
96 {\ifempty\p_setups
97
98 \else
99 \clf_setadaptive {
100 method \adaptiveparameter\c!method
101 setups {\p_setups}
102 color {\adaptiveparameter\c!color}
103 alternative {\adaptiveparameter\c!alternative}
104 rulethickness \adaptiveparameter\c!rulethickness
105 }
106 \fi
107 \scratchdimen\adaptiveparameter\c!margin\relax
108 \edef\p_stretch{\adaptiveparameter\c!stretch}
109 \edef\p_shrink {\adaptiveparameter\c!shrink}
110 \uleaders
111 \s!callback \numexpr \adaptiveattribute \relax
112 \ifcase#1
113 \hbox
114 \s!spread \scratchdimen
115 \bgroup
116 \hss\box\nextbox\hss
117 \egroup
118 \hskip
119 \else
120 \vbox
121 \s!spread \scratchdimen
122 \bgroup
123 \vss\box\nextbox\vss
124 \egroup
125 \vskip
126 \fi
127 \zeropoint
128 \s!plus \ifempty\p_stretch\scratchdimen\else\p_stretch\fi
129 \s!minus \ifempty\p_shrink \scratchdimen\else\p_shrink \fi
130 \endgroup}
131 \ifcase#1\hbox\else\vbox\fi}
132
133
134
135
136
137
138
139
140\permanent\protected\def\adaptive
141 {\dowithnextbox{\adaptivecheckbox\nextbox\box\nextbox}}
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243\protect
244 |