~reviczky/context/mirror

1722 by Hans Hagen
2020-11-23 18:39:00
1
%D \module
2
%D   [       file=page-one,
3
%D        version=2000.10.20,
4
%D          title=\CONTEXT\ Page Macros,
5
%D       subtitle=Default Routine,
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
\writestatus{loading}{ConTeXt Page Macros / Default Routine}
15
16
%D This is just the good old \CONTEXT\ output routine, which
17
%D has been there right from the start.
18
19
\unprotect
20
21
% OTRONE: basic single column
22
23
\newconstant \c_page_one_float_method
24
25
\protected\def\page_one_command_next_page
26
  {\page_otr_eject_page}
27
28
\protected\def\page_one_command_next_page_and_inserts
29
  {\page_otr_eject_page_and_flush_inserts}
30
31
\protected\def\page_one_command_set_hsize
32
  {\global\hsize\textwidth
33
   \columnwidth\textwidth} % bonus so that it's not zero
34
35
\protected\def\page_one_command_set_float_hsize
36
  {\global\hsize\textwidth}
37
1844 by Hans Hagen
2021-09-13 09:40:00
38
%D It's complicated:
39
40
\newconditional\c_page_one_set_vsize_tmp
41
42
\installtextracker{otr.insertheights}
43
  {\settrue\c_page_one_set_vsize_tmp}
44
  {\setfalse\c_page_one_set_vsize_tmp}
45
46
\def\page_one_command_set_vsize_tmp
47
  {\settotalinsertionheight
48
   \writestatus
49
     {set vsize one}
50
     {insert heights=\the\insertheights,
51
      total insertion height=\the\totalinsertionheight,
52
      delta=\the\dimexpr\insertheights-\totalinsertionheight}%
53
   \page_one_command_set_vsize_new}
54
55
\def\page_one_command_set_vsize_old
56
  {\settotalinsertionheight
57
   \pagegoal\dimexpr
58
      \vsize
59
     -\totalinsertionheight
60
   \relax}
61
62
\def\page_one_command_set_vsize_new
63
  {\pagegoal\dimexpr
64
      \vsize
65
     -\d_page_floats_inserted_top
66
     -\d_page_floats_inserted_bottom
67
     -\insertheights
68
   \relax
1845 by Hans Hagen
2021-09-14 21:41:00
69
   }% no: \insertheights\zeropoint}
1844 by Hans Hagen
2021-09-13 09:40:00
70
1722 by Hans Hagen
2020-11-23 18:39:00
71
\protected\def\page_one_command_set_vsize
72
  {\ifgridsnapping
73
     \ifcase\layoutlines
74
       \getrawnoflines\textheight
75
     \else
76
       \noflines\layoutlines
77
     \fi
78
     \global\vsize\noflines\openlineheight
79
   \else
80
     \global\vsize\textheight
81
   \fi
1887 by Hans Hagen
2022-05-02 15:50:00
82
   %
83
   \ifzeropt\textadaptive\else
84
     \global\d_page_adapts_delta\textadaptive
85
     \global\pageextragoal-\textadaptive
86
   \fi
87
   %
1722 by Hans Hagen
2020-11-23 18:39:00
88
   \global\advance\vsize\d_page_adapts_delta
89
   % alternatively we could set it in builders.buildpage_filter
90
 % \ifdim\pagegoal<\maxdimen .. \fi
1844 by Hans Hagen
2021-09-13 09:40:00
91
 % \writestatus{!!!!!!!!}{\the\vsize-> v:\the\pagevsize,g:\the\pagegoal,t:\the\pagetotal,i:\the\insertheights}%
92
   \ifconditional\c_page_one_set_vsize_tmp
93
     \page_one_command_set_vsize_tmp
94
   \orelse\ifzeropt\insertheights
95
     \page_one_command_set_vsize_old
96
   \else
97
     \page_one_command_set_vsize_new
98
   \fi}
1722 by Hans Hagen
2020-11-23 18:39:00
99
100
% 1 = partial page, 2 = whole page, 3 = partial page
101
102
% We really need a setting! Todo, what key to use?
103
104
\pushoverloadmode
1764 by Hans Hagen
2021-02-12 18:48:00
105
    \setnewconstant\kindofpagetextareas\plustwo                     % \plusone can become default some day
1793 by Hans Hagen
2021-05-05 19:24:00
106
    \overloaded\mutable\let\kindofpagetextareas\kindofpagetextareas % for now mutable, can become a key/value
1722 by Hans Hagen
2020-11-23 18:39:00
107
\popoverloadmode
108
109
\def\page_one_registered_text_area_a % two arguments: (un)vbox n
110
  {\ifconditional\c_page_areas_enabled
111
     \expandafter\page_one_registered_text_area_a_indeed
112
   \else
113
     \expandafter\firstofoneargument
114
   \fi}
115
116
\def\page_one_registered_text_area_b % one arguments: content
117
  {\ifconditional\c_page_areas_enabled
118
     \expandafter\page_one_registered_text_area_b_indeed
119
   \else
120
     \expandafter\firstofoneargument
121
   \fi}
