1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Anchoring Macros Positioning}
15
16
17
18
19
20\unprotect
21
22\newinteger\c_anch_column
23\newinteger\c_anch_text
24\newinteger\c_anch_free
25\newtoks \t_anch_positions_tracers
26\newinteger\c_anch_positions_paragraph
27\newbox \b_anch_position
28\newif \ifpositioning
29
30\registerctxluafile{anchpos}{autosuffix}
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57\mutable\lettonothing\currentposition
58\mutable\lettonothing\currentpositionaction
59\mutable\lettonothing\currentpositionanchor
60\mutable\lettonothing\currentpositionregion
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94\aliased\let\MPpage \MPp
95\aliased\let\MPregion \MPr
96\aliased\let\MPcolumn \MPc
97\aliased\let\MPparagraph\MPn
98\aliased\let\MPanchor \MPpos
99
100\aliased\let\MPleftskip \MPls
101\aliased\let\MPrightkip \MPrs
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125\aliased\let\MPv \MPplus
126\aliased\let\MPvv\MPrest
127
128
129
130
131\let\dopositionaction\gobbleoneargument
132
133\def\anch_positions_initialize
134 {\ifpositioning \else
135 \global\positioningtrue
136 \fi}
137
138\permanent\protected\def\setpositiononly
139 {\iftrialtypesetting
140 \expandafter\gobbleoneargument
141 \else
142 \expandafter\anch_positions_set_only_indeed
143 \fi}
144
145\def\anch_positions_set_only_indeed#1
146 {\anch_positions_initialize
147 \cdef\currentposition{#1}
148 \dosetposition\currentposition}
149
150\permanent\protected\def\setposition
151 {\iftrialtypesetting
152 \expandafter\gobbleoneargument
153 \else
154 \expandafter\anch_positions_set_indeed
155 \fi}
156
157\def\anch_positions_set_indeed#1
158 {\anch_positions_initialize
159 \cdef\currentposition{#1}
160 \dosetposition\currentposition
161 \anch_positions_trace_left
162 \dopositionaction\currentposition}
163
164\permanent\protected\def\setpositiondata
165 {\iftrialtypesetting
166 \expandafter\gobblefourarguments
167 \else
168 \expandafter\anch_positions_set_data_indeed
169 \fi}
170
171\def\anch_positions_set_data_indeed#1#2#3#4
172 {\anch_positions_initialize
173 \hbox
174 {\cdef\currentposition{#1}
175 \dosetpositionwhd\currentposition{#2}{#3}{#4}
176 \anch_positions_trace_left
177 \dopositionaction\currentposition
178 \hss}}
179
180\permanent\protected\def\setpositionbox
181 {\iftrialtypesetting
182 \expandafter\anch_positions_set_box_nop
183 \else
184 \expandafter\anch_positions_set_box_yes
185 \fi}
186
187\def\anch_positions_set_box_nop#1
188 {\dowithnextboxcs\flushnextbox}
189
190\def\anch_positions_set_box_yes#1
191 {\dowithnextbox{\anch_positions_set_box_finish{#1}}}
192
193\def\anch_positions_set_box_finish#1
194 {\anch_positions_initialize
195
196 \hpack to \wd\nextbox
197 {\cdef\currentposition{#1}
198 \dosetpositionbox\currentposition\nextbox
199 \anch_positions_trace_left
200 \setbox\b_anch_position\box\nextbox
201 \dopositionaction\currentposition
202 \box\b_anch_position
203 \hss}}
204
205\permanent\protected\def\setpositionstrut
206 {\iftrialtypesetting
207 \expandafter\anch_positions_set_strut_nop
208 \else
209 \expandafter\anch_positions_set_strut_yes
210 \fi}
211
212\def\anch_positions_set_strut_nop#1
213 {\strut}
214
215\def\anch_positions_set_strut_yes#1
216 {\anch_positions_initialize
217 \hbox to \zeropoint
218 {\cdef\currentposition{#1}
219 \dosetpositionstrut\currentposition
220 \anch_positions_trace_left
221 \dopositionaction\currentposition
222 \strut
223 \hss}}
224
225\permanent\protected\def\setpositionstrutkind
226 {\iftrialtypesetting
227 \expandafter\anch_positions_set_strut_kind_nop
228 \else
229 \expandafter\anch_positions_set_strut_kind_yes
230 \fi}
231
232\def\anch_positions_set_strut_kind_yes#1#2
233 {\anch_positions_initialize
234 \hbox to \zeropoint
235 {\cdef\currentposition{#1}
236 \dosetpositionstrutkind\currentposition{#2}
237 \anch_positions_trace_left
238 \dopositionaction\currentposition
239 \strut
240 \hss}}
241
242\def\anch_positions_set_strut_kind_nop#1#2
243 {\strut}
244
245\permanent\protected\def\setpositiondataplus
246 {\iftrialtypesetting
247 \expandafter\gobblefivearguments
248 \else
249 \expandafter\anch_positions_set_plus_indeed
250 \fi}
251
252\def\anch_positions_set_plus_indeed#1#2#3#4#5
253 {\anch_positions_initialize
254 \hbox
255 {\cdef\currentposition{#1}
256 \dosetpositionplus\currentposition{#2}{#3}{#4}{#5}
257 \anch_positions_trace_right
258 \dopositionaction\currentposition
259 \hss}}
260
261\permanent\protected\def\setpositionplus
262 {\iftrialtypesetting
263 \expandafter\anch_positions_set_plus_nop
264 \else
265 \expandafter\anch_positions_set_plus_yes
266 \fi}
267
268\def\anch_positions_set_plus_nop#1#2
269 {\dowithnextboxcs\flushnextbox}
270
271\def\anch_positions_set_plus_yes#1#2
272 {\dowithnextbox{\anch_positions_set_plus_yes_finish{#1}{#2}}}
273
274\def\anch_positions_set_plus_yes_finish#1#2
275 {\anch_positions_initialize
276 \hbox to \nextboxwd
277 {\cdef\currentposition{#1}
278 \dosetpositionplus\currentposition{\wd\nextbox}{\ht\nextbox}{\dp\nextbox}{#2}
279 \anch_positions_trace_right
280 \setbox\b_anch_position\flushnextbox
281 \dopositionaction\currentposition
282 \box\b_anch_position
283 \hss}}
284
285\let\currentposition\s!unknown
286
287
288
289\permanent\def\pageanchor {page:\the\realpageno}
290\permanent\def\textanchor {text:\the\realpageno}
291\permanent\def\regionanchor{region:0}
292
293
294
295
296
297
298
299
300
301
302
303
304\protected\def\anch_mark_column_box#1#2
305 {\global\advanceby\c_anch_column\plusone
306 \clf_markregionboxtaggedn#1{columnarea}\c_anch_column#2\relax}
307
308\protected\def\anch_mark_region_box
309 {\iftrialtypesetting
310 \expandafter\gobbleoneargument
311 \orelse\ifpositioning
312 \expandafter\anch_mark_region_box_indeed
313 \else
314 \expandafter\gobbleoneargument
315 \fi}
316
317\protected\def\anch_mark_region_box_indeed#1
318 {\clf_markregionbox#1\relax}
319
320\protected\def\anch_mark_flow_box#1
321 {\hpack\bgroup
322 \global\advanceby\c_anch_text\plusone
323 \clf_markregionboxtagged#1{textarea}\c_anch_text
324 \box#1
325 \egroup}
326
327\protected\def\anch_mark_tagged_box#1#2#3
328 {\clf_markregionboxtagged#1{#2}#3\relax}
329
330\protected\def\anch_mark_flow_only#1
331 {\global\advanceby\c_anch_text\plusone
332 \clf_markregionboxcorrected#1{textarea}\c_anch_text}
333
334\protected\def\anch_make_page_box#1
335 {\clf_setregionboxtagged#1{page}\realpageno}
336
337\protected\def\anch_mark_text_box#1
338 {\clf_markregionboxtagged#1{text}\realpageno}
339
340\protected\def\anch_mark_tagged_box_free
341 {\ifpositioning
342 \expandafter\anch_mark_tagged_box_free_yes
343 \else
344 \expandafter\gobblesixarguments
345 \fi}
346
347
348
349\protected\def\anch_mark_tagged_box_free_yes#1#2#3#4#5#6
350 {\global\advanceby\c_anch_free\plusone
351 \clf_markregionboxtaggedkind
352 #1
353 {free}
354 \c_anch_free
355 #2
356 #3
357 #4
358 #5
359 #6
360 \relax}
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385\aliased\let\doifpositionelse \doifelseposition
386\aliased\let\doifpositiononpageelse\doifelsepositiononpage
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405\aliased\let\xypos\setpositiononly
406
407\permanent\protected\def\hpos #1{\dontleavehmode\setpositionbox{#1}\hbox}
408\permanent\protected\def\vpos #1{\setpositionbox{#1}\vbox}
409\permanent\protected\def\bpos #1{\dontleavehmode\setpositionstrut{b:#1}\ignorespaces}
410\permanent\protected\def\epos #1{\removeunwantedspaces\setpositionstrut{e:#1}}
411\permanent\protected\def\bposkind#1#2{\dontleavehmode\setpositionstrutkind{b:#1}{#2}\ignorespaces}
412\permanent\protected\def\eposkind#1#2{\removeunwantedspaces\setpositionstrutkind{e:#1}{#2}}
413
414
415
416
417
418
419
420
421
422\permanent\protected\def\tracepositions
423 {\expand\t_anch_positions_tracers}
424
425\permanent\protected\def\enableparpositions
426 {\enforced\aliased\glet\registerparoptions\doregisterparoptions
427 \global\positioningtrue}
428
429\permanent\protected\lettonothing\disableparpositions
430\permanent\protected\lettonothing\registerparoptions
431
432\permanent\protected\def\doregisterparoptions
433 {\iftrialtypesetting \orelse\ifinpagebody \orelse\ifmmode \orelse\ifinformula \else
434 \anch_positions_register_par_options
435 \fi}
436
437\def\anch_positions_register_par_options_normal
438 {\dontleavehmode\clf_parpos}
439
440\def\anch_positions_register_par_options_traced
441 {\anch_positions_register_par_options_normal
442 \begingroup
443 \setbox\scratchbox\hpack
444 {\hss
445 \startcolor[blue]
446 \hpack \s!yoffset 2\onepoint to \zeropoint
447 {\hss\infofont\the\c_anch_positions_paragraph\hskip2\onepoint}
448 \vrule
449 \s!width 4\onepoint
450 \s!height2\onepoint
451 \s!depth 2\onepoint
452 \stopcolor
453 \hss}
454 \smashbox\scratchbox
455 \boxxoffset\scratchbox2\onepoint
456 \box\scratchbox
457 \endgroup}
458
459\let\anch_positions_register_par_options\anch_positions_register_par_options_normal
460
461\appendtoks
462 \let\anch_positions_register_par_options\anch_positions_register_par_options_traced
463\to \t_anch_positions_tracers
464
465\protected\def\anch_positions_trace#1#2#3
466 {\smashedhbox
467 {#1{\infofont#2#3}
468 \kern\onepoint
469 \vrule\s!width2\onepoint\s!height\halfapoint\s!depth\halfapoint}}
470
471\protected\def\anch_positions_trace_left_indeed
472 {\anch_positions_trace\llap\darkmagenta{\currentposition>}}
473
474\protected\def\anch_positions_trace_right_indeed
475 {\anch_positions_trace\rlap\darkcyan{<\currentposition}}
476
477\let\anch_positions_trace_left \relax
478\let\anch_positions_trace_right\relax
479
480\appendtoks
481 \let\anch_positions_trace_left \anch_positions_trace_left_indeed
482 \let\anch_positions_trace_right \anch_positions_trace_right_indeed
483\to \t_anch_positions_tracers
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501\aliased\let\doifoverlappingelse\doifelseoverlapping
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523\aliased\let\doifpositionsonsamepageelse\doifelsepositionsonsamepage
524\aliased\let\doifpositionsonthispageelse\doifelsepositionsonthispage
525\aliased\let\doifpositionsusedelse \doifelsepositionsused
526
527
528
529\permanent\protected\def\savepos {\clf_savepos}
530\permanent\protected\def\lastxpos{\numexpr\clf_lastxpos\relax}
531\permanent\protected\def\lastypos{\numexpr\clf_lastypos\relax}
532
533\protect \endinput
534 |