summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/anch-snc.mkxl
blob: 5f0246155e82bc984287ac05bfdf2a93fd1d08c1 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
%D \module
%D   [       file=anch-snc,
%D        version=2003.12.01, % actually 1999 so real old
%D          title=\CONTEXT\ Anchoring Macros,
%D       subtitle=Synchronization,
%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.

%D The original is in the mkii file. It does more at the \TEX\ end and
%D has some more magic. If we really need that I'll add it. After all,
%D in mkiv we can do things different.

%D TODO: bleed : + left , minus right oro check if it touches page ... autobleed

\writestatus{loading}{ConTeXt Anchoring Macros / Synchronization}

\registerctxluafile{anch-snc}{}

\unprotect

\ifx\??syncposcounter\undefined \installcorenamespace{syncposcounter} \fi
\ifx\s!syncpos       \undefined \def\s!syncpos       {syncpos}        \fi

\let\c_sync_n\relax

\unexpanded\def\definesyncpositions[#1]%
  {\ifcsname\??syncposcounter:#1\endcsname \else
     \expandafter\newcount\csname\??syncposcounter:#1\endcsname
   \fi}

\unexpanded\def\syncposition
  {\dodoubleempty\anch_sync_position}

\def\anch_sync_position[#1][#2]% we could actually use par positions
  {\dontleavehmode
   \ifcsname\??syncposcounter:#1\endcsname
     \let\c_sync_n\lastnamedcs
     \global\advance\c_sync_n\plusone
     \enabletextarearegistration
     \setpositionplus{\s!syncpos:#1:\the\c_sync_n}{#2}\hpack{\strut}%
   \else
     \strut
   \fi
   \ignorespaces}

\protect

\continueifinputfile{anch-snc.mkiv}

\starttext

% \setuppapersize[A4][A3]

\setuplayout[location=middle]

\setupbodyfont[dejavu]

\definesyncpositions[1]
\definesyncpositions[2]

% \enabletrackers[metapost.lua]

\startMPdefinitions
    input "mp-asnc.mpiv" ;

    SetSyncColor(1,0,"magenta") ;
    SetSyncColor(1,1,"red") ;
    SetSyncColor(1,2,"green") ;
    SetSyncColor(1,3,"blue") ;
    SetSyncColor(1,4,"yellow") ;

    SetSyncColor(2,0,"magenta") ;
    SetSyncColor(2,1,"red") ;
    SetSyncColor(2,2,"green") ;
    SetSyncColor(2,3,"blue") ;
    SetSyncColor(2,4,"yellow") ;
\stopMPdefinitions

\startuseMPgraphic{sync1}
    StartPage ;
        StartSync(1) ;
            SyncHOffset := 0 ;
            SyncWidth   := BackSpace - LeftMarginDistance;
            CollectSyncDataPage ;
         %  ExtendSyncPaths ;  % to top of text area
            PruneSyncPaths ;   % clip top / bottom
            CollapseSyncPaths ;
            MakeSyncPaths ;
          % DrawSyncPaths ;
            FillSyncPaths ;
        StopSync ;
        clip currentpicture to Page ;
        setbounds currentpicture to Page ;
    StopPage ;
\stopuseMPgraphic

\startuseMPgraphic{sync2}
    StartSync(2) ;
        SyncHOffset := -1cm ;
        SyncWidth   :=  1cm ;
        CollectSyncDataRegion(OverlayRegion) ;
        ExtendSyncPaths ;  % to top of text area
        MakeSyncPaths ;
        FillSyncPaths ;
    StopSync ;
    clip currentpicture to OverlayBox leftenlarged 1cm;
    setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\defineoverlay[tempoverlay1][\useMPgraphic{sync1}]
\defineoverlay[tempoverlay2][\useMPgraphic{sync2}]

\setupbackgrounds[page][background=tempoverlay1]

\framed[region=yes,background=tempoverlay2,width=14cm,align=normal]{
    \syncposition[2][1]\samplefile{ward}\endgraf
    \syncposition[2][2]\samplefile{ward}\endgraf
    \syncposition[2][3]\samplefile{ward}\endgraf
}


\vskip1cm \hskip1cm \framed[region=yes,background=tempoverlay2,width=16cm,align=normal]{
    \syncposition[2][1]\samplefile{ward}\endgraf
    \syncposition[2][2]\samplefile{ward}\endgraf
    \syncposition[2][3]\samplefile{ward}\endgraf
}

\vskip1cm \hskip1cm \framed[region=yes,background=tempoverlay2,width=10cm,align=normal]{
    \syncposition[2][1]\samplefile{ward}\endgraf
    \syncposition[2][2]\samplefile{ward}\endgraf
    \syncposition[2][3]\samplefile{ward}\endgraf
}


\dorecurse {100} {
% \dorecurse {1} {
    \startchapter[title={Test #1}]
        \syncposition[1][1,reset]\dorecurse{20}{\samplefile{ward}\endgraf}
        \syncposition[1][2]\dorecurse {4}{\samplefile{ward}\endgraf}
        \syncposition[1][3]\dorecurse {7}{\samplefile{ward}\endgraf}
        \syncposition[1][4]\dorecurse {3}{\samplefile{ward}\endgraf}
    \stopchapter
}

\dorecurse {100} {
% \dorecurse {1} {
    \startchapter[title={Test #1}]
        \syncposition[1][1]\dorecurse{1}{\samplefile{ward}\endgraf}
        \syncposition[1][2]\dorecurse{1}{\samplefile{ward}\endgraf}
        \syncposition[1][3]\dorecurse{1}{\samplefile{ward}\endgraf}
        \syncposition[1][4]\dorecurse{1}{\samplefile{ward}\endgraf}
    \stopchapter
}

\stoptext