122
123
\def\page_one_registered_text_area_a_indeed % two arguments: (un)vbox n
124
  {\ifcase\kindofpagetextareas
125
     \expandafter\firstofoneargument
126
   \or % partial page (experimental)
127
     \expandafter\page_areas_register_direct
128
   \or % whole page   (default)
129
     \expandafter\firstofoneargument
130
   \else
131
     \expandafter\firstofoneargument
132
   \fi}
133
134
\def\page_one_registered_text_area_b_indeed % one arguments: content
135
  {\ifcase\kindofpagetextareas
136
     % \expandafter\firstofoneargument
137
   \or % partial page (experimental)
138
     % \expandafter\firstofoneargument
139
   \or % whole page   (default)
140
     \expandafter\page_areas_register_boxed
141
   \else
142
     % \expandafter\firstofoneargument
143
   \fi}
144
145
\newdimen\d_page_one_natural_depth
146
\newbox  \b_page_one_bottom_notes
147
\newbox  \b_page_one_contents
148
149
\let\page_one_command_package_show_state\relax
150
151
% \fakepagenotes ... needs checking
152
%
153
% we can also have bottom notes on top of bottom insertions
154
1796 by Hans Hagen
2021-05-15 22:44:00
155
% \protected\def\page_one_command_package_contents#1#2% \box<n> \unvbox<n> % this one will be redone (checked)
156
%   {\bgroup
157
%    \strc_notes_check_if_bottom_present
158
%    \d_page_one_natural_depth\dp#2\relax
159
%    % we need to set the height as otherwise the shrink will not kick in so the following
160
%    % no longer applies:
161
%    %
162
%    % \setbox\b_page_one_contents\vbox \ifconditional\c_notes_bottom_present to \textheight \fi
163
%    %
164
%    \setbox\b_page_one_contents\vbox to \textheight % probably no pack
165
%      {\page_otr_command_flush_top_insertions
166
%       % this is messy ... we will provide a more tight area (no big deal as we can
167
%       % do that at the lua end)
168
% % \parfillskip\zeropoint
169
%       \page_one_registered_text_area_a#1#2% \unvbox <box>
170
%       %
171
%       \ifgridsnapping
172
%         \unskip % new per 2019-06-18, otherwise weird bottom floats
173
%         \vkern\dimexpr\openstrutdepth-\d_page_one_natural_depth\relax
174
%         \prevdepth\openstrutdepth
175
%         \page_otr_command_flush_bottom_insertions
176
%         \vfil
177
%       \orelse\ifcase\bottomraggednessmode
178
%         % ragged (default)
179
%         \unskip % new per 2019-06-18, otherwise weird bottom floats
180
%         \vkern\dimexpr\openstrutdepth-\d_page_one_natural_depth\relax
181
%         \prevdepth\openstrutdepth
182
%         % these have whitespace before but we can have some more options
183
%         % like a \vfill or so
184
%         \page_otr_command_flush_bottom_insertions
185
%         \vfil
186
%       \or
187
%         % align (normal)
188
%         \page_otr_command_flush_bottom_insertions
189
%       \or
190
%         % baseline
191
%         \unskip % new per 2019-06-18, otherwise weird bottom floats
192
%         \vkern\dimexpr\maxdepth-\d_page_one_natural_depth\relax
193
%         \page_otr_command_flush_bottom_insertions
194
%       \fi
195
%       \fakepagenotes}%
196
%    \page_one_command_package_show_state
197
%    \ifconditional\c_notes_bottom_present
198
%      \ifgridsnapping
199
%        \ifcase\layoutlines
200
%          \getrawnoflines\textheight
201
%        \else
202
%          \noflines\layoutlines
203
%        \fi
204
%        \scratchoffset\dimexpr\numexpr\noflines-\plusone\relax\lineheight+\topskip\relax
205
%      \else
206
%        \scratchoffset\ht\b_page_one_contents
207
%      \fi
208
%      \setbox\b_page_one_bottom_notes\hpack
209
%        {\lower\scratchoffset\vbox{\placebottomnotes\par\kern\zeropoint}}% kerns makes notes sit on bottom % pack ?
210
%      \smashbox\b_page_one_bottom_notes
211
%      \ht\b_page_one_contents\zeropoint
212
%      \page_one_registered_text_area_b
213
%        {\vpack to \textheight
214
%           {\box\b_page_one_contents
215
%            \box\b_page_one_bottom_notes}}%
216
%    \else
217
%      \ht\b_page_one_contents\textheight
218
%      \page_one_registered_text_area_b
219
%        {\box\b_page_one_contents}%
220
%    \fi
221
%    \egroup}
222
223
%D \starttyping
224
%D \setuplayout[height=middle] \showframe
225
%D
226
%D % \markpages[stretch][lines=2] % current page
227
%D
228
%D \starttext
229
%D     \brokenpenalty 10000 \clubpenalty 20000 \widowpenalty 20000
230
%D     \dorecurse{10}{\samplefile{tufte}\par} \page
231
%D     \startmarkpages[stretch][lines=2]
232
%D         \dorecurse{10}{\samplefile{tufte}\par} \page
233
%D     \stopmarkpages
234
%D     \dorecurse{10}{\samplefile{tufte}\par} \page
235
%D \stoptext
236
%D \stoptyping
237
238
\newcount\c_page_one_stretch % we use marked pages which actually slow down a little
239
240
\def\page_one_check_stretch_contents
241
  {\ifdim\dimexpr\textheight-\ht\b_page_one_contents\relax<\c_page_one_stretch\lineheight
242
     \setbox\b_page_one_contents\vpack\bgroup
243
       % no need to speed up low level
244
       \scale[\c!height=\textheight,\c!width=\textwidth]{\box\b_page_one_contents}%
245
     \egroup
246
   \fi}
