diff options
Diffstat (limited to 'tex/context/base/mkiv/anch-snc.mkiv')
-rw-r--r-- | tex/context/base/mkiv/anch-snc.mkiv | 272 |
1 files changed, 114 insertions, 158 deletions
diff --git a/tex/context/base/mkiv/anch-snc.mkiv b/tex/context/base/mkiv/anch-snc.mkiv index 3e99da8a6..5f0246155 100644 --- a/tex/context/base/mkiv/anch-snc.mkiv +++ b/tex/context/base/mkiv/anch-snc.mkiv @@ -1,6 +1,6 @@ %D \module %D [ file=anch-snc, -%D version=2003.12.01, +%D version=2003.12.01, % actually 1999 so real old %D title=\CONTEXT\ Anchoring Macros, %D subtitle=Synchronization, %D author=Hans Hagen, @@ -11,151 +11,42 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -% this can be optimized (will do when used again) +%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\s!num \undefined \def\s!num {num} \fi -\ifx\s!set \undefined \def\s!set {set} \fi -\ifx\s!reset \undefined \def\s!reset {reset} \fi -\ifx\s!preset \undefined \def\s!preset {preset} \fi -\ifx\s!syncpos\undefined \def\s!syncpos{syncpos} \fi +\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\s!num:\s!syncpos:#1\endcsname \else - \global\let\flushsyncpositions\doflushsyncpositions % only when used - \global\let\flushsyncresets \doflushsyncresets - \global\let\flushsyncpresets \doflushsyncpresets - \expandafter\newcount\csname\s!num:\s!syncpos:#1\endcsname - \doglobal\appendtoksonce\csname\s!reset :\s!syncpos:#1\endcsname\to\resetsyncpositions - \doglobal\appendtoksonce\csname\s!preset:\s!syncpos:#1\endcsname\to\presetsyncpositions -% to be tested: -% \doglobal\expandafter\appendtoksonce\csname\s!reset :\s!syncpos:#1\endcsname\to\resetsyncpositions -% \doglobal\expandafter\appendtoksonce\csname\s!preset:\s!syncpos:#1\endcsname\to\presetsyncpositions - \setgvalue{\s!syncpos:#1}{sync_n[#1] := 0 ;}% - \setgvalue{\s!set:\s!syncpos:#1}{\dosetsyncpositions{#1}}% + {\ifcsname\??syncposcounter:#1\endcsname \else + \expandafter\newcount\csname\??syncposcounter:#1\endcsname \fi} -\def\syncposition - {\dodoubleempty\dosyncposition} - -\def\dosyncposition[#1][#2]% - {\letgvalue{\s!reset :\s!syncpos:#1}\relax - \letgvalue{\s!preset:\s!syncpos:#1}\relax - \dontleavehmode - \dodosyncposition{#1}{#2}\s!set - \ignorespaces} - -\def\doifelselastsyncposition#1#2% - {\doifelse{\lastsyncclass\lastsyncposition}{#1#2}} - -\let\doiflastsyncpositionelse\doifelselastsyncposition +\unexpanded\def\syncposition + {\dodoubleempty\anch_sync_position} -\def\dodosyncposition#1#2#3% - {\letgvalue{\s!reset:\s!syncpos:#1}\relax - \letgvalue{\s!preset:\s!syncpos:#1}\relax - \ifcsname\s!syncpos:#1\endcsname - \global\advance\csname\s!num:\s!syncpos:#1\endcsname\plusone - \setsyncpositions{#1}% - % option: geen w/h, alleen p 0 0 0 data - \setpositionplus{\s!syncpos:#1:\the\csname\s!num:\s!syncpos:#1\endcsname}{#2}\hpack{\strut}% +\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} - -\def\setsyncpositions#1% - {\enabletextarearegistration - \getvalue {\s!set:\s!syncpos:#1}% - \letgvalue{\s!set:\s!syncpos:#1}\relax} - -\def\dosetsyncpositions#1% - {\startnointerference % removing out of sync can best be done in mp - \!!dimena\maxdimen - \!!counta\zerocount - \!!countc\zerocount - \doloop - {\doifelseposition{\s!syncpos:#1:\recurselevel} - {\!!dimenb\MPy{\s!syncpos:#1:\recurselevel}\relax - \!!countb\MPp{\s!syncpos:#1:\recurselevel}\relax - \ifnum\!!countb=\!!counta % same page - \ifdim\!!dimenb>\!!dimena - \donefalse % out of order nodes - \else - \donetrue % nodes in order - \fi - \else - \donetrue % different page - \fi - \ifdone - \!!counta\!!countb - \!!dimena\!!dimenb - \advance\!!countc\plusone - \edef\!!stringa{[#1][\the\!!countc]:=}% - \edef\!!stringc{\s!syncpos:#1:\the\!!countc}% - \edef\!!stringd{\MPplus\!!stringc{1}{0}}% - \setxvalue{\s!syncpos:#1}% - {\getsyncpositions{#1}% - sync_p \!!stringa \MPp \!!stringc ; - sync_xy\!!stringa \MPxy\!!stringc ; - sync_w \!!stringa \MPw \!!stringc ; - sync_h \!!stringa \MPh \!!stringc ; - sync_d \!!stringa \MPd \!!stringc ; - \ifx\!!stringd\empty \else sync_t \!!stringa \MPplus\!!stringc{1}{0} ; \fi}% - \fi} - {\setxvalue{\s!syncpos:#1}% - {\getsyncpositions{#1}% - sync_n[#1] := \the\!!countc ;} - \exitloop}}% - \stopnointerference} - -\def\getsyncpositions#1% - {\getvalue{\s!syncpos:#1}} - -\newtoks\resetsyncpositions -\newtoks\presetsyncpositions - -\def\resyncposition {\dodoubleargument\doresyncposition} -\def\presyncposition{\dodoubleargument\dopresyncposition} - -\def\dodoresyncposition #1#2{\dodosyncposition{#1}{#2}\s!reset} -\def\dodopresyncposition#1#2{\dodosyncposition{#1}{#2}\s!preset} - -\def\doresyncposition [#1][#2]{\setxvalue{\s!reset :\s!syncpos:#1}{\noexpand\dodoresyncposition{#1}{#2}}} -\def\dopresyncposition[#1][#2]{\setxvalue{\s!preset:\s!syncpos:#1}{\noexpand\dodopresyncposition{#1}{#2}}} - -\let\flushsyncpositions\relax - -\def\doflushsyncpositions % this order ! - {\begingroup - \the\presetsyncpositions - \the\resetsyncpositions - \endgroup} - -\def\flushsyncxxsets#1% - {\begingroup - \setbox\scratchbox\hbox{\the#1}% - \ifvoid\scratchbox\else - \prewordbreak - %\let\prewordbreak\relax % only once - \smashbox\scratchbox - \box\scratchbox \fi - \endgroup} - -\let\flushsyncresets \relax -\let\flushsyncpresets\relax - -\def\doflushsyncresets {\flushsyncxxsets\resetsyncpositions } -\def\doflushsyncpresets{\flushsyncxxsets\presetsyncpositions} - -% \appendtoks \flushsyncpositions \to \everypar -% \appendtoks \flushsyncpositions \to \everyheadstart - -% \explicitneverypar -> in grid snapper, eerst testen -% -% \appendtoks \flushsyncpositions \to \neverypar + \ignorespaces} \protect @@ -163,41 +54,106 @@ \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{sync} - StartPage ; - \getsyncpositions{1} ; - SyncThreshold := 2LineHeight ; - SyncLeftOffset := -.5LeftMarginDistance ; - % SetSyncThreshold(1,3,3LineHeight) ; - SyncWidth := - (BackSpace + SyncLeftOffset) ; - SetSyncColor(1,1,\MPcolor{red}) ; - SetSyncColor(1,2,\MPcolor{green}) ; - SetSyncColor(1,3,\MPcolor{blue}) ; - SetSyncColor(1,4,\MPcolor{yellow}) ; - PrepareSyncTasks(1,true,true,false) ; - for i = 1 upto NOfSyncPaths : - fill SyncPaths[i] - withcolor TheSyncColor(CurrentSyncClass,sync_t[CurrentSyncClass][SyncTasks[i]]) ; - endfor ; - setbounds currentpicture to Page ; - StopPage ; +\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[tempoverlay][\useMPgraphic{sync}] +\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 +} -\setupbackgrounds[page][background=tempoverlay] -\dorecurse {10} { +\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{10}{\input ward \endgraf} - \syncposition[1][2] \dorecurse {4}{\input ward \endgraf} - \syncposition[1][3] \dorecurse {7}{\input ward \endgraf} - \syncposition[1][4] \dorecurse {3}{\input ward \endgraf} + \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 } |