1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Page Macros Float Management}
15
16
17
18
19\registerctxluafile{pageflt}{}
20
21\unprotect
22
23\defineinsertion[\s!topfloat]
24\defineinsertion[\s!bottomfloat]
25\defineinsertion[\s!pagefloat]
26
27\newdimension\d_page_floats_inserted_bottom
28\newdimension\d_page_floats_inserted_top
29\newdimension\d_page_floats_inserted_page
30\newinteger \c_page_floats_n_of_top \c_page_floats_n_of_top \plustwo
31\newinteger \c_page_floats_n_of_bottom \c_page_floats_n_of_bottom\zerocount
32\newinteger \c_page_floats_n_of_page \c_page_floats_n_of_page \plustwo
33
34\newconstant\c_page_floats_insertions_topskip_mode
35
36\def\page_floats_report_total
37 {\showmessage\m!floatblocks4
38 {\the\totalnoffloats
39 \ifempty\floatlocationmethod
40 \ifempty\floatlocation\else,\floatlocation\fi
41 \else
42 ,\floatlocationmethod
43 \fi}}
44
45\def\page_floats_report_flushed
46 {\showmessage\m!floatblocks3
47 {\the\numexpr\totalnoffloats\savednoffloats\relax}}
48
49
50
51\newconditional\c_page_floats_room
52\newconditional\c_page_floats_some_waiting
53\newconditional\c_page_floats_not_permitted
54\newconditional\c_page_floats_flushing
55\newconditional\c_page_floats_center_box \c_page_floats_center_box\conditionaltrue
56\newconditional\c_page_floats_center_box_local
57\newconditional\c_page_floats_center_box_global
58\newconditional\c_page_floats_compress_flushed \c_page_floats_compress_flushed\conditionaltrue
59
60\newdimension \d_page_floats_compress_distance
61
62
63
64\newinteger \totalnoffloats
65\newinteger \savednoffloats
66\newinteger \nofcollectedfloats
67\newdimension\maxcollectedfloatstotal
68\newinteger \noffloatinserts
69
70\newbox \floattext
71
72\newdimension\floatwidth
73\newdimension\floatheight
74\newdimension\floatdepth
75\newdimension\floattextwidth
76\newdimension\floattextheight
77
78\newbox \floatbox
79\newbox \savedfloatbox
80
81
82
83
84
85
86\newtoks \everyfloatscheck
87
88\appendtoks
89 \ifcase\savednoffloats
90 \global\c_page_floats_some_waiting\conditionalfalse
91 \else
92 \global\c_page_floats_some_waiting\conditionaltrue
93 \fi
94\to \everyfloatscheck
95
96\protected\def\page_floats_flush#1#2
97 {\clf_flushfloat{#1}#2\relax
98 \expand\everyfloatscheck}
99
100\protected\def\page_floats_flush_by_label#1#2
101 {\clf_flushlabeledfloat{#1}{#2}\relax
102 \expand\everyfloatscheck}
103
104\protected\def\page_floats_save#1
105 {\clf_savefloat{#1}\relax
106 \expand\everyfloatscheck}
107
108\protected\def\page_floats_resave#1
109 {\clf_resavefloat{#1}\relax
110 \expand\everyfloatscheck}
111
112\protected\def\page_floats_push_saved
113 {\clf_pushfloat
114 \expand\everyfloatscheck}
115
116\protected\def\page_floats_pop_saved
117 {\clf_popfloat
118 \expand\everyfloatscheck}
119
120\protected\def\page_floats_get_info#1
121 {\clf_consultfloat{#1}}
122
123\protected\def\page_floats_if_else#1
124 {\clf_doifelsestackedfloats{#1}}
125
126\protected\def\page_floats_collect#1#2#3
127 {\clf_collectfloat{#1}\dimexpr#2\relax\dimexpr#3\relax}
128
129\permanent\def\nofstackedfloatsincategory#1
130 {\clf_nofstackedfloats{#1}}
131
132\let\page_floats_column_push_saved\page_floats_push_saved
133\let\page_floats_column_pop_saved \page_floats_pop_saved
134
135\protected\def\page_floats_save_page_float#1#2
136 {\clf_savespecificfloat{#1}{specification{#2}}\relax}
137
138\protected\def\page_floats_save_somewhere_float#1#2
139 {\clf_savespecificfloat{#1}{specification{#2}label{\floatlabel}}\relax}
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158\permanent\tolerant\protected\def\placenamedfloat[#1]#*[#2]
159 {\doloop
160 {\page_floats_flush_by_label\s!somewhere{#2}
161 \ifvoid\floatbox
162 \exitloop
163 \else
164 \cdef\currentfloat{#1}
165 \blank[\rootfloatparameter\c!spacebefore]
166 \box\floatbox
167 \blank[\rootfloatparameter\c!spaceafter]
168 \fi}}
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190\newbox\b_strc_float_saved
191
192\permanent\tolerant\protected\def\placesavedfloat[#1]#*[#2]#*[#S#3]
193 {\clf_flushlabeledfloat\s!somewhere{#2}\relax
194
195 \setbox\b_strc_float_saved\vpack{\box\floatbox}
196 \startplacefloat[#1][\c!location=\v!none,#3]
197 \box\b_strc_float_saved
198 \stopplacefloat}
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214\mutable\lettonothing\floatsetupcaption
215\mutable\lettonothing\floatsetupcontent
216\mutable\lettonothing\floatsetupwidth
217\mutable\lettonothing\floatsetupheight
218
219\aliased\let\placesetupfloat\gobbleoneoptional
220
221\permanent\tolerant\protected\def\placefloatwithsetups[#1]#*[#S#2]#*[#S#3]#:#4
222 {\def\floatsetupcaption{#4}
223 \def\floatsetupcontent{\copy\nextbox}
224 \def\floatsetupwidth {\wd\nextbox}
225 \def\floatsetupheight {\ht\nextbox}
226 \enforced\permanent\protected\def\placesetupfloat[##1]
227 {\placefloat[##1][#2][#3]{#4}{\floatsetupcontent}}
228 \dowithnextbox{\setups[#1]}\vbox}
229
230
231
232
233
234
235\def\page_floats_get_used_hsize{\hsize}
236
237\protected\def\page_floats_get
238 {\ifconditional\c_page_floats_some_waiting
239 \page_floats_flush\s!text\plusone
240 \ifconditional\c_page_floats_center_box
241 \ifdim\wd\globalscratchbox<\page_floats_get_used_hsize
242 \global\setbox\floatbox\hpack to \page_floats_get_used_hsize{\hss\box\floatbox\hss}
243 \orelse\ifinsidecolumns
244
245 \ifdim\wd\floatbox>\makeupwidth
246 \wd\floatbox\makeupwidth
247 \fi
248 \fi
249 \fi
250 \else
251 \global\savednoffloats\zerocount
252 \global\setbox\floatbox\emptybox
253 \fi}
254
255\protected\def\page_floats_flush_saved
256 {\doloop
257 {\ifconditional\c_page_floats_some_waiting
258 \page_otr_command_check_if_float_fits
259 \ifconditional\c_page_floats_room
260 \page_floats_get
261 \doplacefloatbox
262 \else
263 \exitloop
264 \fi
265 \else
266
267
268
269 \exitloop
270
271 \fi}}
272
273
274
275
276
277
278
279
280
281
282\permanent\protected\def\placefloatplaceholder
283 {\ifconditional\c_page_floats_room \else
284 \ifdim\dimexpr\pagegoal\pagetotal3\lineheight\relax>\zeropoint
285 \startlinecorrection[blank]
286 \mhbox{\inframed{\labeltexts{placeholder}{\m_strc_floats_last_caption_tag}}}
287 \stoplinecorrection
288 \else
289 \allowbreak
290 \fi
291 \fi}
292
293\setuplabeltext
294 [placeholder={\Word{\lastplacedfloat}, moved}]
295
296
297
298\newtoks\everybeforeflushedpagefloat
299
300\let\m_page_otr_checked_page_float\relax
301
302\newconditional\c_page_floats_flushed
303
304\def\page_floats_flush_page_floats_inject#1
305 {\page_floats_flush{#1}\plusone
306 \edef\floatspecification{\clf_getfloatvariable{specification}}
307 \expand\everybeforeflushedpagefloat
308 \vpack to \textheight
309 {\ifinset\v!high\floatspecification\else\vfill\fi
310 \box\floatbox
311 \ifinset\v!low \floatspecification\else\vfill\fi}
312 \page_otr_fill_and_eject_page
313 \global\c_page_floats_flushed\conditionaltrue}
314
315\protected\def\page_floats_flush_page_floats
316 {\global\c_page_floats_flushed\conditionalfalse
317 \page_floats_flush_page_floats_indeed
318 \ifconditional\c_page_floats_flushed
319 \page_otr_fill_and_eject_page
320 \fi}
321
322\protected\def\page_floats_flush_page_floats_indeed
323 {\edef\m_page_otr_checked_page_float{\clf_checkedpagefloat}
324 \ifempty\m_page_otr_checked_page_float
325
326 \orelse\ifx\m_page_otr_checked_page_float\v!empty
327 \emptyhbox \page_otr_fill_and_eject_page
328 \expandafter\page_floats_flush_page_floats
329 \else
330 \page_floats_flush_page_floats_inject\m_page_otr_checked_page_float
331 \expandafter\page_floats_flush_page_floats
332 \fi}
333
334
335
336
337
338
339
340
341\appendtoks
342 \global\setbox\savedfloatbox\box\floatbox
343\to \everybeforeoutput
344
345\appendtoks
346 \global\setbox\floatbox\box\savedfloatbox
347\to \everyafteroutput
348
349\protect \endinput
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375 |