247
248
\def\page_one_check_stretch_lines
249
  {\edef\m_lines{\markedpageparameter\v!stretch\v!lines}%
250
   \ifempty\m_lines\else\c_page_one_stretch\m_lines\fi}
251
1722 by Hans Hagen
2020-11-23 18:39:00
252
\protected\def\page_one_command_package_contents#1#2% \box<n> \unvbox<n> % this one will be redone (checked)
253
  {\bgroup
254
   \strc_notes_check_if_bottom_present
255
   \d_page_one_natural_depth\dp#2\relax
256
   % we need to set the height as otherwise the shrink will not kick in so the following
257
   % no longer applies:
258
   %
259
   % \setbox\b_page_one_contents\vbox \ifconditional\c_notes_bottom_present to \textheight \fi
260
   %
1796 by Hans Hagen
2021-05-15 22:44:00
261
   \ifconditional\c_notes_bottom_present\else
262
      \doifmarkedpage\v!stretch\page_one_check_stretch_lines
263
   \fi
264
   \setbox\b_page_one_contents\vbox \ifcase\c_page_one_stretch to \textheight\fi % probably no pack
1722 by Hans Hagen
2020-11-23 18:39:00
265
     {\page_otr_command_flush_top_insertions
266
      % this is messy ... we will provide a more tight area (no big deal as we can
267
      % do that at the lua end)
1796 by Hans Hagen
2021-05-15 22:44:00
268
    % \parfillskip\zeropoint
1722 by Hans Hagen
2020-11-23 18:39:00
269
      \page_one_registered_text_area_a#1#2% \unvbox <box>
270
      %
271
      \ifgridsnapping
272
        \unskip % new per 2019-06-18, otherwise weird bottom floats
273
        \vkern\dimexpr\openstrutdepth-\d_page_one_natural_depth\relax
274
        \prevdepth\openstrutdepth
275
        \page_otr_command_flush_bottom_insertions
276
        \vfil
277
      \orelse\ifcase\bottomraggednessmode
278
        % ragged (default)
279
        \unskip % new per 2019-06-18, otherwise weird bottom floats
280
        \vkern\dimexpr\openstrutdepth-\d_page_one_natural_depth\relax
281
        \prevdepth\openstrutdepth
282
        % these have whitespace before but we can have some more options
283
        % like a \vfill or so
284
        \page_otr_command_flush_bottom_insertions
285
        \vfil
286
      \or
287
        % align (normal)
288
        \page_otr_command_flush_bottom_insertions
289
      \or
290
        % baseline
291
        \unskip % new per 2019-06-18, otherwise weird bottom floats
292
        \vkern\dimexpr\maxdepth-\d_page_one_natural_depth\relax
1880 by Hans Hagen
2022-03-12 11:26:00
293
      % \srule depth \dimexpr\maxdepth-\d_page_one_natural_depth\relax
1722 by Hans Hagen
2020-11-23 18:39:00
294
        \page_otr_command_flush_bottom_insertions
295
      \fi
296
      \fakepagenotes}%
297
   \page_one_command_package_show_state
298
   \ifconditional\c_notes_bottom_present
299
     \ifgridsnapping
300
       \ifcase\layoutlines
301
         \getrawnoflines\textheight
302
       \else
303
         \noflines\layoutlines
304
       \fi
305
       \scratchoffset\dimexpr\numexpr\noflines-\plusone\relax\lineheight+\topskip\relax
306
     \else
307
       \scratchoffset\ht\b_page_one_contents
308
     \fi
309
     \setbox\b_page_one_bottom_notes\hpack
310
       {\lower\scratchoffset\vbox{\placebottomnotes\par\kern\zeropoint}}% kerns makes notes sit on bottom % pack ?
311
     \smashbox\b_page_one_bottom_notes
312
     \ht\b_page_one_contents\zeropoint
313
     \page_one_registered_text_area_b
314
       {\vpack to \textheight
315
          {\box\b_page_one_contents
316
           \box\b_page_one_bottom_notes}}%
317
   \else
1796 by Hans Hagen
2021-05-15 22:44:00
318
     \ifcase\c_page_one_stretch\else
319
        \page_one_check_stretch_contents
320
     \fi
1722 by Hans Hagen
2020-11-23 18:39:00
321
     \ht\b_page_one_contents\textheight
322
     \page_one_registered_text_area_b
323
       {\box\b_page_one_contents}%
324
   \fi
325
   \egroup}
326
327
\protected\def\page_one_command_side_float_output
328
  {\page_otr_construct_and_shipout\unvbox\normalpagebox\plusone} % three arguments, we need to be in the output group
329
330
\protected\def\page_one_command_routine
331
  {\page_sides_output_routine}
