mp-apos.mpiv /size: 3492 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=mp-apos.mpiv,
3%D        version=2012.02.19, % was mp-core: 1999.08.01, anchoring
4%D          title=\CONTEXT\ \METAPOST\ graphics,
5%D       subtitle=anchored background macros,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14if known context_apos : endinput ; fi ;
15
16boolean context_apos ; context_apos := true ;
17
18path    posboxes[],
19        posregions[] ;
20
21numeric multipages[],
22        nofposboxes ;
23
24nofposboxes := 0 ;
25
26def boxlineoptions = withcolor .8blue  enddef ;
27def boxfilloptions = withcolor .8white enddef ;
28
29def connect_positions =
30    if nofposboxes = 2 :
31        pickup pencircle scaled boxlinewidth ;
32        path pa ; pa := posboxes[1] enlarged boxlineoffset ;
33        path pb ; pb := posboxes[2] enlarged boxlineoffset ;
34        if pospages[1] = pospages[2] :
35            draw posboxes[1]  boxlineoptions ;
36            path pc ; pc := center pa {up} .. {down} center pb ;
37            pair cc ; cc := (pc intersection_point pa) ;
38            if intersection_found :
39                pc := pc cutbefore cc ;
40                cc := (pc intersection_point pb) ;
41                if intersection_found :
42                    pc := pc cutafter cc ;
43                    drawarrow pc boxlineoptions ;
44                    drawarrow reverse pc boxlineoptions ;
45                fi ;
46            fi ;
47        elseif pospages[1] == RealPageNumber :
48            draw posboxes[1] boxlineoptions ;
49            path pc ; pc := center pa {up} ... {right} urcorner (posregions[1] enlarged (20pt,20pt)) ;
50            pair cc ; cc := (pc intersection_point pa) ;
51            if intersection_found :
52                pc := pc cutbefore cc ;
53                drawarrow pc boxlineoptions ;
54            fi ;
55        elseif pospages[2] == RealPageNumber :
56            draw posboxes[2] boxlineoptions ;
57            path pc ; pc := ulcorner (posregions[2] enlarged (20pt,20pt)) {right} ... {down} center pb ;
58            pair cc ; cc := (pc intersection_point pb) ;
59            if intersection_found :
60                pc := pc cutafter cc ;
61                drawarrow pc boxlineoptions ;
62            fi ;
63        fi ;
64    fi ;
65enddef ;
66
67% anch-bar:
68
69def anch_sidebars_draw (expr p_b_self, p_e_self, y_b_self, y_e_self, h_b_self, d_e_self,
70        x, y, w, h, alternative, distance, linewidth, linecolor, topoffset, bottomoffset) =
71    % beware, we anchor at (x,y)
72    begingroup ;
73    if alternative = 1 :
74        interim linecap := rounded ;
75    else :
76        interim linecap := butt ;
77    fi ;
78    save a, b ; pair a, b ;
79    if p_b_self = p_e_self :
80        a := (-distance,y_b_self+h_b_self-y) ;
81        b := (-distance,y_e_self-d_e_self-y) ;
82    elseif RealPageNumber = p_b_self :
83        a := (-distance,y_b_self+h_b_self-y) ;
84        b := (-distance,0) ;
85    elseif RealPageNumber = p_e_self :
86        a := (-distance,h) ;
87        b := (-distance,y_e_self-d_e_self-y) ;
88    else :
89        a := (-distance,h) ;
90        b := (-distance,0) ;
91    fi ;
92    a := (xpart a, min(ypart a + topoffset,   h)) ;
93    b := (xpart b, max(ypart b - bottomoffset,0)) ;
94    draw
95        a -- b
96        if alternative = 1 :
97            dashed (withdots scaled (linewidth/2))
98        fi
99        withpen pencircle scaled linewidth
100        withcolor linecolor ;
101    endgroup ;
102enddef ;
103