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}{}
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\unexpanded\def\anch_positions_set_action#1
35 {\expandafter\gdef\csname\??positionaction#1\endcsname}
36
37\unexpanded\def\doifpositionaction#1
38 {\ifcsname\??positionaction#1\endcsname
39 \expandafter\firstofoneargument
40 \else
41 \expandafter\gobbleoneargument
42 \fi}
43
44\unexpanded\def\doifelsepositionaction#1
45 {\ifcsname\??positionaction#1\endcsname
46 \expandafter\firstoftwoarguments
47 \else
48 \expandafter\secondoftwoarguments
49 \fi}
50
51\let\doifpositionactionelse\doifelsepositionaction
52
53\unexpanded\def\dopositionaction#1
54 {\edef\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 \the\everyinsertpositionaction
72 \the\everypositionaction
73 \begincsname\??positionaction\currentpositionaction\endcsname
74 \anch_positions_cleanup_action}
75 \smashedbox\scratchbox
76 \endgroup}
77
78\unexpanded\def\anch_positions_trace_action_nop_indeed
79 {\anch_positions_trace\clap\darkred{<\currentpositionaction>}}
80
81\unexpanded\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 \the\everycleanpositionaction
100 \setxvalue{\??positioncleanup\currentpositionaction}{\csname\??positioncleanup\currentpositionaction\endcsname}
101 \fi}
102
103\def\handlepositionaction#1\with#2\on#3
104 {\begingroup
105 \edef\currentpositionanchor
106 {\ifx\currentpositionoverlay\empty#3\else\currentpositionoverlay::\MPanchoridentifier\fi}
107 \normalexpanded{\anch_positions_set_action{\currentpositionanchor}{\noexpand\getvalue{\??positioncleanup\currentpositionanchor}}}
108 \let#1\relax
109 \ifcsname\??positioncleanup\currentpositionanchor\endcsname
110 \setxvalue{\??positioncleanup\currentpositionanchor}
111 {\csname\??positioncleanup\currentpositionanchor\endcsname#1#2}
112 \else
113 \setxvalue{\??positioncleanup\currentpositionanchor}
114 {#1#2}
115 \fi
116 \endgroup}
117
118
119
120
121
122\newdimen\c_anch_page_width
123\newdimen\c_anch_page_height
124
125\unexpanded\def\anch_positions_register_page#1
126 {\ifpositioning\ifcase\realpageno\or
127 \ifdim\c_anch_page_height=\paperheight
128 \ifdim\c_anch_page_width=\paperwidth
129
130 \else
131 \c_anch_page_width \paperwidth
132 \c_anch_page_height\paperheight
133 \anch_make_page_box{#1}
134 \fi
135 \else
136 \c_anch_page_width \paperwidth
137 \c_anch_page_height\paperheight
138 \anch_make_page_box{#1}
139 \fi
140 \fi\fi}
141
142\unexpanded\def\anch_positions_place_anchors
143 {\ifpositioning
144 \anch_positions_place_anchors_yes
145 \else
146 \anch_positions_place_anchors_nop
147 \fi}
148
149\def\anch_positions_place_anchors_yes
150 {\begingroup
151 \setbox\scratchbox\emptyhbox
152 \ht\scratchbox\textheight
153 \dp\scratchbox\zeropoint
154 \wd\scratchbox\makeupwidth
155 \anch_mark_text_box\scratchbox
156 \box\scratchbox
157 \endgroup}
158
159\def\anch_positions_place_anchors_nop
160 {\vkern\textheight}
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\def\MPanchoridentifier{mpa}
211
212
213
214\let\currentpositionoverlay\empty
215
216
217
218\def\textbackgroundoverlay#1{\v!text#1}
219\def\MPanchornumber {\the\realpageno}
220
221\unexpanded\def\positionoverlay
222 {\ifpositioning
223 \expandafter\anch_positions_overlay_indeed
224 \else
225 \expandafter\gobbleoneargument
226 \fi}
227
228\def\anch_positions_overlay_indeed#1
229 {\begingroup
230 \edef\currentpositionoverlay{#1}
231 \ifcsname\??positionaction\currentpositionoverlay::\MPanchoridentifier\endcsname
232 \anch_positions_overlay_compose
233 \fi
234 \endgroup}
235
236\def\MPoverlayanchor#1{\MPpos\MPanchorid}
237
238\def\anch_positions_overlay_compose
239 {\vpack to \d_overlay_height
240 {
241 \edef\MPanchorid{\currentpositionoverlay::\MPanchoridentifier:\MPanchornumber}
242
243 \let\MPanchor\MPoverlayanchor
244 \the\everyinsertpositionaction
245 \copyposition{\currentpositionoverlay::\MPanchoridentifier}\MPanchorid
246 \setbox\scratchbox\hbox to \d_overlay_width
247 {\dopositionaction{\currentpositionoverlay::\MPanchoridentifier}\hss}
248 \ht\scratchbox\d_overlay_height
249 \dp\scratchbox\zeropoint
250 \anch_mark_tagged_box\scratchbox\MPanchorid
251 \box\scratchbox
252 \vfill}}
253
254\unexpanded\def\positionregionoverlay
255 {\ifpositioning
256 \expandafter\anch_positions_region_overlay_indeed
257 \else
258 \expandafter\gobbletwoarguments
259 \fi}
260
261\let\currentpositionregion\empty
262
263\def\anch_positions_region_overlay_indeed#1#2
264 {\begingroup
265 \edef\currentpositionregion {#1}
266 \edef\currentpositionoverlay{#2}
267 \ifcsname\??positionaction\currentpositionoverlay::\MPanchoridentifier\endcsname
268 \anch_positions_region_overlay_compose
269 \fi
270 \endgroup}
271
272\def\anch_positions_region_overlay_compose
273 {\vpack to \d_overlay_height
274 {\let\MPanchorid\currentpositionregion
275 \let\MPanchor\MPoverlayanchor
276 \the\everyinsertpositionaction
277 \copyposition{\currentpositionoverlay::\MPanchoridentifier}\MPanchorid
278 \setbox\scratchbox\hbox to \d_overlay_width
279 {\dopositionaction{\currentpositionoverlay::\MPanchoridentifier}\hss}
280 \ht\scratchbox\d_overlay_height
281 \dp\scratchbox\zeropoint
282 \box\scratchbox
283 \vfill}}
284
285
286
287\unexpanded\def\startpositionoverlay
288 {\iftrialtypesetting
289 \expandafter\anch_positions_overlay_start_nop
290 \else
291 \expandafter\anch_positions_overlay_start_yes
292 \fi}
293
294\let\stoppositionoverlay\relax
295
296\def\anch_positions_overlay_start_nop#1\stoppositionoverlay
297 {}
298
299\ifdefined\checkpositionoverlays \else \let\checkpositionoverlays\relax \fi
300
301\let\currentpositionoverlay\empty
302
303\def\anch_positions_overlay_start_yes#1
304 {\checkpositionoverlays
305 \edef\currentpositionoverlay{#1}}
306
307\unexpanded\def\stoppositionoverlay
308 {\let\currentpositionoverlay\empty}
309
310
311
312
313\installcorenamespace{positiongraphic}
314\installcorenamespace{positionmethod}
315
316
317\newbox\b_anch_positions_graphic
318
319\def\startMPpositiongraphic
320 {\dodoublegroupempty\anch_positions_meta_graphic_start}
321
322\def\anch_positions_meta_graphic_start#1#2#3\stopMPpositiongraphic
323 {\setgvalue{\??positiongraphic#1}{\anch_positions_meta_graphic_use{#1}{#2}{#3}}}
324
325\let\stopMPpositiongraphic\relax
326
327\def\anch_positions_meta_graphic_prepare
328 {\ifcsname\??graphicvariable\currentmpvariableclass:self\endcsname \else
329 \letvalue{\??graphicvariable\currentmpvariableclass:self}\currentposition
330 \fi
331 \ifcsname\??graphicvariable\currentmpvariableclass:from\endcsname \else
332 \letvalue{\??graphicvariable\currentmpvariableclass:from}\currentposition
333 \fi}
334
335\def\anch_positions_meta_graphic_use#1#2#3
336 {\begingroup
337 \meta_prepare_variables{#2}
338 \anch_positions_meta_graphic_prepare
339 \startMPcode#3\stopMPcode
340 \endgroup}
341
342\unexpanded\def\MPpositiongraphic
343 {\dodoublegroupempty\anch_positions_meta_graphic_direct}
344
345\def\anch_positions_meta_graphic_direct#1
346 {\ifcsname\??positionmethod#1\endcsname
347 \expandafter\anch_positions_meta_graphic_direct_indeed_method
348 \else\ifcsname\??positiongraphic#1\endcsname
349 \doubleexpandafter\anch_positions_meta_graphic_direct_indeed_normal
350 \else
351 \doubleexpandafter\anch_positions_meta_graphic_direct_indeed_unknown
352 \fi\fi{#1}}
353
354\let\anch_positions_meta_graphic_direct_indeed_unknown\gobbletwoarguments
355
356\def\anch_positions_meta_graphic_direct_indeed_method
357 {\anch_positions_meta_graphic_direct_indeed\??positionmethod}
358
359\def\anch_positions_meta_graphic_direct_indeed_normal
360 {\anch_positions_meta_graphic_direct_indeed\??positiongraphic}
361
362\def\anch_positions_meta_graphic_direct_indeed#1#2#3
363 {\begingroup
364 \setupMPvariables[#2][#3]
365 \edef\currentmpvariableclass{#2}
366 \anch_positions_meta_graphic_prepare
367 \obeyMPboxorigin
368 \def\anch_positions_meta_graphic_direct{\anch_positions_meta_graphic_nested{#3}}
369 \setbox\b_anch_positions_graphic\hbox
370 {\ignorespaces\begincsname#1#2\endcsname\removelastspace}
371 \smashbox\b_anch_positions_graphic
372 \box\b_anch_positions_graphic
373 \endgroup}
374
375\def\anch_positions_meta_graphic_nested#1#2#3
376 {\begingroup
377 \setupMPvariables[#2][#1,#3]
378 \edef\currentmpvariableclass{#2}
379 \anch_positions_meta_graphic_prepare
380 \begincsname\??positiongraphic#2\endcsname
381 \endgroup}
382
383\def\startMPpositionmethod#1#2\stopMPpositionmethod
384 {\setgvalue{\??positionmethod#1}{#2}}
385
386\let\stopMPpositionmethod\relax
387
388
389
390\unexpanded\def\setMPpositiongraphic
391 {\dotriplegroupempty\anch_positions_meta_graphic_set}
392
393\def\anch_positions_meta_graphic_set#1#2#3
394 {\ifx\currentpositionoverlay\empty
395 \anch_positions_set_action{#1}{\MPpositiongraphic{#2}{#3}}
396 \else
397 \anch_positions_meta_graphic_handle{#1}{#2}{#3}
398 \fi}
399
400\def\anch_positions_meta_graphic_handle#1#2#3
401 {\handlepositionaction\anch_positions_meta_graphic_handle_indeed\with{#1}{#2}{#3}\on{#2}}
402
403\def\anch_positions_meta_graphic_insert#1#2#3
404 {\ifnum\MPp{#1}=\realpageno\relax
405 \def\currentposition{#1}\MPpositiongraphic{#2}{#3}
406 \fi}
407
408\let\anch_positions_meta_graphic_handle_indeed\relax
409
410\appendtoks
411 \let\anch_positions_meta_graphic_handle_indeed\anch_positions_meta_graphic_insert
412\to \everyinsertpositionaction
413
414\def\anch_positions_meta_graphic_cleanup#1#2#3
415 {\ifnum\MPp{#1}<\realpageno \else
416 \noexpand\anch_positions_meta_graphic_handle_indeed{#1}{#2}{#3}
417 \fi}
418
419\appendtoks
420 \let\anch_positions_meta_graphic_handle_indeed\anch_positions_meta_graphic_cleanup
421\to \everycleanpositionaction
422
423
424
425\unexpanded\def\setMPpositiongraphicrange
426 {\doquadruplegroupempty\anch_positions_meta_graphic_set_range}
427
428\def\anch_positions_meta_graphic_set_range#1#2#3#4
429 {\ifx\currentpositionoverlay\empty
430 \anch_positions_set_action{#1}{\MPpositiongraphic{#3}{#4}}
431 \else
432 \anch_positions_meta_graphic_handle_range{#1}{#2}{#3}{#4}
433 \fi}
434
435\def\anch_positions_meta_graphic_handle_range#1#2#3#4
436 {\handlepositionaction\anch_positions_meta_graphic_handle_range_indeed\with{#1}{#2}{#3}{#4}\on{#2}}
437
438\def\anch_positions_meta_graphic_insert_range#1#2#3#4
439 {\clf_doifelserangeonpage{#1}{#2}\realpageno
440 {\def\currentposition{#1}
441 \MPpositiongraphic{#3}{#4}}
442 {}}
443
444\appendtoks
445 \let\anch_positions_meta_graphic_handle_range_indeed\anch_positions_meta_graphic_insert_range
446\to \everyinsertpositionaction
447
448\def\anch_positions_meta_graphic_cleanup_range#1#2#3#4
449 {\ifnum\MPp{#2}<\realpageno \else
450 \noexpand \anch_positions_meta_graphic_handle_range_indeed{#1}{#2}{#3}{#4}
451 \fi}
452
453\appendtoks
454 \let\anch_positions_meta_graphic_handle_range_indeed\anch_positions_meta_graphic_cleanup_range
455\to \everycleanpositionaction
456
457\let\anch_positions_meta_graphic_handle_range_indeed\gobblefourarguments
458
459
460
461\def\MPgetposboxes #1#2{\clf_fetchposboxes{#1}{#2}\realpageno}
462\def\MPgetmultipars#1#2{\clf_fetchmultipar{#1}{#2}\realpageno}
463
464\protect \endinput
465 |