1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Page Macros Facing floats}
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\unprotect
65
66
67
68
69
70
71
72
73
74
75
76
77
78\newdimension\d_page_adapts_preroll
79\newinteger \c_page_adapts_pushed
80
81
82
83
84
85\def\page_adapts_layout_preroll#1
86 {\begingroup
87 \global\d_page_adapts_preroll\zeropoint
88 \def\page_adapts_layout_indeed##1
89 {\setupcurrentadaptlayout[\c!top=\zeropoint,##1]
90 \global\d_page_adapts_preroll\dimexpr\adaptlayoutparameter\c!top\relax}
91 \begincsname\??pageadaptations\number#1\endcsname
92 \endgroup}
93
94\permanent\protected\def\registertopcontent[#1]
95 {\begingroup
96 \dowithnextbox
97 {\page_adapts_layout_preroll{#1}
98 \scratchdimen\dimexpr
99 \htdp\nextbox\d_page_adapts_preroll
100 \ifzeropt\d_page_adapts_preroll
101 \lineheight
102 \fi
103 \relax
104 \putboxincache{\v!page:\number#1}{}\nextbox
105 \normalexpanded{\adaptlayout[\number#1][\c!top=\the\scratchdimen]}
106 \global\advanceby\c_page_adapts_pushed\plusone
107 \endgroup}}
108
109\def\page_otr_flush_top_content
110 {\scratchcounter\getboxcountfromcache{\v!page:\the\realpageno}\relax
111 \ifcase\scratchcounter\else
112 \dorecurse\scratchcounter
113 {\directboxfromcache{\v!page:\the\realpageno}\recurselevel
114 \nointerlineskip
115 \par}
116 \disposeboxesincache{\v!page:\the\realpageno}
117 \global\advanceby\c_page_adapts_pushed\minusone
118 \nointerlineskip
119 \fi}
120
121\permanent\protected\def\flushpendingtopcontent
122 {\ifcase\c_page_adapts_pushed\else
123 \null
124 \page
125 \expandafter\flushpendingtopcontent
126 \fi}
127
128
129
130
131
132\def\page_check_weird_page_indeed
133 {\ifdim\vsize>\zeropoint\else
134
135 \writestatus\m!layouts{forcing zero height page}
136 \emptyhbox\page
137 \fi}
138
139
140
141
142
143
144
145
146
147\installcorenamespace {facingfloat}
148
149\installframedcommandhandler \??facingfloat {facingfloat} \??facingfloat
150
151\setupfacingfloat
152 [\c!spaceinbetween=\v!big,
153 \c!inbetween={\blank[\v!big]},
154
155
156
157 \c!width=\v!fit]
158
159\newinteger\c_defining_facing_float
160
161\appendtoks
162 \advanceby\c_defining_facing_float\plusone
163 \ifcase\c_defining_facing_float\or
164 \normalexpanded{
165 \definefacingfloat[\currentfacingfloat:\v!left ][\currentfacingfloat]
166 \definefacingfloat[\currentfacingfloat:\v!right][\currentfacingfloat]
167 }
168 \fi
169 \advanceby\c_defining_facing_float\minusone
170\to \everydefinefacingfloat
171
172\newinteger\c_strc_floats_facing_saved
173\newinteger\c_strc_floats_facing_flushed
174\newbox \b_strc_floats_facing_l
175\newbox \b_strc_floats_facing_r
176
177\let\m_strc_floats_state\relax
178
179\installcorenamespace {facingfloatflusher}
180
181\def\strc_floats_facing_flush_indeed_step#1#2#3
182 {\ifnum#2<#3\relax
183 \advanceby#2\plusone
184 \donetrue
185 \writestatus
186 {facing}
187 {page: \the\scratchcounterone, location: #1, blob: \the#2, max: \the#3}
188 \registertopcontent
189 [\scratchcounterone]
190 \hbox{\directboxfromcache{\currentfacingfloat:#1}{\the#2}}
191 \fi}
192
193\def\strc_floats_facing_flush_indeed#1
194 {\begingroup
195 \cdef\currentfacingfloat{#1}
196 \glet\page_check_weird_page\page_check_weird_page_indeed
197 \scratchcounterone \realpageno
198 \scratchcounterthree\getboxcountfromcache{\currentfacingfloat:\v!left }\relax
199 \scratchcounterfour \getboxcountfromcache{\currentfacingfloat:\v!right}\relax
200 \scratchcounterfive \zerocount
201 \scratchcountersix \zerocount
202
203 \ifdim\pagetotal>\zeropoint
204 \advanceby\scratchcounterone\plusone
205 \fi
206 \ifodd\scratchcounterone
207 \advanceby\scratchcounterone\plusone
208 \fi
209 \writestatus
210 {facing}
211 {page: \the\scratchcounterone, start checking}
212 \doloop{
213 \page_adapts_layout_preroll\scratchcounterone
214 \ifzeropt\d_page_adapts_preroll
215
216 \advanceby\scratchcounterone\plusone
217 \page_adapts_layout_preroll\scratchcounterone
218 \ifzeropt\d_page_adapts_preroll
219
220 \advanceby\scratchcounterone\minusone
221 \exitloop
222 \fi
223 \else
224 \advanceby\scratchcounterone\plustwo
225 \fi
226 }
227 \writestatus
228 {facing}
229 {page: \the\scratchcounterone, start flushing}
230 \doloop{
231 \ifodd\scratchcounterone
232 \strc_floats_facing_flush_indeed_step\v!right\scratchcountersix \scratchcounterfour
233 \else
234 \strc_floats_facing_flush_indeed_step\v!left \scratchcounterfive\scratchcounterthree
235 \fi
236 \ifnum\scratchcountersix<\scratchcounterfour
237
238 \orelse\ifnum\scratchcounterfive<\scratchcounterthree
239
240 \else
241 \exitloop
242 \fi
243 \advanceby\scratchcounterone\plusone
244 }
245 \disposeboxesincache{\currentfacingfloat:\v!right}
246 \disposeboxesincache{\currentfacingfloat:\v!left}
247 \page_check_weird_page_indeed
248 \endgroup}
249
250\permanent\protected\tolerant\def\flushfacingfloats[#1]
251 {\processcommalist[#1]\strc_floats_facing_flush_indeed}
252
253\protected\def\strc_floats_facing_setup
254 {\cdef\currentfacingfloat{\currentfacingfloat:\m_strc_floats_state}
255 \usefacingfloatstyleandcolor\c!style\v!color}
256
257\protected\def\strc_floats_facing_collect
258 {\ifx\m_strc_floats_state\v!left
259 \ifvoid\nextbox\orelse\ifzeropt\wd\nextbox\else
260 \ifvoid\b_strc_floats_facing_l
261 \setbox\b_strc_floats_facing_l\box\nextbox
262 \else
263 \setbox\b_strc_floats_facing_l\vbox\bgroup
264 \unvbox\b_strc_floats_facing_l
265 \facingfloatparameter\c!inbetween
266 \unvbox\nextbox
267 \egroup
268 \fi
269 \fi
270 \let\m_strc_floats_state\v!right
271 \orelse\ifx\m_strc_floats_state\v!right
272 \ifvoid\nextbox\orelse\ifzeropt\wd\nextbox\else
273 \ifvoid\b_strc_floats_facing_r
274 \setbox\b_strc_floats_facing_r\box\nextbox
275 \else
276 \setbox\b_strc_floats_facing_r\vbox\bgroup
277 \unvbox\b_strc_floats_facing_r
278 \facingfloatparameter\c!inbetween
279 \unvbox\nextbox
280 \egroup
281 \fi
282 \fi
283 \let\m_strc_floats_state\v!left
284 \else
285 \let\m_strc_floats_state\v!left
286 \fi}
287
288\protected\def\strc_floats_facing_handle
289 {\doifnextbgroupelse
290 \strc_floats_facing_handle_indeed
291 \strc_floats_facing_wrap_up}
292
293\protected\def\strc_floats_facing_handle_indeed
294 {\dowithnextboxcontent
295 \strc_floats_facing_setup
296 {\strc_floats_facing_collect\strc_floats_facing_handle}
297 \vbox}
298
299\permanent\protected\def\startfacingfloat[#1]
300 {\begingroup
301 \cdef\currentfacingfloat{#1}
302 \edef\p_width{\facingfloatparameter\c!width}
303 \letfacingfloatparameter\c!width\v!fit
304 \ifx\p_width\v!frame
305 \setbox\scratchbox\hpack{\inheritedfacingfloatframed{}}
306 \advanceby\hsize\wd\scratchbox
307 \orelse\ifx\p_width\v!fit
308
309 \else
310 \hsize\p_width
311 \fi
312 \enforced\let\startcontent\bgroup
313 \enforced\let\stopcontent\egroup
314 \let\m_strc_floats_state\v!left
315 \strc_floats_facing_handle}
316
317\permanent\protected\def\stopfacingfloat
318 {\endgroup}
319
320\protected\def\strc_floats_facing_wrap_up
321 {\edef\p_spaceinbetween{\facingfloatparameter\c!spaceinbetween}
322 \ifempty\p_spaceinbetween
323 \scratchdimen\zeropoint
324 \else
325 \setbox\scratchbox\vbox{\directvspacing\p_spaceinbetween}
326 \scratchdimen\htdp\scratchbox
327 \fi
328 \ifvoid\b_strc_floats_facing_l\else
329 \page_postprocessors_linenumbers_box\b_strc_floats_facing_l
330 \fi
331 \ifvoid\b_strc_floats_facing_r\else
332 \page_postprocessors_linenumbers_box\b_strc_floats_facing_r
333 \fi
334 \doloop{
335 \strc_floats_facing_flush_wrap\b_strc_floats_facing_l\v!left
336 \strc_floats_facing_flush_wrap\b_strc_floats_facing_r\v!right
337 \global\advanceby\c_strc_floats_facing_saved\plusone
338 \ifvoid\b_strc_floats_facing_l\relax\ifvoid\b_strc_floats_facing_r\relax
339 \exitloop
340 \fi\fi}}
341
342\def\strc_floats_facing_flush_wrap#1#2
343 {\ifvoid#1\relax
344
345 \else
346 \begingroup
347 \setbox\scratchboxone\hpack\bgroup
348 \cdef\currentfacingfloat{\currentfacingfloat:#2}
349 \inheritedfacingfloatframed{\strut}
350 \egroup
351 \scratchdimenone\dimexpr\textheight\htdp\scratchboxone\lineheight\relax
352 \dontcomplain
353 \splittopskip\zeroskip
354 \setbox\scratchbox\vsplit#1 upto \scratchdimenone
355 \setsplitlisthtdp\scratchbox\strutht\strutdp
356 \setbox\scratchbox\hpack\bgroup
357 \cdef\currentfacingfloat{\currentfacingfloat:#2}
358 \inheritedfacingfloatframed{\box\scratchbox}
359 \egroup
360 \setbox\scratchbox\vbox
361 \ifdim\ht\scratchbox<\dimexpr\textheight\scratchdimen\relax
362 {\box\scratchbox\directvspacing\p_spaceinbetween}
363 \else
364 to \textheight{\box\scratchbox\vss}
365 \fi
366 \putboxincache{\currentfacingfloat:#2}{}\scratchbox
367 \endgroup
368 \fi}
369
370\protect \endinput
371 |