332
333
%D Insertions
334
335
\newconditional\c_page_one_top_of_insert
336
\newconditional\c_page_one_correct_top_insert  \settrue\c_page_one_correct_top_insert % false moves up (tight)
337
\newskip       \s_page_one_between_top_insert
338
339
\def\page_one_prepare_top_float
340
  {\ifdim\d_page_floats_inserted_top=\zeropoint
341
     \settrue\c_page_one_top_of_insert
342
   \else
343
     \setfalse\c_page_one_top_of_insert
344
   \fi
345
   \s_page_one_between_top_insert\ifdim\d_strc_floats_top>\d_strc_floats_bottom\d_strc_floats_top\else\d_strc_floats_bottom\fi\relax
346
   \global\advance\d_page_floats_inserted_top\dimexpr\ht\floatbox+\dp\floatbox+\s_page_one_between_top_insert\relax}
347
348
\def\page_one_insert_top_float % maybe remember last beforeskip
349
  {\floatingpenalty\zerocount
1803 by Hans Hagen
2021-05-27 14:14:00
350
   \page_inserts_inject\namedinsertionnumber\s!topfloat\bgroup
1722 by Hans Hagen
2020-11-23 18:39:00
351
     \forgetall
352
     \ifconditional\c_page_one_top_of_insert
353
       \ifconditional\c_page_one_correct_top_insert
354
         \topskipcorrection % [xx] new: see icare topbleed
355
         \kern-\lineskip
356
         \par
357
         \prevdepth\maxdimen
358
       \fi
359
     \fi
360
     \page_otr_command_flush_float_box
361
     \vskip\s_page_one_between_top_insert
362
   \egroup}
363
1755 by Hans Hagen
2021-01-21 18:04:00
364
\mutable\let\totaltopinserted\!!zeropoint
365
\mutable\let\totalbotinserted\!!zeropoint
1722 by Hans Hagen
2020-11-23 18:39:00
366
367
\protected\def\page_one_command_set_top_insertions
368
  {\bgroup
369
   \ifconditional\c_page_floats_some_waiting
370
     \noffloatinserts\zerocount
371
     \let\totaltopinserted\!!zeropoint
372
     \page_one_command_set_top_insertions_indeed
1871 by Hans Hagen
2021-12-24 19:09:00
373
     \ifnum\rootfloatparameter\c!nbottom=\zerocount % \ifnum\c_page_floats_n_of_bottom=\zerocount
1722 by Hans Hagen
2020-11-23 18:39:00
374
       \ifnum\rootfloatparameter\c!nlines>\zerocount
375
         \ifdim\totaltopinserted>\zeropoint\relax
376
           \ifdim\dimexpr\rootfloatparameter\c!nlines\lineheight+\totaltopinserted\relax>\textheight
377
             \showmessage\m!floatblocks8{\rootfloatparameter\c!nlines}%
378
             \page_otr_fill_and_eject_page % was tripple: vfilll
379
           \fi
380
         \fi
381
       \fi
382
     \fi
383
   \fi
384
   \egroup}
385
386
\def\page_one_command_set_top_insertions_indeed
387
  {\ifnum\noffloatinserts<\c_page_floats_n_of_top
388
     \page_floats_get
389
     \page_one_prepare_top_float
390
     \ifdim\d_page_floats_inserted_top<\textheight\relax
391
       \xdef\totaltopinserted{\the\d_page_floats_inserted_top}%
392
       \page_one_insert_top_float
393
       \ifconditional\c_page_floats_some_waiting
394
         \advance\noffloatinserts \plusone
395
       \else
396
         \noffloatinserts\c_page_floats_n_of_top\relax
397
       \fi
398
       \page_floats_report_flushed
399
     \else
400
       \page_floats_resave\s!text
401
       \noffloatinserts\c_page_floats_n_of_top\relax
402
     \fi
403
   \else
404
     \ifconditional\c_page_floats_some_waiting
405
       \showmessage\m!floatblocks6{\the\c_page_floats_n_of_top}%
406
     \fi
407
     \let\page_one_command_set_top_insertions_indeed\relax
408
   \fi
409
   \page_one_command_set_top_insertions_indeed}
410
411
\protected\def\page_one_command_set_bottom_insertions
412
  {\bgroup
413
   \ifconditional\c_page_floats_some_waiting
414
     \noffloatinserts\zerocount
415
     \page_one_command_set_bottom_insertions_indeed
416
   \fi
417
   \egroup}
418
419
\def\page_one_command_set_bottom_insertions_indeed
420
  {\ifnum\noffloatinserts<\c_page_floats_n_of_bottom\relax
421
     \page_floats_get
422
     \global\advance\d_page_floats_inserted_bottom\dimexpr\ht\floatbox+\dp\floatbox+\d_strc_floats_top\relax
423
     \ifdim\d_page_floats_inserted_bottom<\pagegoal\relax
424
       \floatingpenalty\zerocount
1803 by Hans Hagen
2021-05-27 14:14:00
425
       \page_inserts_inject\namedinsertionnumber\s!bottomfloat\bgroup
1722 by Hans Hagen
2020-11-23 18:39:00
426
         \forgetall
427
         \blank[\rootfloatparameter\c!spacebefore]%
428
         \page_otr_command_flush_float_box
429
       \egroup
430
       \ifconditional\c_page_floats_some_waiting
431
         \advance\noffloatinserts \plusone
432
       \else
433
         \noffloatinserts\c_page_floats_n_of_bottom
434
       \fi
435
       \page_floats_report_flushed
436
     \else
437
       \page_floats_resave\s!text
438
       \noffloatinserts\c_page_floats_n_of_bottom\relax
439
     \fi
440
     \global\settrue\c_page_floats_not_permitted % vgl topfloats s!
441
   \else
442
     \ifconditional\c_page_floats_some_waiting
443
       \showmessage\m!floatblocks7{\the\c_page_floats_n_of_bottom}%
444
     \fi
445
     \let\page_one_command_set_bottom_insertions_indeed\relax
446
   \fi
447
   \page_one_command_set_bottom_insertions_indeed}
