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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
\unprotect
% % % NOT ENGLISH % % %
% clean up footnotes to notes
% We need to set the \dimen globally since we are in the
% OTR. Unfortunately this interferes with local settings,
% although we may assume that they will not cross page
% boundaries.
\def\OTRSETcheckcontent
{\bgroup
\donefalse
\def\OTRSETcheckcontent##1%
{\setbox\scratchbox##1\recurselevel
\setbox\scratchbox\vbox{\unvbox\scratchbox}%
\ifdim\ht\scratchbox>\zeropoint\donetrue\fi}%
\dorecurse{\nofcolumns}
{\OTRSETcheckcontent\columngettextbox
\OTRSETcheckcontent\columngetfootbox
\OTRSETcheckcontent\columngettopbox
\OTRSETcheckcontent\columngetbotbox}%
\ifdone\egroup\donefalse\else\egroup\donetrue\fi}
\def\OTRSETgetcolumntextheight#1% max - boven - top
{\scratchdimen=\OTRSETgetparameter\c!maxhoogte#1%
\advance\scratchdimen -\OTRSETgetparameter\c!bovenoffset#1%
\advance\scratchdimen -\ht\columntopbox#1%
\advance\scratchdimen -\getvalue{\??mc\number\mofcolumns-f}%
\advance\scratchdimen -\ht\columnbotbox#1} % not used
\def\OTRSETgetcolumnnaturalheight#1% max - boven - top
{\setbox\scratchbox\vbox{\unvcopy\columntextbox#1}%
\scratchdimen\ht\scratchbox
\advance\scratchdimen \OTRSETgetparameter\c!bovenoffset#1%
\advance\scratchdimen \ht\columntopbox#1%
\advance\scratchdimen -\getvalue{\??mc\number\mofcolumns-f}%
\advance\scratchdimen \ht\columnbotbox#1} % not used
\def\OTRSETdobalance% splitten in met en zonder footnotes
{\bgroup
\maxdeadcycles=1000
% collect content and notes
\bgroup
\OTRSEToutput
{\global\setbox1\vbox{\unvbox\normalpagebox}%
\global\setbox3\vbox{\unvbox\footins}}%
\verticalstrut\vskip-\struttotal % makes footnotes flush
\eject
\global\collectingcontentfalse
% check for footnotes only
\ifdim\ht1<\topskip % real dirty
\global\setbox1=\vbox{}
% fix height of first line
\ifdim\ht3>\!!zeropoint
\global\setbox3\vbox
{\setfootnotebodyfont
\kern-\strutht
\kern\topskip
\unvbox3}
\fi
% prepare trial box
\global\setbox5\vbox
{\ifdim\ht1>\zeropoint
\unvcopy1 \ifdim\ht3>\zeropoint \kern\skip\footins \fi
\fi
\ifdim\ht3>\zeropoint \unvcopy3 \fi}
\egroup
% erase old stuff
\columnerasetextboxes
\columnerasefootboxes
% prepare floats
\OTRSETdotopinsertions
\OTRSETdobotinsertions % not used can be removed
% calculate available space
\!!heighta\zeropoint % available total height
\dorecurse{\nofcolumns}
{\OTRSETgetcolumntextheight\recurselevel
\OTRSETcalculatelines\scratchdimen
\advance\!!heighta \scratchdimen}
% quick check
\ifdim\ht5>\!!heighta
% use normal routine
\columnerasetextboxes
\columnerasefootboxes
% TEMP, TODO, FORCE NEXT PASS !
\unvbox1
\unvbox3
\doglobal\addtocommalist{-\realfolio}\OTRSETbalancinglist
\donefalse
%\writestatus\m!columns{no balancing, text overflows height}%
\else\ifdim\ht5>\zeropoint \relax
% some text and/or notes
\donetrue
\else
\donefalse
\dorecurse\nofcolumns
{\ifdim\ht\columntopbox\recurselevel>\zeropoint \donetrue \fi}%
\ifdone
% no text and notes, but figures
\else
% no text, no notes, no figures
\doglobal\addtocommalist{-\realfolio}\OTRSETbalancinglist
\writestatus\m!columns{no balancing, nothing to be placed}%
\fi
\fi\fi
\ifdone
\ifdim\ht5>\zeropoint \relax
% balancing text and notes
%\writestatus\m!columns{text may fit, balancing}%
\newcounter\loopcounter
\newcounter\balancinglines
\doloop
{\increment\loopcounter\relax
% initialize
\columnerasetextboxes
\columnerasefootboxes
\setbox0=\copy5
\splittopskip\topskip
% pre-split loop and quality calculation
%\writestatus\m!columns{pass \loopcounter: correction -\balancinglines}
\dorecurse\nofcolumns
{\OTRSETgetcolumntextheight\recurselevel
\OTRSETcalculatelines\scratchdimen
\!!heightc\scratchdimen
\ifnum\recurselevel<\nofcolumns
\advance\!!heightc -\balancinglines\lineheight
\fi
\columnsettextbox\recurselevel\vsplit0 to \!!heightc}
% just one method
\OTRSETgetcolumnnaturalheight1 \dimen4\scratchdimen
\OTRSETgetcolumnnaturalheight\nofcolumns \dimen6\scratchdimen
%\writestatus\m!columns{first column: \the\dimen4}%
%\writestatus\m!columns{last column: \the\dimen6}%
\ifdim\dimen4=\dimen6
\donetrue % perfect balance
\else\ifdim\dimen4>\dimen6
\donefalse % not yet good enough
\increment\balancinglines % try again
\edef\balancingcount{\the\!!counta}
\else
\donetrue % worse balance
\ifnum\balancinglines>0 % take previous
\decrement\balancinglines
\fi
\fi\fi
% extra check
% \ifdim\ht0>\zeropoint\relax \donefalse \fi
% another check
\ifdone
%\writestatus\m!columns{balancing finished in pass \loopcounter}%
\else \ifnum\loopcounter>100 \donetrue
%\writestatus\m!columns{balancing aborted after pass \loopcounter}%
\else
%\writestatus\m!columns{balancing continued after pass \loopcounter}%
\fi \fi
% final balancing pass
\ifdone
\setbox0\copy1
\setbox2\copy3
\columnerasetextboxes
\columnerasefootboxes
\dorecurse\nofcolumns
{\OTRSETgetcolumntextheight\recurselevel
\OTRSETcalculatelines\scratchdimen
\!!heightc\scratchdimen
\ifnum\recurselevel<\nofcolumns
\advance\!!heightc -\balancinglines\lineheight
\fi
% split off text
\ifdim\ht0>\zeropoint
\columnsettextbox\recurselevel\vsplit0 to \!!heightc
\setbox4\vbox{\unvcopy\columntextbox\recurselevel}
\advance\!!heightc -\ht4
\ifdim\ht0>\zeropoint
\columnsettextbox\recurselevel\box4
\advance\!!heightc \skip\footins
\fi
\fi
% split off footnotes
\ifdim\ht0>\zeropoint\relax \else
\ifdim\ht2>\zeropoint\relax
\setbox4\vsplit2 to \!!heightc
\setbox\footins=\vbox{\unvbox4} % ugly and dirty trick
\ifdim\ht\columntextbox\recurselevel=\zeropoint\relax
\columnsettextbox\recurselevel\hbox
{\raise\strutdp\hbox % ugly but needed
{\setfootnotebodyfont % both these moves
\lower\strutdp\hbox{\placebottomnotes}}}
\else
\columnsetfootbox\recurselevel\hbox{\placebottomnotes}
\fi
\fi
\fi}
\exitloop
\fi}
\else
% no reason to balance floats
\fi
\fi
\doglobal\addtocommalist{\realfolio}\OTRSETbalancinglist
\OTRSETdoflush
\fi
\egroup}
\protect \endinput
% \def\OTRSETsetbalanceht#1#2% var col
% {#1\getvalue{\??mc\OTRSETidentifier\number#2\c!regels}\relax
% \ifcase#1#1\getvalue{\??mc\OTRSETidentifier\c!regels}\relax\fi
% \ifcase#1#1\savedcolumnmaxcells\relax\fi}
% \def\OTRSETinitbalancing
% {\ifbalancecolumns
% \let\savedcolumnmaxcells\columnmaxcells
% \ifnum\realpageno=\balancingpageno\relax
% \ifnum\mofcolumns=\plusone\relax
% \ifcase\OTRSETbottombalance \else
% \!!countc\zeropoint
% \dorecurse\nofcolumns
% {\OTRSETsetbalanceht\!!countb\recurselevel
% \ifnum\!!countb>\!!countc\!!countc\!!countb\fi}%
% \fi
% \dorecurse\nofcolumns
% {\!!counta\recurselevel\relax
% % can be an option: absolute versus relative
% \ifcase\OTRSETbottombalance
% \OTRSETsetbalanceht\!!countb\recurselevel
% \advance\!!countb\precolumnlines
% \ifnum\!!countb>\localcolumnmaxcells\relax
% \xdef\localcolumnmaxcells{\the\!!countb}%
% \fi
% \advance\!!countb \plusone
% \dostepwiserecurse\!!countb\columnmaxcells\plusone
% {\ifvoid\OTRSETgridcell\!!counta\recurselevel
% \OTRSETsetgridcell\!!counta\recurselevel\copy\placeholderboxe
% \fi}%
% \else
% \globallet\localcolumnmaxcells\columnmaxcells
% \!!countb\!!countc
% \advance\!!countb-\columnmaxcells
% \!!countb-\!!countb
% \advance\!!countb \minusone
% \ifnum\!!countb>\zerocount
% \dostepwiserecurse\plusone\!!countb\plusone
% {\ifvoid\OTRSETgridcell\!!counta\recurselevel
% \OTRSETsetgridcell\!!counta\recurselevel\copy\placeholderboxe
% \fi}%
% \OTRSETsetbalanceht\!!countb\recurselevel
% \ifnum\!!countc>\!!countb
% \!!countd\columnmaxcells
% \advance\!!countd-\!!countc
% \advance\!!countd+\!!countb
% \dostepwiserecurse\!!countd\columnmaxcells\plusone
% {\ifvoid\OTRSETgridcell\!!counta\recurselevel
% \OTRSETsetgridcell\!!counta\recurselevel\copy\placeholderboxe
% \fi}%
% \fi
% \fi
% \fi}%
% \OTRSETsetvsize % ! ! !
% \fi
% \fi
% \fi}
|