summaryrefslogtreecommitdiff
path: root/metapost/context/base/mpiv/mp-apos.mpiv
blob: 7b77377545a2d7bac2f3eab4c87cc7c42640a066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
58
59
60
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
95
96
97
98
99
100
101
102
%D \module
%D   [       file=mp-apos.mpiv,
%D        version=2012.02.19, % was mp-core: 1999.08.01, anchoring
%D          title=\CONTEXT\ \METAPOST\ graphics,
%D       subtitle=anchored background macros,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

if known context_apos : endinput ; fi ;

boolean context_apos ; context_apos := true ;

path    posboxes[],
        posregions[] ;

numeric multipages[],
        nofposboxes ;

nofposboxes := 0 ;

def boxlineoptions = withcolor .8blue  enddef ;
def boxfilloptions = withcolor .8white enddef ;

def connect_positions =
    if nofposboxes = 2 :
        pickup pencircle scaled boxlinewidth ;
        path pa ; pa := posboxes[1] enlarged boxlineoffset ;
        path pb ; pb := posboxes[2] enlarged boxlineoffset ;
        if pospages[1] = pospages[2] :
            draw posboxes[1]  boxlineoptions ;
            path pc ; pc := center pa {up} .. {down} center pb ;
            pair cc ; cc := (pc intersection_point pa) ;
            if intersection_found :
                pc := pc cutbefore cc ;
                cc := (pc intersection_point pb) ;
                if intersection_found :
                    pc := pc cutafter cc ;
                    drawarrow pc boxlineoptions ;
                    drawarrow reverse pc boxlineoptions ;
                fi ;
            fi ;
        elseif pospages[1] == RealPageNumber :
            draw posboxes[1] boxlineoptions ;
            path pc ; pc := center pa {up} ... {right} urcorner (posregions[1] enlarged (20pt,20pt)) ;
            pair cc ; cc := (pc intersection_point pa) ;
            if intersection_found :
                pc := pc cutbefore cc ;
                drawarrow pc boxlineoptions ;
            fi ;
        elseif pospages[2] == RealPageNumber :
            draw posboxes[2] boxlineoptions ;
            path pc ; pc := ulcorner (posregions[2] enlarged (20pt,20pt)) {right} ... {down} center pb ;
            pair cc ; cc := (pc intersection_point pb) ;
            if intersection_found :
                pc := pc cutafter cc ;
                drawarrow pc boxlineoptions ;
            fi ;
        fi ;
    fi ;
enddef ;

% anch-bar:

def anch_sidebars_draw (expr p_b_self, p_e_self, y_b_self, y_e_self, h_b_self, d_e_self,
        x, y, w, h, alternative, distance, linewidth, linecolor, topoffset, bottomoffset) =
    % beware, we anchor at (x,y)
    begingroup ;
    if alternative = 1 :
        interim linecap := rounded ;
    else :
        interim linecap := butt ;
    fi ;
    save a, b ; pair a, b ;
    if p_b_self = p_e_self :
        a := (-distance,y_b_self+h_b_self-y) ;
        b := (-distance,y_e_self-d_e_self-y) ;
    elseif RealPageNumber = p_b_self :
        a := (-distance,y_b_self+h_b_self-y) ;
        b := (-distance,0) ;
    elseif RealPageNumber = p_e_self :
        a := (-distance,h) ;
        b := (-distance,y_e_self-d_e_self-y) ;
    else :
        a := (-distance,h) ;
        b := (-distance,0) ;
    fi ;
    a := (xpart a, min(ypart a + topoffset,   h)) ;
    b := (xpart b, max(ypart b - bottomoffset,0)) ;
    draw
        a -- b
        if alternative = 1 :
            dashed (withdots scaled (linewidth/2))
        fi
        withpen pencircle scaled linewidth
        withcolor linecolor ;
    endgroup ;
enddef ;