448
1881 by Hans Hagen
2022-03-24 21:17:00
449
% \protected\def\page_one_command_flush_top_insertions
450
%   {\ifzeropt\page_inserts_get_height\namedinsertionnumber\s!topfloat\else
451
%      \page_one_command_flush_top_insertions_indeed % less tracing
452
%    \fi
453
%    \global\d_page_floats_inserted_top\zeropoint}
454
1722 by Hans Hagen
2020-11-23 18:39:00
455
\protected\def\page_one_command_flush_top_insertions
1801 by Hans Hagen
2021-05-25 17:56:00
456
  {\ifzeropt\page_inserts_get_height\namedinsertionnumber\s!topfloat\else
1722 by Hans Hagen
2020-11-23 18:39:00
457
     \page_one_command_flush_top_insertions_indeed % less tracing
1881 by Hans Hagen
2022-03-24 21:17:00
458
     \ifcase\bottomraggednessmode\or\else
459
       % will be an option
460
       \vskip\zeropoint plus \openstrutdepth minus \openstrutdepth
461
     \fi
1722 by Hans Hagen
2020-11-23 18:39:00
462
   \fi
463
   \global\d_page_floats_inserted_top\zeropoint}
464
465
\def\page_one_command_flush_top_insertions_indeed
466
  {\ifgridsnapping
1801 by Hans Hagen
2021-05-25 17:56:00
467
     \page_inserts_get_boxed\namedinsertionnumber\s!topfloat
1722 by Hans Hagen
2020-11-23 18:39:00
468
     \vkern-\topskip
469
     \vkern\strutheight % [xx] new: see icare topbleed
470
   \else
471
     \ifcase\c_page_floats_insertions_topskip_mode
472
       % 0: default, do nothing
473
     \or
474
       % 1: no topskip (crossed fingers)
475
       \vskip-\topskip % skip !
476
       \vkern\strutheight
477
     \fi
1801 by Hans Hagen
2021-05-25 17:56:00
478
     \page_inserts_get_unboxed\namedinsertionnumber\s!topfloat
1722 by Hans Hagen
2020-11-23 18:39:00
479
   \fi}
480
481
\protected\def\page_one_command_flush_bottom_insertions
1801 by Hans Hagen
2021-05-25 17:56:00
482
  {\ifzeropt\page_inserts_get_height\namedinsertionnumber\s!bottomfloat\else
1722 by Hans Hagen
2020-11-23 18:39:00
483
     \page_one_command_flush_bottom_insertions_indeed
484
   \fi
485
   \global\d_page_floats_inserted_bottom\zeropoint
486
   \global\setfalse\c_page_floats_not_permitted}
487
488
\def\page_one_command_flush_bottom_insertions_indeed
489
  {\ifgridsnapping
1871 by Hans Hagen
2021-12-24 19:09:00
490
   % \rootfloatparameter\c!bottombefore
1801 by Hans Hagen
2021-05-25 17:56:00
491
     \snaptogrid\hbox{\page_inserts_get_boxed\namedinsertionnumber\s!bottomfloat}%
1871 by Hans Hagen
2021-12-24 19:09:00
492
   % \rootfloatparameter\c!bottomafter
1722 by Hans Hagen
2020-11-23 18:39:00
493
   \else
1871 by Hans Hagen
2021-12-24 19:09:00
494
     \rootfloatparameter\c!bottombefore
1801 by Hans Hagen
2021-05-25 17:56:00
495
     \page_inserts_get_unboxed\namedinsertionnumber\s!bottomfloat
1871 by Hans Hagen
2021-12-24 19:09:00
496
     \rootfloatparameter\c!bottomafter
1722 by Hans Hagen
2020-11-23 18:39:00
497
   \fi}
498
499
\protected\def\page_one_command_flush_floats
500
  {\global\settrue\c_page_floats_flushing
501
   \ifconditional\c_page_floats_some_waiting
502
     \par
503
     % if kept, then option and definitely off in gridmode ! ! ! !
504
     % \ifvmode \prevdepth\maxdimen \fi % prevents whitespace; problematic in icare tests
505
     \page_one_command_flush_floats_indeed
506
   \fi
507
   \global\savednoffloats\zerocount
508
   \global\setfalse\c_page_floats_some_waiting
509
   \global\setfalse\c_page_floats_flushing}
510
511
\protected\def\page_one_command_flush_float_box
512
  {\ifconditional\c_page_floats_center_box \ifdim\wd\floatbox<\hsize
513
     \global\setbox\floatbox\hpack to \hsize{\hss\box\floatbox\hss}%
514
   \fi \fi
515
   \snaptogrid\hpack{\box\floatbox}} % was copy
