1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Anchoring Macros Grapics}
15
16
17
18
19\registerctxluafile{anchpgr}{autosuffix}
20
21\unprotect
22
23
24
25
26
27\newtoks\everypositionaction
28\newtoks\everyinsertpositionaction
29\newtoks\everycleanpositionaction
30
31\installcorenamespace{positionaction}
32\installcorenamespace{positioncleanup}
33
34\protected\def\anch_positions_set_action#1
35 {\gdefcsname\??positionaction#1\endcsname}
36
37\permanent\protected\def\doifpositionaction#1
38 {\ifcsname\??positionaction#1\endcsname
39 \expandafter\firstofoneargument
40 \else
41 \expandafter\gobbleoneargument
42 \fi}
43
44\permanent\protected\def\doifelsepositionaction#1
45 {\ifcsname\??positionaction#1\endcsname
46 \expandafter\firstoftwoarguments
47 \else
48 \expandafter\secondoftwoarguments
49 \fi}
50
51\aliased\let\doifpositionactionelse\doifelsepositionaction
52
53\permanent\protected\def\dopositionaction#1
54 {\cdef\currentpositionaction{#1}
55 \ifcsname\??positionaction\currentpositionaction\endcsname
56 \anch_positions_action_indeed
57 \fi}
58
59\def\anch_positions_action_indeed
60 {\doifelseposition\currentpositionaction
61 \anch_positions_action_indeed_yes
62 \anch_positions_action_indeed_nop}
63
64\def\anch_positions_action_indeed_nop
65 {\anch_positions_trace_action_nop}
66
67\def\anch_positions_action_indeed_yes
68 {\begingroup
69 \setbox\scratchbox\hbox
70 {\anch_positions_trace_action_yes
71 \expand\everyinsertpositionaction
72 \expand\everypositionaction
73 \begincsname\??positionaction\currentpositionaction\endcsname
74 \anch_positions_cleanup_action}
75 \smashedbox\scratchbox
76 \endgroup}
77
78\protected\def\anch_positions_trace_action_nop_indeed
79 {\anch_positions_trace\clap\darkred{<\currentpositionaction>}}
80
81\protected\def\anch_positions_trace_action_yes_indeed
82 {\anch_positions_trace\clap\darkgreen{<\currentpositionaction>}}
83
84\let\anch_positions_trace_action_nop\relax
85\let\anch_positions_trace_action_yes\relax
86
87\appendtoks
88 \let\anch_positions_trace_action_nop\anch_positions_trace_action_nop_indeed
89 \let\anch_positions_trace_action_yes\anch_positions_trace_action_yes_indeed
90\to \t_anch_positions_tracers
91
92
93
94
95
96
97\def\anch_positions_cleanup_action
98 {\ifcsname\??positioncleanup\currentpositionaction\endcsname
99 \expand\everycleanpositionaction
100 \xdefcsname\??positioncleanup\currentpositionaction\endcsname{\csname\??positioncleanup\currentpositionaction\endcsname}
101 \fi}
102
103\permanent\protected\def\handlepositionaction#1\with#2\on#3
104 {\begingroup
105 \cdef\currentpositionanchor{\ifempty\currentpositionoverlay#3\else\currentpositionoverlay::\MPanchoridentifier\fi}
106 \normalexpanded{\anch_positions_set_action{\currentpositionanchor}{\noexpand\csname\??positioncleanup\currentpositionanchor\endcsname}}
107 \let#1\relax
108 \ifcsname\??positioncleanup\currentpositionanchor\endcsname
109 \xdefcsname\??positioncleanup\currentpositionanchor\endcsname{\csname\??positioncleanup\currentpositionanchor\endcsname#1#2}
110 \else
111 \xdefcsname\??positioncleanup\currentpositionanchor\endcsname{#1#2}
112 \fi
113 \endgroup}
114
115
116
117
118
119\newdimension\c_anch_page_width
120\newdimension\c_anch_page_height
121
122\protected\def\anch_positions_register_page#1
123 {\ifpositioning\ifcase\realpageno\or
124 \ifdim\c_anch_page_height=\paperheight
125 \ifdim\c_anch_page_width=\paperwidth
126
127 \else
128 \c_anch_page_width \paperwidth
129 \c_anch_page_height\paperheight
130 \anch_make_page_box{#1}
131 \fi
132 \else
133 \c_anch_page_width \paperwidth
134 \c_anch_page_height\paperheight
135 \anch_make_page_box{#1}
136 \fi
137 \fi\fi}
138
139\protected\def\anch_positions_place_anchors
140 {\ifpositioning
141 \anch_positions_place_anchors_yes
142 \else
143 \anch_positions_place_anchors_nop
144 \fi}
145
146\def\anch_positions_place_anchors_yes
147 {\begingroup
148 \setbox\scratchbox\emptyhbox
149 \ht\scratchbox\textheight
150 \dp\scratchbox\zeropoint
151 \wd\scratchbox\makeupwidth
152 \anch_mark_text_box\scratchbox
153 \box\scratchbox
154 \endgroup}
155
156\def\anch_positions_place_anchors_nop
157 {\vkern\textheight}
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\immutable\def \MPanchoridentifier{mpa}
208\mutable \def \MPanchornumber {\the\realpageno}
209\mutable \lettonothing\MPanchorid
210
211
212
213\mutable\lettonothing\currentpositionoverlay
214
215
216
217\immutable\def\textbackgroundoverlay#1{\v!text#1}
218
219\permanent\protected\def\positionoverlay
220 {\ifpositioning
221 \expandafter\anch_positions_overlay_indeed
222 \else
223 \expandafter\gobbleoneargument
224 \fi}
225
226\def\anch_positions_overlay_indeed#1
227 {\begingroup
228 \cdef\currentpositionoverlay{#1}
229 \ifcsname\??positionaction\currentpositionoverlay::\MPanchoridentifier\endcsname
230 \anch_positions_overlay_compose
231 \fi
232 \endgroup}
233
234\permanent\def\MPoverlayanchor#1{\MPpos\MPanchorid}
235
236\def\anch_positions_overlay_compose
237 {\vpack to \d_overlay_height
238 {
239 \edef\MPanchorid{\currentpositionoverlay::\MPanchoridentifier:\MPanchornumber}
240
241 \enforced\let\MPanchor\MPoverlayanchor
242 \expand\everyinsertpositionaction
243 \copyposition{\currentpositionoverlay::\MPanchoridentifier}\MPanchorid
244 \setbox\scratchbox\hbox to \d_overlay_width
245 {\dopositionaction{\currentpositionoverlay::\MPanchoridentifier}\hss}
246 \ht\scratchbox\d_overlay_height
247 \dp\scratchbox\zeropoint
248 \anch_mark_tagged_box\scratchbox\MPanchorid\zerocount
249 \box\scratchbox
250 \vfill}}
251
252\permanent\protected\def\positionregionoverlay
253 {\ifpositioning
254 \expandafter\anch_positions_region_overlay_indeed
255 \else
256 \expandafter\gobbletwoarguments
257 \fi}
258
259\lettonothing\currentpositionregion
260
261\def\anch_positions_region_overlay_indeed#1#2
262 {\begingroup
263 \cdef\currentpositionregion {#1}
264 \cdef\currentpositionoverlay{#2}
265 \ifcsname\??positionaction\currentpositionoverlay::\MPanchoridentifier\endcsname
266 \anch_positions_region_overlay_compose
267 \fi
268 \endgroup}
269
270\def\anch_positions_region_overlay_compose
271 {\vpack to \d_overlay_height
272 {\let\MPanchorid\currentpositionregion
273 \enforced\let\MPanchor\MPoverlayanchor
274 \expand\everyinsertpositionaction
275 \copyposition{\currentpositionoverlay::\MPanchoridentifier}\MPanchorid
276 \setbox\scratchbox\hbox to \d_overlay_width
277 {\dopositionaction{\currentpositionoverlay::\MPanchoridentifier}\hss}
278 \ht\scratchbox\d_overlay_height
279 \dp\scratchbox\zeropoint
280 \box\scratchbox
281 \vfill}}
282
283
284
285\permanent\protected\def\startpositionoverlay
286 {\iftrialtypesetting
287 \expandafter\anch_positions_overlay_start_nop
288 \else
289 \expandafter\anch_positions_overlay_start_yes
290 \fi}
291
292\def\anch_positions_overlay_start_nop#1\stoppositionoverlay
293 {}
294
295\ifdefined\checkpositionoverlays \else \let\checkpositionoverlays\relax \fi
296
297\mutable\lettonothing\currentpositionoverlay
298
299\def\anch_positions_overlay_start_yes#1
300 {\checkpositionoverlays
301 \cdef\currentpositionoverlay{#1}}
302
303\permanent\protected\def\stoppositionoverlay
304 {\lettonothing\currentpositionoverlay}
305
306
307
308
309\installcorenamespace{positiongraphic}
310\installcorenamespace{positionmethod}
311
312
313\newbox\b_anch_positions_graphic
314
315\permanent\tolerant\protected\def\startMPpositiongraphic#=##=#:#3\stopMPpositiongraphic
316 {\gdefcsname\??positiongraphic#1\endcsname{\anch_positions_meta_graphic_use{#1}{#2}{#3}}}
317
318\permanent\protected\lettonothing\stopMPpositiongraphic
319
320\def\anch_positions_meta_graphic_prepare
321 {\ifempty{\mpcategoryparameter{self}}
322 \letmpcategoryparameter{self}\currentposition
323 \fi
324 \ifempty{\mpcategoryparameter{from}}
325 \letmpcategoryparameter{from}\currentposition
326 \fi}
327
328\def\anch_positions_meta_graphic_use#1#2#3
329 {\begingroup
330 \cdef\currentmpcategory{#1}
331 \anch_positions_meta_graphic_prepare
332 \startMPcode#3\stopMPcode
333 \endgroup}
334
335\permanent\tolerant\protected\def\MPpositiongraphic#=#*#=
336 {\ifcsname\??positionmethod#1\endcsname
337 \expandafter\anch_positions_meta_graphic_direct_method
338 \orelse\ifcsname\??positiongraphic#1\endcsname
339 \expandafter\anch_positions_meta_graphic_direct_normal
340 \else
341 \expandafter\gobbletwoarguments
342 \fi{#1}{#2}}
343
344\def\anch_positions_meta_graphic_direct_method{\anch_positions_meta_graphic_direct\??positionmethod }
345\def\anch_positions_meta_graphic_direct_normal{\anch_positions_meta_graphic_direct\??positiongraphic}
346
347\def\anch_positions_meta_graphic_direct#1#2#3
348 {\begingroup
349 \cdef\currentmpcategory{#2}
350 \setupcurrentmpcategory[#3]
351 \anch_positions_meta_graphic_prepare
352 \obeyMPboxorigin
353 \enforced\tolerant\protected\def\MPpositiongraphic##=##*##={\anch_positions_meta_graphic_nested{#3}{##1}{##2}}
354
355 \setbox\b_anch_positions_graphic\hpack
356 {\ignorespaces\begincsname#1#2\endcsname\removelastspace}
357 \smashbox\b_anch_positions_graphic
358 \box\b_anch_positions_graphic
359 \endgroup}
360
361\def\anch_positions_meta_graphic_nested#1#2#3
362 {\begingroup
363 \cdef\currentmpcategory{#2}
364 \setupcurrentmpcategory[#1,#3]
365 \anch_positions_meta_graphic_prepare
366 \begincsname\??positiongraphic#2\endcsname
367 \endgroup}
368
369\permanent\def\startMPpositionmethod#1#2\stopMPpositionmethod
370 {\gdefcsname\??positionmethod#1\endcsname{#2}}
371
372\permanent\protected\lettonothing\stopMPpositionmethod
373
374
375
376\permanent\tolerant\protected\def\setMPpositiongraphic#=#*#=#*#=
377 {\ifempty\currentpositionoverlay
378 \anch_positions_set_action{#1}{\MPpositiongraphic{#2}{#3}}
379 \else
380 \anch_positions_meta_graphic_handle{#1}{#2}{#3}
381 \fi}
382
383\def\anch_positions_meta_graphic_handle#1#2#3
384 {\handlepositionaction\anch_positions_meta_graphic_handle_indeed\with{#1}{#2}{#3}\on{#2}}
385
386\def\anch_positions_meta_graphic_insert#1#2#3
387 {\ifnum\MPp{#1}=\realpageno\relax
388 \cdef\currentposition{#1}\MPpositiongraphic{#2}{#3}
389 \fi}
390
391\let\anch_positions_meta_graphic_handle_indeed\relax
392
393\appendtoks
394 \let\anch_positions_meta_graphic_handle_indeed\anch_positions_meta_graphic_insert
395\to \everyinsertpositionaction
396
397\def\anch_positions_meta_graphic_cleanup#1#2#3
398 {\ifnum\MPp{#1}<\realpageno \else
399 \noexpand\anch_positions_meta_graphic_handle_indeed{#1}{#2}{#3}
400 \fi}
401
402\appendtoks
403 \let\anch_positions_meta_graphic_handle_indeed\anch_positions_meta_graphic_cleanup
404\to \everycleanpositionaction
405
406
407
408\permanent\tolerant\protected\def\setMPpositiongraphicrange#=#*#=#*#=#*#=
409 {\ifempty\currentpositionoverlay
410 \anch_positions_set_action{#1}{\MPpositiongraphic{#3}{#4}}
411 \else
412 \anch_positions_meta_graphic_handle_range{#1}{#2}{#3}{#4}
413 \fi}
414
415\def\anch_positions_meta_graphic_handle_range#1#2#3#4
416 {\handlepositionaction\anch_positions_meta_graphic_handle_range_indeed\with{#1}{#2}{#3}{#4}\on{#2}}
417
418\def\anch_positions_meta_graphic_insert_range#1#2#3#4
419 {\clf_doifelserangeonpage{#1}{#2}\realpageno
420 {\cdef\currentposition{#1}
421 \MPpositiongraphic{#3}{#4}}
422 {}}
423
424\appendtoks
425 \let\anch_positions_meta_graphic_handle_range_indeed\anch_positions_meta_graphic_insert_range
426\to \everyinsertpositionaction
427
428\def\anch_positions_meta_graphic_cleanup_range#1#2#3#4
429 {\ifnum\MPp{#2}<\realpageno \else
430 \noexpand\anch_positions_meta_graphic_handle_range_indeed{#1}{#2}{#3}{#4}
431 \fi}
432
433\appendtoks
434 \let\anch_positions_meta_graphic_handle_range_indeed\anch_positions_meta_graphic_cleanup_range
435\to \everycleanpositionaction
436
437\let\anch_positions_meta_graphic_handle_range_indeed\gobblefourarguments
438
439
440
441\permanent\def\MPgetposboxes #1#2{\clf_fetchposboxes{#1}{#2}\realpageno}
442\permanent\def\MPgetmultipars#1#2{\clf_fetchmultipar{#1}{#2}\realpageno}
443
444\protect \endinput
445 |