page-ini.mkiv /size: 11 Kb    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=page-ini,
3%D        version=2000.10.20,
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Initializations,
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 / Initializations}
15
16\registerctxluafile{page-ini}{}
17
18%D The \type {\processpage} command has become obsolete. It's original
19%D purpose was to flush only parts of a document but nowadays we have
20%D project structure and modes. This is just one of those very early
21%D features that no longer makes sense.
22
23%D The \type {\couplepage} command has become obsolete. It's original
24%D purpose was to provide hooks for printer directives (like choosing
25%D different paper trays).
26
27\unprotect
28
29%D Shipout control.
30
31\newcount\nofshipouts
32
33\appendtoks
34    \global\advance\nofshipouts\plusone
35\to \everyaftershipout
36
37\newconditional\c_otr_shipout_enabled \settrue\c_otr_shipout_enabled
38
39\unexpanded\def\page_otr_shipout % not used at all
40  {\ifconditional\c_otr_shipout_enabled
41     \expandafter\page_otr_shipout_yes
42   \else
43     \expandafter\page_otr_shipout_nop
44   \fi}
45
46\let\page_otr_shipout_yes\normalshipout
47
48\unexpanded\def\page_otr_shipout_nop
49  {\writestatus\m!system{ignoring shipout of real page \the\realpageno}%
50   \global\advance\realpageno\minusone % else no flush of resources
51   \dowithnextbox{\deadcycles\zerocount}}
52
53% We don't support direct user \shipouts (weird: this does not work, bug?)
54%
55% \let\shipout\page_otr_shipout_nop
56
57%D Building pages.
58
59\newbox\pagebox
60
61% \ifdefined\page_postprocessors_column \else \let\page_postprocessors_column\gobbleoneargument \fi
62% \ifdefined\page_postprocessors_page   \else \let\page_postprocessors_page  \gobbleoneargument \fi
63% \ifdefined\page_postprocessors_box    \else \let\page_postprocessors_box   \gobbleoneargument \fi
64
65\newtoks\t_page_postprocessors_box
66\newtoks\t_page_postprocessors_page
67\newtoks\t_page_postprocessors_column
68
69\newconstant\b_page_postprocessor
70
71\def\page_apply_postprocessors_box#1%
72  {\b_page_postprocessor#1\relax
73   \the\t_page_postprocessors_box}
74
75\def\page_apply_postprocessors_page#1%
76  {\b_page_postprocessor#1\relax
77   \the\t_page_postprocessors_page}
78
79\def\page_apply_postprocessors_column#1%
80  {\b_page_postprocessor#1\relax
81   \the\t_page_postprocessors_column}
82
83%D Floats.
84
85\def\page_otr_flush_all_floats
86  {%\flushnotes already done
87   \ifconditional\c_page_floats_some_waiting
88     \page_otr_command_flush_all_floats
89   \fi}
90
91\def\page_otr_insert_dummy_page
92  {\par
93   \ifvmode
94     \page_otr_flush_all_floats
95     \fixedspace
96     \vfill
97     \page_otr_command_next_page
98   \fi}
99
100\def\page_otr_flush_pending_content
101  {\vkern\zeropoint\relax
102   \ifvoid\normalpagebox \else
103     \unvbox\normalpagebox
104     \penalty\outputpenalty
105   \fi}
106
107\newconstant\c_page_postponed_mode % \c_page_postponed_mode\plusone
108\newbox     \b_page_otr_saved
109
110\installoutputroutine\savepagecontent
111  {\global\setbox\b_page_otr_saved\box\normalpagebox}
112
113\unexpanded\def\flushpagecontent
114  {\ifvoid\b_page_otr_saved\else\unvbox\b_page_otr_saved\fi}
115
116% Test case: assumes one group level for output routine, todo:
117% a toks.
118%
119% \starttext
120%
121% \startbuffer[makeup]
122% \startpagemakeup[pagestate=start,page=no]
123%     \color[red]{
124%         \vfill
125%         \dorecurse{3}{
126%             \samplefile{klein}
127%             \vfill
128%         }
129%     }
130% \stoppagemakeup
131% \stopbuffer
132%
133% \startcolor[green]
134%     \dorecurse{10}{
135%         \dontleavehmode{\bf 1:#1:} \samplefile{sapolsky}\par
136%     }
137% \stopcolor
138%
139% \startpostponing % [+3]
140%     \getbuffer[makeup]
141% \stoppostponing
142%
143% \startcolor[blue]
144%     \dorecurse{25}{
145%         \dontleavehmode{\bf 2:#1:} \samplefile{sapolsky}\par
146%     }
147% \stopcolor
148%
149% \stoptext
150
151\def\page_otr_construct_and_shipout#1#2#3%
152  {\forgetall
153   \page_boxes_shipout{\page_boxes_constructed_page#1#2}% \hbox removed
154   \page_otr_flush_pending_content
155   % not really needed, replaced by \flushsavedfloats
156   \page_otr_check_for_pending_inserts
157   % but does not hurt either (we're still in the otr!)
158   \inpagebodytrue      % needed for enabling \blank ! brrr
159   \pagebodymode\plusone % todo: \plustwo when spread
160   \page_otr_command_flush_saved_floats
161   \page_otr_command_set_vsize   % this is needed for interacting components, like floats and multicolumns
162   \strc_pagenumbers_increment_counters % should hook into an every
163   \page_adapts_synchronize
164   \page_otr_check_for_pending_inserts
165   \page_otr_command_flush_facing_floats
166   \page_floats_flush_page_floats % before postponed blocks
167   \page_spread_flush % defined later
168   \ifnum#3=\plusone
169     % this is tricky! we need to make sure we are in the output group
170     \ifnum\c_page_postponed_mode=\plusone
171       \aftergroup\page_postponed_blocks_flush
172     \else
173       \page_postponed_blocks_flush
174     \fi
175   \else
176     \page_postponed_blocks_flush
177   \fi}
178
179% Can't we get rid of this hackery? It's used in some widgets
180% stuff so probably not.
181
182\newbox\b_page_otr_special
183
184\def\page_otr_flush_special_content
185  {\ifvoid\b_page_otr_special \else
186     \box\b_page_otr_special
187   \fi}
188
189\def\page_otr_add_special_content
190  {\dowithnextboxcs\page_otr_add_special_content_indeed\hbox}
191
192\def\page_otr_add_special_content_indeed
193  {\wd\nextbox\zeropoint
194   \ht\nextbox\zeropoint
195   \dp\nextbox\zeropoint
196   \global\setbox\b_page_otr_special\hbox
197     {%\hskip-\maxdimen                    % not here, fails in acrobat (clips)
198      \box\b_page_otr_special\box\nextbox}}% was \unhbox, is now box again
199
200\let\flushatshipout\page_otr_add_special_content
201
202\maxdeadcycles=1000
203
204\newtoks\afterpage     \newtoks\aftereverypage
205\newtoks\beforepage    \newtoks\beforeeverypage
206
207\newif\ifarrangingpages \arrangingpagesfalse
208
209\newconstant\pageornamentstate % 0=on 1=one-off 2=always-off
210
211% \appendtoks
212%     \ifcase\pageornamentstate \or
213%         \pageornamentstate\zerocount
214%     \fi
215% \to \everyaftershipout
216
217\appendtoks
218    \ifcase\pageornamentstate \or
219        \global\pageornamentstate\zerocount
220    \fi
221\to \everyaftershipout
222
223% Mark synchronization
224
225\newconditional\c_page_marks_building_successive_pages \settrue\c_page_marks_building_successive_pages
226
227\def\page_marks_synchronize_page#1% box
228  {\strc_markings_synchronize[\v!page][#1][\ifconditional\c_page_marks_building_successive_pages\v!keep\fi]}
229
230\def\page_marks_synchronize_column#1#2#3#4% first last column box
231  {\ifnum#3=#1\relax
232     \strc_markings_synchronize[\number#3,\v!column:\number#3,\v!first,\v!column:\v!first][#4][]%
233   \else\ifnum#3=#2\relax
234     \strc_markings_synchronize[\number#3,\v!column:\number#3,\v!last, \v!column:\v!last ][#4][]%
235   \else
236     \strc_markings_synchronize[\number#3,\v!column:\number#3                            ][#4][]%
237   \fi\fi}
238
239% Page body building
240
241\newconditional\c_page_boxes_save_page_body
242\newbox        \b_page_boxes_saved_page_body
243
244\def\page_boxes_constructed_page_body#1#2%
245  {\ifconditional\c_page_boxes_save_page_body \global\setbox\b_page_boxes_saved_page_body \fi \vpack \bgroup
246      \boxmaxdepth\maxdimen % new
247      \dontcomplain
248      \page_marks_synchronize_page                    {#2}%  we could consider doing this for \pagebox (needs testing)
249      \page_boxes_construct_content       \pagebox{#1}{#2}%
250      \page_backgrounds_add_to_main       \pagebox
251      \page_boxes_apply_offsets           \pagebox
252      \page_info_add_to_box               \pagebox
253      \ifcase\pageornamentstate
254        \page_backgrounds_add_to_paper    \pagebox
255      \fi
256      \anch_positions_register_page       \pagebox
257      \ifarrangingpages
258        \page_boxes_apply_shift_paper     \pagebox % \v!paper
259      \else
260        \page_boxes_apply_clip_paper      \pagebox
261        \page_marks_add_page              \pagebox
262        \page_boxes_apply_replicate       \pagebox
263        \page_boxes_apply_scale           \pagebox
264        \page_boxes_apply_mirror_paper    \pagebox
265        \page_boxes_apply_orientate_paper \pagebox
266        \page_marks_add_more              \pagebox
267        \page_boxes_apply_center          \pagebox
268        \page_backgrounds_add_to_print    \pagebox
269        \page_boxes_apply_mirror_print    \pagebox
270        \page_boxes_apply_orientate_print \pagebox
271        \page_boxes_apply_shift_print     \pagebox % \v!page
272        \page_boxes_apply_offset          \pagebox
273        \page_boxes_apply_negate_print    \pagebox
274      \fi
275      \box\pagebox
276   \egroup \ifconditional\c_page_boxes_save_page_body \copy\b_page_boxes_saved_page_body \fi}
277
278\appendtoks
279    \restoreglobalbodyfont
280    \pickupattributes
281\to \everybeforepagebody
282
283\ifdefined\nestednewbox \else \newbox\nestednextbox \fi % hm, still needed?
284
285\prependtoks
286    \let\nextbox\nestednextbox
287\to \everybeforepagebody
288
289\def\page_boxes_constructed_page#1#2%
290  {\vpack\bgroup % intercept spurious spaces
291     \the\everybeforepagebody
292     \starttextproperties
293     \checkmarginblocks
294     \the\beforeeverypage
295     \normalexpanded{\global\beforepage\emptytoks\the\beforepage}%
296     \inpagebodytrue
297     \pagebodymode\plusone % todo: \plustwo when spread
298     \page_boxes_constructed_page_body#1#2%
299     \normalexpanded{\global\afterpage \emptytoks\the\afterpage }%
300     \the\aftereverypage
301     \resetpagebreak
302     \resetlayouttextlines % will go to \aftereverypage
303     \stoptextproperties
304     \the\everyafterpagebody
305   \egroup}
306
307\def\doifelsetopofpage
308  {\ifdim\pagegoal=\maxdimen
309     \expandafter\firstoftwoarguments
310   \else\ifdim\pagegoal=\vsize
311     \doubleexpandafter\firstoftwoarguments
312   \else
313     \doubleexpandafter\secondoftwoarguments
314   \fi\fi}
315
316\let\doiftopofpageelse\doifelsetopofpage
317
318% %D Idea:
319%
320% \newinsert\thispageinsert % <- installinsertion
321%
322% \def\flushatthispage
323%   {\bgroup
324%    \dowithnextbox{\insert\thispageinsert{\box\nextbox}\egroup}%
325%    \hbox}
326%
327% \appendtoks
328%     \ifvoid\thispageinsert\else\hbox{\smashedbox\thispageinsert}\fi
329% \to \everyshipout
330
331% not yet in i-* file
332
333\installcorenamespace{markedpage}
334
335\unexpanded\def\markpage
336  {\dotripleempty\page_mark}
337
338\def\page_mark[#1][#2][#3]%
339  {\clf_markpage{#1}{#2}{#3}}
340
341\def\markedpages[#1]% expandable
342  {\clf_markedpages{#1}}
343
344\unexpanded\def\doifelsemarkedpage#1%
345  {\clf_doifelsemarkedpage{#1}}
346
347\unexpanded\def\doifmarkedpage#1%
348  {\clf_doifmarkedpage{#1}}
349
350\unexpanded\def\startmarkpages
351  {\dodoubleempty\page_start_marked}
352
353\def\page_start_marked[#1][#2]%
354  {\clf_startmarkpages{#1}{#2}}
355
356\unexpanded\def\stopmarkpages
357  {\clf_stopmarkpages}
358
359\unexpanded\def\checkmarkedpages
360  {\clf_checkmarkedpages}
361
362\def\markedpageparameter#1#2%
363  {\clf_markedpageparameter{#1}{#2}}
364
365\appendtoks
366    \checkmarkedpages
367\to \everyaftershipout
368
369%D Experimental:
370
371\newconstant\c_page_force_strut_depth_trace_mode
372
373\installtextracker
374  {otr.forcestrutdepth}
375  {\c_page_force_strut_depth_trace_mode\plusone}
376  {\c_page_force_strut_depth_trace_mode\zerocount}
377
378\installoutputroutine\forcestrutdepth
379  {\clf_forcestrutdepth\normalpagebox\strutdp\c_page_force_strut_depth_trace_mode
380   \unvbox\normalpagebox}
381
382\installoutputroutine\forcestrutdepthplus % experimental
383  {\clf_forcestrutdepthplus\normalpagebox\strutdp\c_page_force_strut_depth_trace_mode
384   \unvbox\normalpagebox}
385
386% maybe better:
387%
388% \installoutputroutine\doforcestrutdepth
389%   {\clf_forcestrutdepth\normalpagebox\strutdp\c_page_force_strut_depth_trace_mode
390%    \unvbox\normalpagebox}
391%
392% \unexpanded\def\forcestrutdepth
393%   {\par\ifvmode\ifinner\else\doforcestrutdepth\fi\fi}
394
395% Also experimental:
396
397\unexpanded\def\doifelsependingpagecontent{\clf_doifelsependingpagecontent}
398
399\protect \endinput
400