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\newfloat\f_anch_extra_y_scale
305
306\def\d_anch_extra_text_depth
307
308 {\ifnum\bottomraggednessmode=\plusthree\strutdp\else\zeropoint\fi}
309
310\protected\def\anch_mark_column_box#1#2
311 {\global\advanceby\c_anch_column\plusone
312 \clf_markregionboxtaggedn
313 #1
314 {columnarea}
315 \c_anch_column
316 \zeropoint
317 \zerofloat
318 #2
319 \relax
320 \f_anch_extra_y_scale\zerofloat}
321
322\protected\def\anch_mark_region_box
323 {\iftrialtypesetting
324 \expandafter\gobbleoneargument
325 \orelse\ifpositioning
326 \expandafter\anch_mark_region_box_indeed
327 \else
328 \expandafter\gobbleoneargument
329 \fi}
330
331\protected\def\anch_mark_region_box_indeed#1
332 {\clf_markregionbox#1\relax}
333
334\protected\def\anch_mark_flow_box#1
335 {\hpack\bgroup
336 \global\advanceby\c_anch_text\plusone
337 \clf_markregionboxtagged
338 #1
339 {textarea}
340 \c_anch_text
341 \d_anch_extra_text_depth
342 \f_anch_extra_y_scale
343 \box#1
344 \egroup
345 \f_anch_extra_y_scale\zerofloat}
346
347\protected\def\anch_mark_tagged_box#1#2#3
348 {\clf_markregionboxtagged#1{#2}#3\zeropoint\zerofloat\relax}
349
350\protected\def\anch_mark_flow_only#1
351 {\global\advanceby\c_anch_text\plusone
352 \clf_markregionboxcorrected
353 #1
354 {textarea}
355 \c_anch_text
356 \d_anch_extra_text_depth
357 \f_anch_extra_y_scale
358 \relax
359 \f_anch_extra_y_scale\zerofloat}
360
361\protected\def\anch_make_page_box#1
362 {\clf_setregionboxtagged
363 #1
364 {page}
365 \realpageno
366 \zeropoint
367 \zerofloat
368 \relax
369 \f_anch_extra_y_scale\zerofloat}
370
371\protected\def\anch_mark_text_box#1
372 {\clf_markregionboxtagged
373 #1
374 {text}
375 \realpageno
376 \d_anch_extra_text_depth
377 \f_anch_extra_y_scale
378 \relax
379 \f_anch_extra_y_scale\zerofloat}
380
381\protected\def\anch_mark_tagged_box_free
382 {\ifpositioning
383 \expandafter\anch_mark_tagged_box_free_yes
384 \else
385 \expandafter\gobblesixarguments
386 \fi}
387
388
389
390\protected\def\anch_mark_tagged_box_free_yes#1#2#3#4#5#6
391 {\global\advanceby\c_anch_free\plusone
392 \clf_markregionboxtaggedkind
393 #1
394 {free}
395 \c_anch_free
396 \zeropoint
397 \zerofloat
398 #2
399 #3
400 #4
401 #5
402 #6
403 \relax
404 \f_anch_extra_y_scale\zerofloat}
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429\aliased\let\doifpositionelse \doifelseposition
430\aliased\let\doifpositiononpageelse\doifelsepositiononpage
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449\aliased\let\xypos\setpositiononly
450
451\permanent\protected\def\hpos #1{\dontleavehmode\setpositionbox{#1}\hbox}
452\permanent\protected\def\vpos #1{\setpositionbox{#1}\vbox}
453\permanent\protected\def\bpos #1{\dontleavehmode\setpositionstrut{b:#1}\ignorespaces}
454\permanent\protected\def\epos #1{\removeunwantedspaces\setpositionstrut{e:#1}}
455\permanent\protected\def\bposkind#1#2{\dontleavehmode\setpositionstrutkind{b:#1}{#2}\ignorespaces}
456\permanent\protected\def\eposkind#1#2{\removeunwantedspaces\setpositionstrutkind{e:#1}{#2}}
457
458
459
460
461
462
463
464
465
466\permanent\protected\def\tracepositions
467 {\expand\t_anch_positions_tracers}
468
469\permanent\protected\def\enableparpositions
470 {\enforced\aliased\glet\registerparoptions\doregisterparoptions
471 \global\positioningtrue}
472
473\permanent\protected\lettonothing\disableparpositions
474\permanent\protected\lettonothing\registerparoptions
475
476\permanent\protected\def\doregisterparoptions
477 {\iftrialtypesetting \orelse\ifinpagebody \orelse\ifmmode \orelse\ifinformula \else
478 \anch_positions_register_par_options
479 \fi}
480
481\def\anch_positions_register_par_options_normal
482 {\dontleavehmode\clf_parpos}
483
484\def\anch_positions_register_par_options_traced
485 {\anch_positions_register_par_options_normal
486 \begingroup
487 \setbox\scratchbox\hpack
488 {\hss
489 \startcolor[blue]
490 \hpack \s!yoffset 2\onepoint to \zeropoint
491 {\hss\infofont\the\c_anch_positions_paragraph\hskip2\onepoint}
492 \vrule
493 \s!width 4\onepoint
494 \s!height2\onepoint
495 \s!depth 2\onepoint
496 \stopcolor
497 \hss}
498 \smashbox\scratchbox
499 \boxxoffset\scratchbox2\onepoint
500 \box\scratchbox
501 \endgroup}
502
503\let\anch_positions_register_par_options\anch_positions_register_par_options_normal
504
505\appendtoks
506 \let\anch_positions_register_par_options\anch_positions_register_par_options_traced
507\to \t_anch_positions_tracers
508
509\protected\def\anch_positions_trace#1#2#3
510 {\smashedhbox
511 {#1{\infofont#2#3}
512 \kern\onepoint
513 \vrule\s!width2\onepoint\s!height\halfapoint\s!depth\halfapoint}}
514
515\protected\def\anch_positions_trace_left_indeed
516 {\anch_positions_trace\llap\darkmagenta{\currentposition>}}
517
518\protected\def\anch_positions_trace_right_indeed
519 {\anch_positions_trace\rlap\darkcyan{<\currentposition}}
520
521\let\anch_positions_trace_left \relax
522\let\anch_positions_trace_right\relax
523
524\appendtoks
525 \let\anch_positions_trace_left \anch_positions_trace_left_indeed
526 \let\anch_positions_trace_right \anch_positions_trace_right_indeed
527\to \t_anch_positions_tracers
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545\aliased\let\doifoverlappingelse\doifelseoverlapping
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567\aliased\let\doifpositionsonsamepageelse\doifelsepositionsonsamepage
568\aliased\let\doifpositionsonthispageelse\doifelsepositionsonthispage
569\aliased\let\doifpositionsusedelse \doifelsepositionsused
570
571
572
573
574
575
576
577\protect \endinput
578 |