%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\OTRONEsethsize%
  {\global\hsize=\tekstbreedte}

\def\OTRONEsetvsize%
  {\ifdim\vsize=\teksthoogte \else
     \bgroup
     \scratchdimen=-\vsize
     \advance\scratchdimen by \teksthoogte
     \global\advance\vsize by \scratchdimen
     \ifdim\pagegoal<\maxdimen
       \advance\scratchdimen by \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
      \ifdim\ht\footins>\!!zeropoint % beter dan \ifvoid\footins\else
        \kern\skip\footins
        \kern\ht\footins
      \fi}%
   \ifbottomnotes
     \ifgridsnapping
       \getnoflines\teksthoogte
       \advance\noflines by -1
       \scratchdimen=\noflines\lineheight
       \advance\scratchdimen by \topskip
     \else
       \scratchdimen=\ht0
     \fi
   \else
     \scratchdimen=\!!zeropoint
   \fi
   \setbox2=\hbox
     {\ifvoid\savedfootins \else
        \setbox\footins=\box\savedfootins
      \fi
      \lower\scratchdimen\vbox{\placefootnotes}}%
   \smashbox2% % needed here 
   \ifbottomnotes
     \ht0=\!!zeropoint
   \fi
   \vbox to \teksthoogte
     {\box0\box2\ifbottomnotes\else\vfill\fi}%
   \egroup}

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

\def\OTRONEsetfootnotehsize%
  {\hsize\@@vnbreedte}

\OTRONEoutput%
  {\sidefloatoutput} 

%D Insertions 

\newif\iftopofinsert 

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

\def\OTRONEdodosettopinserts%
  {\ifnum\noffloatinserts<\noftopfloats
     \dogetfloat
     \ifdim\topinserted=\!!zeropoint\relax
       \topofinserttrue
     \else
       \topofinsertfalse
     \fi
     \global\advance\topinserted by \ht\floatbox
     \global\advance\topinserted by \dp\floatbox
     \global\advance\topinserted by \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 by 1
       \else
         \noffloatinserts=\noftopfloats\relax
       \fi
       \dofloatflushedinfo
     \else
       \doresavefloat
       \noffloatinserts=\noftopfloats\relax
     \fi
   \else
     \ifsomefloatwaiting
       \showmessage{\m!floatblocks}{6}{\the\noftopfloats}%
     \fi
     \let\OTRONEdodosettopinserts=\relax
   \fi
   \OTRONEdodosettopinserts}

\def\OTRONEdosetbotinserts%
  {\bgroup
   \ifsomefloatwaiting
     \noffloatinserts=0
     \OTRONEdodosetbotinserts
   \fi
   \egroup}

\def\OTRONEdodosetbotinserts%
  {\ifnum\noffloatinserts<\nofbotfloats\relax
     \dogetfloat
     \global\advance\botinserted by \ht\floatbox\relax
     \global\advance\botinserted by \dp\floatbox\relax
     \global\advance\botinserted by \floattopskip\relax
     \ifdim\botinserted<\pagegoal\relax
       \insert\botins
         {\forgetall
          \blanko[\@@bkvoorwit]%
          \flushfloatbox}%
       \ifsomefloatwaiting
         \advance\noffloatinserts by 1
       \else
         \noffloatinserts=\nofbotfloats
       \fi
       \dofloatflushedinfo
     \else
       \doresavefloat
       \noffloatinserts=\nofbotfloats\relax
     \fi
     \global\nofloatpermittedtrue % vgl topfloats s!
   \else
     \ifsomefloatwaiting
       \showmessage{\m!floatblocks}{7}{\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\relax}

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

\def\OTRONEdoflushfloats%
  {\global\flushingfloatstrue
   \ifsomefloatwaiting
     \par
     \ifvmode\prevdepth=\maxdimen\fi % prevents whitespace
     \OTRONEdodoflushfloats
   \fi
   \global\savednoffloats=0
   \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 by 1em % variable 
            \advance\!!widtha by \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 by \ht\floatbox
     \advance\dimen0 by \dp\floatbox
     \advance\dimen0 by \floattopskip
     \advance\dimen0 by -\pageshrink  % toegevoegd
%\message{c:\the\mofcolumns,t:\the\pagetotal,g:\the\pagegoal}%\wait
     \ifdim\dimen0>\pagegoal
       \global\roomforfloatfalse
     \else
       \global\roomforfloattrue
     \fi
   \fi}

\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!floatblocks}{9}{}%
   \someherefloat}

\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!inmarge=>{\doinmargenormal\leftmarginfloat
                        \rightmarginfloat{\box\floatbox}}]%
     \doifinset{\v!lang}{#1}
       {\flushsidefloatsafterpar}%
   \fi}

\def\OTRONEsomepagefloat[#1]%  links, rechts, midden, hoog, midden, laag
  {\checkwaitingfloats{#1}%
   \vbox to \teksthoogte
     {\doifnotinset{\v!hoog}{#1}{\vfill}%
      \box\floatbox
      \doifnotinset{\v!laag}{#1}{\vfill}}%
   \doinsertfloatinfo
   \pagina}                      % toegevoegd

\def\OTRONEsometopsfloat[#1]%
  {\ifdim\topinserted=\!!zeropoint\relax
     \topofinserttrue
   \else
     \topofinsertfalse
   \fi
   \global\advance\topinserted by \ht\floatbox
   \global\advance\topinserted by \dp\floatbox
   \global\advance\topinserted by \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 by \ht\floatbox
   \global\advance\botinserted by \dp\floatbox
   \global\advance\botinserted by \floattopskip
   \insert\botins
     {\forgetall
      \blanko[\@@bkvoorwit]%
      \flushfloatbox}%
   %\global\nofloatpermittedtrue
   \doinsertfloatinfo}

\protect \endinput 
