anch-snc.mkiv /size: 4705 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=anch-snc,
3%D        version=2003.12.01, % actually 1999 so real old
4%D          title=\CONTEXT\ Anchoring Macros,
5%D       subtitle=Synchronization,
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
14%D The original is in the mkii file. It does more at the \TEX\ end and
15%D has some more magic. If we really need that I'll add it. After all,
16%D in mkiv we can do things different.
17
18%D TODO: bleed : + left , minus right oro check if it touches page ... autobleed
19
20\writestatus{loading}{ConTeXt Anchoring Macros / Synchronization}
21
22\registerctxluafile{anch-snc}{}
23
24\unprotect
25
26\ifx\??syncposcounter\undefined \installcorenamespace{syncposcounter} \fi
27\ifx\s!syncpos       \undefined \def\s!syncpos       {syncpos}        \fi
28
29\let\c_sync_n\relax
30
31\unexpanded\def\definesyncpositions[#1]%
32  {\ifcsname\??syncposcounter:#1\endcsname \else
33     \expandafter\newcount\csname\??syncposcounter:#1\endcsname
34   \fi}
35
36\unexpanded\def\syncposition
37  {\dodoubleempty\anch_sync_position}
38
39\def\anch_sync_position[#1][#2]% we could actually use par positions
40  {\dontleavehmode
41   \ifcsname\??syncposcounter:#1\endcsname
42     \let\c_sync_n\lastnamedcs
43     \global\advance\c_sync_n\plusone
44     \enabletextarearegistration
45     \setpositionplus{\s!syncpos:#1:\the\c_sync_n}{#2}\hpack{\strut}%
46   \else
47     \strut
48   \fi
49   \ignorespaces}
50
51\protect
52
53\continueifinputfile{anch-snc.mkiv}
54
55\starttext
56
57% \setuppapersize[A4][A3]
58
59\setuplayout[location=middle]
60
61\setupbodyfont[dejavu]
62
63\definesyncpositions[1]
64\definesyncpositions[2]
65
66% \enabletrackers[metapost.lua]
67
68\startMPdefinitions
69    input "mp-asnc.mpiv" ;
70
71    SetSyncColor(1,0,"magenta") ;
72    SetSyncColor(1,1,"red") ;
73    SetSyncColor(1,2,"green") ;
74    SetSyncColor(1,3,"blue") ;
75    SetSyncColor(1,4,"yellow") ;
76
77    SetSyncColor(2,0,"magenta") ;
78    SetSyncColor(2,1,"red") ;
79    SetSyncColor(2,2,"green") ;
80    SetSyncColor(2,3,"blue") ;
81    SetSyncColor(2,4,"yellow") ;
82\stopMPdefinitions
83
84\startuseMPgraphic{sync1}
85    StartPage ;
86        StartSync(1) ;
87            SyncHOffset := 0 ;
88            SyncWidth   := BackSpace - LeftMarginDistance;
89            CollectSyncDataPage ;
90         %  ExtendSyncPaths ;  % to top of text area
91            PruneSyncPaths ;   % clip top / bottom
92            CollapseSyncPaths ;
93            MakeSyncPaths ;
94          % DrawSyncPaths ;
95            FillSyncPaths ;
96        StopSync ;
97        clip currentpicture to Page ;
98        setbounds currentpicture to Page ;
99    StopPage ;
100\stopuseMPgraphic
101
102\startuseMPgraphic{sync2}
103    StartSync(2) ;
104        SyncHOffset := -1cm ;
105        SyncWidth   :=  1cm ;
106        CollectSyncDataRegion(OverlayRegion) ;
107        ExtendSyncPaths ;  % to top of text area
108        MakeSyncPaths ;
109        FillSyncPaths ;
110    StopSync ;
111    clip currentpicture to OverlayBox leftenlarged 1cm;
112    setbounds currentpicture to OverlayBox ;
113\stopuseMPgraphic
114
115\defineoverlay[tempoverlay1][\useMPgraphic{sync1}]
116\defineoverlay[tempoverlay2][\useMPgraphic{sync2}]
117
118\setupbackgrounds[page][background=tempoverlay1]
119
120\framed[region=yes,background=tempoverlay2,width=14cm,align=normal]{
121    \syncposition[2][1]\samplefile{ward}\endgraf
122    \syncposition[2][2]\samplefile{ward}\endgraf
123    \syncposition[2][3]\samplefile{ward}\endgraf
124}
125
126
127\vskip1cm \hskip1cm \framed[region=yes,background=tempoverlay2,width=16cm,align=normal]{
128    \syncposition[2][1]\samplefile{ward}\endgraf
129    \syncposition[2][2]\samplefile{ward}\endgraf
130    \syncposition[2][3]\samplefile{ward}\endgraf
131}
132
133\vskip1cm \hskip1cm \framed[region=yes,background=tempoverlay2,width=10cm,align=normal]{
134    \syncposition[2][1]\samplefile{ward}\endgraf
135    \syncposition[2][2]\samplefile{ward}\endgraf
136    \syncposition[2][3]\samplefile{ward}\endgraf
137}
138
139
140\dorecurse {100} {
141% \dorecurse {1} {
142    \startchapter[title={Test #1}]
143        \syncposition[1][1,reset]\dorecurse{20}{\samplefile{ward}\endgraf}
144        \syncposition[1][2]\dorecurse {4}{\samplefile{ward}\endgraf}
145        \syncposition[1][3]\dorecurse {7}{\samplefile{ward}\endgraf}
146        \syncposition[1][4]\dorecurse {3}{\samplefile{ward}\endgraf}
147    \stopchapter
148}
149
150\dorecurse {100} {
151% \dorecurse {1} {
152    \startchapter[title={Test #1}]
153        \syncposition[1][1]\dorecurse{1}{\samplefile{ward}\endgraf}
154        \syncposition[1][2]\dorecurse{1}{\samplefile{ward}\endgraf}
155        \syncposition[1][3]\dorecurse{1}{\samplefile{ward}\endgraf}
156        \syncposition[1][4]\dorecurse{1}{\samplefile{ward}\endgraf}
157    \stopchapter
158}
159
160\stoptext
161