516
517
\def\page_one_command_floats_get_compressed
518
  {\setfalse\c_page_floats_center_box % not needed as we do call directly
519
   %% no longer (interferes with footnotes):
520
   %%
521
   %% \page_one_command_set_vsize % test 2011.06.24.001
522
   %%
523
   \global\setbox\floatbox\hbox to \hsize
524
     {\hfil
525
      \dorecurse\nofcollectedfloats
526
        {\ifcase\columndirection % nog document wide
527
           \page_floats_flush\s!text\plusone
528
         \else
529
           \page_floats_flush\s!text{\the\numexpr\nofcollectedfloats-\recurselevel+1\relax}%
530
         \fi
531
         \hpack to \ifdim\naturalfloatwd>\makeupwidth\makeupwidth\else\naturalfloatwd\fi
532
           {\hss\box\floatbox\hss}%
533
         \ifnum\recurselevel<\nofcollectedfloats
534
           \hfil
535
         \fi}%
536
      \hfil}}
537
538
\def\page_one_command_flush_floats_indeed
539
  {\ifconditional\c_page_floats_some_waiting
540
     \ifconditional\c_page_floats_pack_flushed
541
       \page_floats_collect\s!text\hsize\d_page_floats_compress_distance
542
       \ifcase\nofcollectedfloats
543
         \page_floats_get
544
       \or
545
         \page_floats_get
546
       \else
547
         \page_one_command_floats_get_compressed
548
       \fi
549
     \else
550
       \page_floats_get
551
     \fi
552
     % there is a chance that due to rounding errors, the float
553
     % fits on a page where it was first rejected, in which case
554
     % the prevdepth is -maxdimen and we cannot obey the grid
555
     \doplacefloatbox
556
     \expandafter\page_one_command_flush_floats_indeed
557
   \fi}
558
559
\protected\def\page_one_command_flush_margin_blocks
560
  {\ifconditional\c_page_margin_blocks_present % \ifvoid\b_page_margin_blocks \else
561
     \ifdim\pagetotal=\zeropoint
562
        \null % \fixedspace
563
     \fi
564
     \page_otr_command_next_page % \page
565
     \ifvoid\b_page_margin_blocks
566
       \global\setfalse\c_page_margin_blocks_present
567
     \else
568
       \doubleexpandafter\page_one_command_flush_margin_blocks
569
     \fi
570
   \fi}
571
572
\protected\def\page_one_command_check_if_float_fits
573
  {\ifconditional\c_page_floats_not_permitted
574
     \global\setfalse\c_page_floats_room
575
   \else
576
     % new per 31/5/2004, should be an option, only one column mode
577
     \begingroup
578
     \scratchdimen\dimexpr\pagetotal+\lineheight\relax
579
     \ifdim\scratchdimen>\pagegoal
580
       \goodbreak % hack ?
581
     \fi
582
     % should be an option
583
     \endgroup
584
     \scratchdimenone\dimexpr
585
        \pagetotal
586
       +\floatheight
587
       +\d_strc_floats_top
588
       +\d_strc_floats_overflow
589
       -\pageshrink
590
     \relax
591
     \scratchdimentwo\pagegoal
592
     \relax % needed
593
     \ifcase\c_page_one_float_method
594
       % method 0 : raw
595
     \or
596
       % method 1 : safe
597
       % too fuzzy as it can change and for a high page it's a lot : \scratchdimentwo .99\pagegoal
598
       \advance\scratchdimentwo -\strutdp
599
     \or
600
       % method 2 : tight
601
       \advance\scratchdimenone -\onepoint
602
     \fi
603
     \relax % really needed ! ! ! !
604
     \ifdim\scratchdimenone>\scratchdimentwo
605
       \global\setfalse\c_page_floats_room
606
     \else
607
       \global\settrue\c_page_floats_room
608
     \fi
609
   \fi}
610
611
\protected\def\page_one_command_flush_saved_floats
612
  {\global\d_page_floats_inserted_top\zeropoint
613
   \global\d_page_floats_inserted_bottom\zeropoint
614
   \ifconditional\c_page_floats_flushing \else
615
     \page_one_command_set_top_insertions
616
     \page_one_command_set_bottom_insertions
617
     \ifconditional\c_page_floats_some_waiting
618
        \doif{\rootfloatparameter\c!cache}\v!no\page_one_command_flush_floats % could be _otr_
619
     \orelse\ifconditional\c_page_margin_blocks_present
620
       \page_one_command_flush_floats
621
     \fi
622
   \fi}
623
624
% \def\page_one_place_float_here_indeed
625
%   {\ifgridsnapping
626
%      % otherwise real bad outcome
627
%    \else
628
%      \baselinecorrection % this has to be done better (and definitely not in column mode)
629
%    \fi
630
%    \doplacefloatbox
631
%    \page_floats_report_total
632
%    \dohandlenextfloatindent}
633
1844 by Hans Hagen
2021-09-13 09:40:00
634
% \def\page_one_place_float_here_indeed
635
%   {\ifgridsnapping
636
%      % otherwise real bad outcome
637
%    \else
638
%     % this was not really applied (delayed)
639
%     % \baselinecorrection % this has to be done better (and definitely not in column mode)
640
%     % so we now use this:
641
%       \checkprevdepth
642
%    \fi
643
%    \doplacefloatbox
644
%    \page_floats_report_total
645
%    \dohandlenextfloatindent}
646
1722 by Hans Hagen
2020-11-23 18:39:00
647
\def\page_one_place_float_here_indeed
648
  {\ifgridsnapping
649
     % otherwise real bad outcome
650
   \else
1844 by Hans Hagen
2021-09-13 09:40:00
651
    \forcestrutdepth
1722 by Hans Hagen
2020-11-23 18:39:00
652
   \fi
653
   \doplacefloatbox
654
   \page_floats_report_total
655
   \dohandlenextfloatindent}
