%D \module
%D   [       file=page-one,
%D        version=2000.10.20,
%D          title=\CONTEXT\ OTR Macros,
%D       subtitle=Default Routine,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{Context OTR Macros / Default Routine} 

%D This is just the good old \CONTEXT\ output routine, which 
%D has been there right from the start. 

\unprotect 

% OTRONE: basic single column

\activateotr{ONE}{} % the default one 

\newtoks\OTRONEoutput

\def\OTRONEgotonextpage
  {\ejectpage}

\def\OTRONEgotonextpageX % will become obsolete 
  {\superejectpage}

\def\OTRONEsethsize
  {\global\hsize\tekstbreedte}

\def\OTRONEsetvsize
  {\ifdim\vsize=\teksthoogte \else
     \bgroup
     \scratchdimen-\vsize
     \advance\scratchdimen \teksthoogte
     \global\advance\vsize \scratchdimen
     \relax
     \ifdim\pagegoal<\maxdimen
       \advance\scratchdimen \pagegoal
       \global\pagegoal\scratchdimen
     \fi
     \egroup
   \fi}

% \def\OTRONEdopagecontents#1#2% \box<n> \unvbox<n> 
%   {\bgroup             % niet breedte zetten, kan fractie zijn! 
%    \setbox0\vbox \ifbottomnotes to \teksthoogte \fi
%      {\edef\currentpagedepth{\the\dp#2}% still to be derived from #1
%       \dotopinsertions
%       #1#2% 
%       \pushcolor
%       \ifgridsnapping
%         \vskip-\currentpagedepth
%         \vskip\openstrutdepth % \dp\strutbox
%         \prevdepth\openstrutdepth % \dp\strutbox
%         \dobotinsertions
%         \vfil
%       \else\ifr@ggedbottom
%         \vskip-\currentpagedepth
%         \vskip\openstrutdepth % \dp\strutbox
%         \prevdepth\openstrutdepth % \dp\strutbox
%         \dobotinsertions
%         \vfil
%       \else\ifb@selinebottom
%         \kern-\currentpagedepth
%         \kern\maxdepth
%         \dobotinsertions
%       \fi\fi\fi
%       \fakefootnotes}%
%    \ifbottomnotes
%      \ifgridsnapping
%        \getnoflines\teksthoogte
%        \advance\noflines -1
%        \scratchdimen\noflines\lineheight
%        \advance\scratchdimen \topskip
%      \else
%        \scratchdimen\ht0
%      \fi
%    \else
%      \scratchdimen\zeropoint
%    \fi
%    \setbox2\hbox
%      {\checksinglecolumnfootnotes
%       \lower\scratchdimen\vbox{\placebottomnotes}}%
%    \smashbox2% % needed here 
%    \ifbottomnotes
%      \ht0\zeropoint
%    \fi
%    \vbox to \teksthoogte
%      {\box0\box2\ifbottomnotes\else\vfill\fi}%
%    \egroup}

%\def\OTRONEregisteredtextarea#1#2#3%
%  {\ifregistertextareas
%     % sub optimal, unvbox is nilled here 
%     \setbox#2\vbox{#1#2}% 
%     \wd#2\zetbreedte % somehow a space creeps in (in unvbox'd #2)
%     \vbox{\registeredtextarea00#2}% 
%     #3%
%   \else
%     #1#2#3%
%   \fi}

\chardef\kindofpagetextareas=2 % whole page

\def\OTRONEregisteredtextarea#1%
  {\ifregistertextareas
     \setbox0\vbox{#1}%
     \wd0\zetbreedte % somehow a space creeps in
     \vbox{\registeredtextarea000}%
   \else
     #1%
   \fi}

\let\OTRONEregisteredtextareaA\firstofoneargument
\let\OTRONEregisteredtextareaB\firstofoneargument

\def\OTRONEdopagecontents#1#2% \box<n> \unvbox<n>
  {\bgroup             % niet breedte zetten, kan fractie zijn!
   \ifcase\kindofpagetextareas
   \or % partial page
     \let\OTRONEregisteredtextareaA\OTRONEregisteredtextarea
   \or % whole page
     \let\OTRONEregisteredtextareaB\OTRONEregisteredtextarea
   \fi
   \setbox0\vbox \ifbottomnotes to \teksthoogte \fi
     {\edef\currentpagedepth{\the\dp#2}% still to be derived from #1
      \dotopinsertions
      \ifgridsnapping
        \OTRONEregisteredtextareaA{#1#2}%
        \vskip-\currentpagedepth\vskip\openstrutdepth
        \pushcolor % moved from just after #1#2
        \prevdepth\openstrutdepth
        \dobotinsertions
        \vfil
      \else\ifr@ggedbottom
        \OTRONEregisteredtextareaA{#1#2}%
        \vskip-\currentpagedepth\vskip\openstrutdepth
        \pushcolor % moved from just after #1#2
        \prevdepth\openstrutdepth
        \dobotinsertions
        \vfil
      \else\ifb@selinebottom
        \OTRONEregisteredtextareaA{#1#2}%
        \kern-\currentpagedepth\kern\maxdepth
        \pushcolor % moved from just after #1#2
        \dobotinsertions
      \else
        \OTRONEregisteredtextareaA{#1#2}%
        \pushcolor % moved from just after #1#2
        \dobotinsertions % added
      \fi\fi\fi
      \fakefootnotes}%
   \ifbottomnotes
     \ifgridsnapping
       \getnoflines\teksthoogte
       \advance\noflines \minusone
       \scratchdimen\noflines\lineheight
       \advance\scratchdimen \topskip
     \else
       \scratchdimen\ht0
     \fi
   \else
     \scratchdimen\zeropoint
   \fi
   \setbox2\hbox
     {\checksinglecolumnfootnotes
      \lower\scratchdimen\vbox{\placebottomnotes}}%
   \smashbox2% % needed here
   \ifbottomnotes
     \ht0\zeropoint
   \fi
   \OTRONEregisteredtextareaB
     {\vbox to \teksthoogte
        {\box0\box2\ifbottomnotes\else\vfill\fi}}%
   \egroup}

\def\OTRONEfinalsidefloatoutput
  {\finaloutput\unvbox\normalpagebox}

\OTRONEoutput
  {\sidefloatoutput} 

%D Insertions 

\newif\iftopofinsert 

\def\OTRONEdosettopinserts
  {\bgroup
   \ifsomefloatwaiting
     \noffloatinserts\zerocount
     \let\totaltopinserted\!!zeropoint
     \OTRONEdodosettopinserts
     \ifnum\@@bknonder=\zerocount
       \ifnum\@@bknregels>\zerocount
         \ifdim\totaltopinserted>\zeropoint\relax
           \dimen0=\lineheight
           \dimen0=\@@bknregels\dimen0
           \advance\dimen0 \totaltopinserted\relax
           \ifdim\dimen0>\teksthoogte
             \showmessage\m!floatblocks8\@@bknregels
             \vfilll\eject
           \fi
         \fi
       \fi
     \fi
   \fi
   \egroup}

\def\OTRONEdodosettopinserts
  {\ifnum\noffloatinserts<\noftopfloats
     \dogetfloat
     \ifdim\topinserted=\zeropoint
       \topofinserttrue
     \else
       \topofinsertfalse
     \fi
     \global\advance\topinserted \ht\floatbox
     \global\advance\topinserted \dp\floatbox
     \global\advance\topinserted \floatbottomskip\relax
     \ifdim\topinserted<\teksthoogte\relax
       \xdef\totaltopinserted{\the\topinserted}%
       \insert\topins
         {\forgetall
          \iftopofinsert
            \kern-\lineskip\par
            \prevdepth\maxdimen
          \else
            %\blanko[-\@@bknawit,\@@bkvoorwit]% inserts can't look back
            \betweenfloatblanko
          \fi
          \flushfloatbox
          \blanko[\@@bknawit]}%
       \ifsomefloatwaiting
         \advance\noffloatinserts \plusone
       \else
         \noffloatinserts\noftopfloats\relax
       \fi
       \dofloatflushedinfo
     \else
       \doresavefloat
       \noffloatinserts\noftopfloats\relax
     \fi
   \else
     \ifsomefloatwaiting
       \showmessage\m!floatblocks6{\the\noftopfloats}%
     \fi
     \let\OTRONEdodosettopinserts\relax
   \fi
   \OTRONEdodosettopinserts}

\def\OTRONEdosetbotinserts
  {\bgroup
   \ifsomefloatwaiting
     \noffloatinserts\zerocount
     \OTRONEdodosetbotinserts
   \fi
   \egroup}

\def\OTRONEdodosetbotinserts
  {\ifnum\noffloatinserts<\nofbotfloats\relax
     \dogetfloat
     \global\advance\botinserted \ht\floatbox\relax
     \global\advance\botinserted \dp\floatbox\relax
     \global\advance\botinserted \floattopskip\relax
     \ifdim\botinserted<\pagegoal\relax
       \insert\botins
         {\forgetall
          \blanko[\@@bkvoorwit]%
          \flushfloatbox}%
       \ifsomefloatwaiting
         \advance\noffloatinserts \plusone
       \else
         \noffloatinserts\nofbotfloats
       \fi
       \dofloatflushedinfo
     \else
       \doresavefloat
       \noffloatinserts\nofbotfloats\relax
     \fi
     \global\nofloatpermittedtrue % vgl topfloats s!
   \else
     \ifsomefloatwaiting
       \showmessage\m!floatblocks7{\the\nofbotfloats}%
     \fi
     \let\OTRONEdodosetbotinserts\relax
   \fi
   \OTRONEdodosetbotinserts}

\def\OTRONEdosetbothinserts
  {\ifflushingfloats
     \global\topinserted\zeropoint
     \global\botinserted\zeropoint 
   \else
     \global\topinserted\zeropoint \OTRONEdosettopinserts
     \global\botinserted\zeropoint \OTRONEdosetbotinserts
   \fi}

\def\OTRONEdotopinsertions
  {\ifvoid\topins\else
     \ifgridsnapping
       %\topsnaptogrid{\box\topins}
       \box\topins % already snapped
     \else
       \unvbox\topins
     \fi
   \fi
   \global\topinserted\zeropoint}

\def\OTRONEdobotinsertions
  {\ifvoid\botins\else
     \ifgridsnapping
       \snaptogrid\hbox{\box\botins}%
     \else
       \unvbox\botins
     \fi
   \fi
   \global\botinserted\zeropoint
   \global\nofloatpermittedfalse}

\def\OTRONEdoflushfloats
  {\global\flushingfloatstrue
   \ifsomefloatwaiting
     \par
     \ifvmode \prevdepth\maxdimen \fi % prevents whitespace
     \OTRONEdodoflushfloats
   \fi
   \global\savednoffloats\zerocount
   \global\somefloatwaitingfalse
   \global\flushingfloatsfalse}

\def\OTRONEflushfloatbox % nog verder doorvoeren en meer info in marge
  {\ifcenterfloatbox \ifdim\wd\floatbox<\hsize
     \setbox\floatbox\hbox to \hsize{\hss\box\floatbox\hss}%
   \fi \fi
   \snaptogrid\hbox{\iftestfloatbox\ruledhbox\fi{\copy\floatbox}}}

% \def\OTRONEdodoflushfloats % moet nog beter: als precies passend, niet onder baseline
%   {\ifsomefloatwaiting
%      \bgroup % \box\floatbox can be in use!
%      \dogetfloat
%      \doplacefloatbox
%      \egroup
%      \dofloatflushedinfo
%      \expandafter\OTRONEdodoflushfloats
%    \fi}

\def\OTRONEdodoflushfloats % much in common with OTRSET
  {\ifsomefloatwaiting
     \ifpackflushedfloats
       \centerfloatboxfalse
       \dogetfloat
       \ifdim\wd\floatbox>\zetbreedte 
         \global\setbox\floatbox\hbox to \zetbreedte{\hss\box\floatbox\hss}%
       \fi
       \OTRONEsetvsize
       \!!widtha\wd\floatbox
       \dofloatflushedinfo
       \doloop
         {\ifsomefloatwaiting 
            \dosavefloatstatus
            \dogetfloat
            \advance\!!widtha 1em % variable 
            \advance\!!widtha \wd\floatbox\relax
            \ifdim\!!widtha>\hsize
              \dorestorefloatstatus
              \global\somefloatwaitingtrue
              \exitloop
            \else
              \global\setbox\floatbox\hbox
                {\ifcase\columndirection % nog document wide
                   \ifvoid\savedfloatbox\else
                     \ifhbox\savedfloatbox\unhbox\else\box\fi\savedfloatbox\hfil 
                   \fi
                   \ifhbox\floatbox\unhbox\else\box\fi\floatbox
                 \else
                   \ifhbox\floatbox\unhbox\else\box\fi\floatbox
                   \ifvoid\savedfloatbox\else
                     \hfil\ifhbox\savedfloatbox\unhbox\else\box\fi\savedfloatbox
                   \fi
                 \fi}%
              \dofloatflushedinfo
            \fi
          \else 
            \exitloop 
          \fi}%
       \global\setbox\floatbox\hbox to \hsize
         {\hfil\ifhbox\floatbox\unhbox\else\box\fi\floatbox\hfil}%
     \else
      %\bgroup % \box\floatbox can be in use!? messy 
       \dogetfloat
      %\doplacefloatbox
      %\egroup
       \dofloatflushedinfo
     \fi
     \doplacefloatbox
     \expandafter\OTRONEdodoflushfloats
   \fi}
 
\def\OTRONEdocheckiffloatfits % vervangen ivm downward comp
  {\ifnofloatpermitted
     \global\roomforfloatfalse
   \else
     \dimen0         \pagetotal
     \advance\dimen0 \ht\floatbox
     \advance\dimen0 \dp\floatbox
     \advance\dimen0 \floattopskip
     \advance\dimen0 -\pageshrink  % toegevoegd
    %\message{c:\the\mofcolumns,t:\the\pagetotal,g:\the\pagegoal}%\wait
     \ifdim\dimen0>\pagegoal
       \global\roomforfloatfalse
     \else
       \global\roomforfloattrue
     \fi
   \fi}

\def\OTRONEflushsavedfloats
  {\dosetbothinserts}

\def\OTRONEsomeherefloat[#1]% spacing between two successive must be better
  {\baselinecorrection
   \doplacefloatbox
   \doinsertfloatinfo
   \doif\@@bkspringvolgendein\v!nee\noindentation} % new 

\def\OTRONEsomefixdfloat % [#1]
  {\docheckiffloatfits
   \ifroomforfloat\else
     \goodbreak
   \fi
   \showmessage\m!floatblocks9\empty
   \someherefloat} % [#1]

\def\OTRONEsomesidefloat[#1]%  links, rechts     NOG TESTEN EN AANPASSEN
  {\ifbinnenkolommen
     \someelsefloat[\v!hier]%
   \else
    %\checkwaitingfloats{#1}%
     \def\logsidefloat
       {\doinsertfloatinfo}%
     \setbox\floatbox\vbox{\box\floatbox}%
     \wd\floatbox\floatwidth
     \processfirstactioninset
       [#1]
       [     \v!links=>\leftfloat{\box\floatbox},
            \v!rechts=>\rightfloat{\box\floatbox},
          \v!inlinker=>\leftmarginfloat{\box\floatbox},
         \v!inrechter=>\rightmarginfloat{\box\floatbox},
       \v!linkermarge=>\leftmarginfloat{\box\floatbox},
      \v!rechtermarge=>\rightmarginfloat{\box\floatbox},
        \v!linkerrand=>\leftedgefloat{\box\floatbox},
       \v!rechterrand=>\rightedgefloat{\box\floatbox},
           \v!inmarge=>{\doinmargenormal\leftmarginfloat
                        \rightmarginfloat{\box\floatbox}}]%
     \doifinset\v!lang{#1}\flushsidefloatsafterpar
   \fi}

\def\OTRONEsomepagefloat[#1]%  
  {%\checkwaitingfloats{#1}%
   \global\setbox\collectedpagefloats\vbox
     {\unvbox\collectedpagefloats
      \vbox to \teksthoogte
        {\doifnotinset\v!hoog{#1}\vfill
         \box\floatbox
         \doifnotinset\v!laag{#1}\vfill}%
      \goodbreak}%
   \doinsertfloatinfo}

\def\OTRONEsometopsfloat[#1]%
  {\ifdim\topinserted=\zeropoint
     \topofinserttrue
   \else
     \topofinsertfalse
   \fi
   \global\advance\topinserted \ht\floatbox
   \global\advance\topinserted \dp\floatbox
   \global\advance\topinserted \floatbottomskip
   \insert\topins
     {\forgetall
      \iftopofinsert
        \kern-\lineskip\par\prevdepth\maxdimen
      \else
        %\blanko[-\@@bknawit,\@@bkvoorwit]% inserts can't look back
        \betweenfloatblanko
      \fi
      \flushfloatbox
      \blanko[\@@bknawit]}%
   \doinsertfloatinfo}

\def\OTRONEsomebotsfloat[#1]%
  {\global\advance\botinserted \ht\floatbox
   \global\advance\botinserted \dp\floatbox
   \global\advance\botinserted \floattopskip
   \insert\botins
     {\forgetall
      \blanko[\@@bkvoorwit]%
      \flushfloatbox}%
   %\global\nofloatpermittedtrue
   \doinsertfloatinfo}

\def\OTRONEnextcolumn[#1]%
  {}

\protect \endinput 
