summaryrefslogtreecommitdiff
path: root/metapost/context/base/mpxl/mp-apos.mpxl
blob: e3746540f59052774566a7e5c60ebc0e62b51e0b (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
103
104
105
106
107
108
109
110
111
112
%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 metafun_loaded_apos : endinput ; fi ;

newinternal boolean metafun_loaded_apos ; metafun_loaded_apos := true ; immutable metafun_loaded_apos ;

path    posboxes[],
        posregions[] ;

numeric pospages[],
        nofposboxes ;

nofposboxes := 0 ;

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

mutable posboxes, posregions, pospages, nofposboxes ;

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 firstpage, lastpage, yfirst, ylast, height, depth,
        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 firstpage = lastpage :
        a := (-distance,yfirst+height-y) ;
        b := (-distance,ylast-depth-y) ;
    elseif RealPageNumber = firstpage :
        a := (-distance,yfirst+height-y) ;
        b := (-distance,0) ;
    elseif RealPageNumber = lastpage :
        a := (-distance,h) ;
        b := (-distance,ylast-depth-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 ;

% new interface

newscriptindex mfid_getposboxes  ; mfid_getposboxes  := scriptindex "getposboxes" ;
newscriptindex mfid_getmultipars ; mfid_getmultipars := scriptindex "getmultipars" ;

def getposboxes (expr tags, anchor) = runscript mfid_getposboxes  tags anchor ; enddef ;
def getmultipars(expr tags, anchor) = runscript mfid_getmultipars tags anchor ; enddef ;