656
657
\def\page_one_place_float_force
658
  {\showmessage\m!floatblocks9\empty
659
   \page_one_place_float_here_indeed}
660
661
\def\page_one_place_float_side_indeed#1%
662
  {\setbox\floatbox\vpack{\box\floatbox}% ? can go
663
   \wd\floatbox\floatwidth
664
   #1{\box\floatbox}%
665
   \doifinset\v!tall\floatlocationmethod\page_sides_flush_floats_after_par}
666
667
\def\page_one_place_float_left
668
  {\page_one_place_float_side_indeed
669
   \page_sides_process_float_left
670
   \presetindentation}
671
672
\def\page_one_place_float_right
673
  {\page_one_place_float_side_indeed
674
   \page_sides_process_float_right}
675
676
\def\page_one_place_float_margin
677
  {\page_margin_blocks_process_float
678
   \nonoindentation} % new, due to popular request
679
680
\def\page_one_place_float_leftmargin
681
  {\page_one_place_float_side_indeed
682
   \page_sides_process_float_leftmargin
683
   \nonoindentation} % new, due to popular request
684
685
\def\page_one_place_float_rightmargin
686
  {\page_one_place_float_side_indeed
687
   \page_sides_process_float_rightmargin
688
   \nonoindentation} % new, due to popular request
689
690
\def\page_one_place_float_leftedge
691
  {\page_one_place_float_side_indeed
692
   \page_sides_process_float_leftedge}
693
694
\def\page_one_place_float_rightedge
695
  {\page_one_place_float_side_indeed
696
   \page_sides_process_float_rightedge}
697
698
\def\page_one_place_float_inmargin
699
  {\page_one_place_float_side_indeed
700
   \page_sides_process_float_cutspace}
701
702
\def\page_one_place_float_backspace
703
  {\page_one_place_float_side_indeed
704
   \page_sides_process_float_backspace}
705
706
\def\page_one_place_float_cutspace
707
  {\page_one_place_float_side_indeed
708
   \page_sides_process_float_cutspace}
709
710
\def\page_one_place_float_page       {\page_floats_save_page_float     \s!page     \floatlocationmethod}
711
\def\page_one_place_float_leftpage   {\page_floats_save_page_float     \s!leftpage \floatlocationmethod}
712
\def\page_one_place_float_rightpage  {\page_floats_save_page_float     \s!rightpage\floatlocationmethod}
713
\def\page_one_place_float_somewhere  {\page_floats_save_somewhere_float\s!somewhere\floatlocationmethod}
714
715
\def\page_one_place_float_here
716
  {\page_one_place_float_otherwise_here}
717
718
\def\page_one_place_float_auto
719
  {\page_one_place_float_otherwise
720
   \nonoindentation} % new, due to popular request
721
722
\def\page_one_place_float_top
723
  {\page_one_place_float_otherwise
724
   \nonoindentation}
725
726
\def\page_one_place_float_bottom
727
  {\page_one_place_float_otherwise
728
   \nonoindentation} % new, due to popular request
729
730
\def\page_one_place_float_otherwise
731
  {\doifelseinset\v!here\floatlocationmethod
732
     \page_one_place_float_otherwise_here
733
     \page_one_place_float_otherwise_else}
734
735
\def\page_one_place_float_otherwise_here
736
  {\doifelseinset\v!always\floatlocationmethod
737
     {\page[\v!preference]%
738
      \page_otr_command_check_if_float_fits
739
      \ifconditional\c_page_floats_room
740
        \page_one_place_float_here_indeed
741
      \else
742
        \showmessage\m!floatblocks9\empty
743
        \page_floats_resave\s!text
744
      \fi}
745
     {\ifconditional\c_page_floats_some_waiting
746
        \page_floats_save\s!text
747
        \nonoindentation
748
      \else
749
        \page[\v!preference]%
750
        \page_otr_command_check_if_float_fits
751
        \ifconditional\c_page_floats_room
752
          \page_one_place_float_here_indeed
753
        \else
754
          \page_floats_save\s!text
755
          \nonoindentation
756
        \fi
757
      \fi}}
758
759
\def\page_one_place_float_otherwise_else
760
  {\doifelseinset\v!always\floatlocationmethod
761
     {\page_otr_command_check_if_float_fits
762
      \ifconditional\c_page_floats_room
763
        \page_one_place_float_auto_top_bottom
764
      \else
765
        \showmessage\m!floatblocks9\empty
766
        \page_floats_resave\s!text
767
      \fi}
768
     {\page_otr_command_check_if_float_fits
769
      \ifconditional\c_page_floats_room
770
        \page_one_place_float_auto_top_bottom
771
      \else
772
        \page_floats_save\s!text
773
        \nonoindentation
774
      \fi}}
775
1732 by Hans Hagen
2020-11-30 10:23:00
776
\mutable\def\floatautofactor{.5}
1722 by Hans Hagen
2020-11-23 18:39:00
777
778
\def\page_one_place_float_auto_top_bottom
779
  {\ifx\floatmethod\v!auto
780
     \ifdim\pagetotal<\floatautofactor\pagegoal % when empty page, maxdimen
781
       \page_one_place_float_top_indeed
782
     \else
783
       \page_one_place_float_bottom_indeed
784
     \fi
785
   \else
786
     \ifx\floatmethod\v!top
787
       \page_one_place_float_top_indeed
788
     \orelse\ifx\floatmethod\v!bottom
789
       \page_one_place_float_bottom_indeed
790
     \else
791
       \page_one_place_float_here_indeed
792
     \fi
793
   \fi}
794
795
\def\page_one_place_float_top_indeed % maybe remember last beforeskip
796
  {\page_one_prepare_top_float
797
   \page_one_insert_top_float
798
   \page_floats_report_total}
799
800
\def\page_one_place_float_bottom_indeed
801
  {\global\advance\d_page_floats_inserted_bottom\dimexpr\ht\floatbox+\dp\floatbox+\d_strc_floats_top\relax
802
   \floatingpenalty\zerocount
1803 by Hans Hagen
2021-05-27 14:14:00
803
   \page_inserts_inject\namedinsertionnumber\s!bottomfloat\bgroup
1722 by Hans Hagen
2020-11-23 18:39:00
804
     \forgetall
805
     \blank[\rootfloatparameter\c!spacebefore]%
806
     \page_otr_command_flush_float_box
807
   \egroup
808
   \page_floats_report_total}
809
810
\def\page_one_place_float_face % links, rechts, midden, hoog, midden, laag
811
  {%\checkwaitingfloats{#1}%
812
   \startopposite
813
   \page_otr_command_flush_float_box
814
   \stopopposite
815
  }%\page_floats_report_total}
816
817
\protected\def\page_one_command_flush_side_floats
818
  {\page_sides_flush_floats}
819
820
\protected\def\page_one_command_synchronize_side_floats
821
  {\page_sides_synchronize_floats}
822
823
\protected\def\page_one_command_test_page
824
  {\testpage}
825
826
\protected\def\page_one_command_flush_all_floats
827
  {\ifconditional\c_page_floats_some_waiting
828
     \begingroup
829
     \c_page_floats_n_of_top\plusthousand
830
     \c_page_floats_n_of_bottom\zerocount
831
     % this is needed in case a float that has been stored
832
     % ends up at the current page; this border case occurs when
833
     % the calculated room is 'eps' smaller that the room available
834
     % when just flushing; so now we have (maybe optional):
835
     \pagebaselinecorrection % hm, needs checking, not needed when no floats
836
     % alas, this is tricky but needed (first surfaced in prikkels)
837
     \page_otr_command_flush_floats
838
     \endgroup
839
   \fi}
840
841
\defineoutputroutine
842
  [\s!singlecolumn]
843
  [\s!page_otr_command_routine                =\page_one_command_routine,
844
   \s!page_otr_command_package_contents       =\page_one_command_package_contents,
845
   \s!page_otr_command_set_vsize              =\page_one_command_set_vsize,
846
   \s!page_otr_command_set_hsize              =\page_one_command_set_hsize,
847
 % \s!page_otr_command_synchronize_hsize      =\page_one_command_synchronize_hsize,
848
   \s!page_otr_command_next_page              =\page_one_command_next_page,
849
   \s!page_otr_command_next_page_and_inserts  =\page_one_command_next_page_and_inserts,
850
   \s!page_otr_command_set_top_insertions     =\page_one_command_set_top_insertions,
851
   \s!page_otr_command_set_bottom_insertions  =\page_one_command_set_bottom_insertions,
852
   \s!page_otr_command_flush_top_insertions   =\page_one_command_flush_top_insertions,
853
   \s!page_otr_command_flush_bottom_insertions=\page_one_command_flush_bottom_insertions,
854
   \s!page_otr_command_check_if_float_fits    =\page_one_command_check_if_float_fits,
855
 % \s!page_otr_command_set_float_hsize        =\page_one_command_set_float_hsize,
856
   \s!page_otr_command_flush_float_box        =\page_one_command_flush_float_box,
857
   \s!page_otr_command_side_float_output      =\page_one_command_side_float_output,
858
   \s!page_otr_command_synchronize_side_floats=\page_one_command_synchronize_side_floats,
859
   \s!page_otr_command_flush_floats           =\page_one_command_flush_floats,
860
   \s!page_otr_command_flush_side_floats      =\page_one_command_flush_side_floats,
861
   \s!page_otr_command_flush_saved_floats     =\page_one_command_flush_saved_floats,
862
   \s!page_otr_command_flush_all_floats       =\page_one_command_flush_all_floats,
863
   \s!page_otr_command_flush_margin_blocks    =\page_one_command_flush_margin_blocks,
864
   \s!page_otr_command_test_column            =\page_one_command_test_page,
865
]
866
867
% \setupoutputroutine
868
%   [\s!singlecolumn]
869
870
\protect \endinput