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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
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
376
|
%D \module
%D [ file=page-ini,
%D version=2000.10.20,
%D title=\CONTEXT\ Page Macros,
%D subtitle=Initializations,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\writestatus{loading}{ConTeXt Page Macros / Initializations}
\registerctxluafile{page-ini}{}
%D The \type {\processpage} command has become obsolete. It's original
%D purpose was to flush only parts of a document but nowadays we have
%D project structure and modes. This is just one of those very early
%D features that no longer makes sense.
%D The \type {\couplepage} command has become obsolete. It's original
%D purpose was to provide hooks for printer directives (like choosing
%D different paper trays).
\unprotect
%D Shipout control.
\newcount\nofshipouts
\appendtoks
\global\advance\nofshipouts\plusone
\to \everyaftershipout
\newconditional\c_otr_shipout_enabled \settrue\c_otr_shipout_enabled
\protected\def\page_otr_shipout % not used at all
{\ifconditional\c_otr_shipout_enabled
\expandafter\page_otr_shipout_yes
\else
\expandafter\page_otr_shipout_nop
\fi}
\aliased\let\page_otr_shipout_yes\normalshipout
\protected\def\page_otr_shipout_nop
{\writestatus\m!system{ignoring shipout of real page \the\realpageno}%
\global\advance\realpageno\minusone % else no flush of resources
\dowithnextbox{\deadcycles\zerocount}}
% We don't support direct user \shipouts (weird: this does not work, bug?)
%
% \let\shipout\page_otr_shipout_nop
%D Building pages.
\newbox\pagebox
% \ifdefined\page_postprocessors_column \else \let\page_postprocessors_column\gobbleoneargument \fi
% \ifdefined\page_postprocessors_page \else \let\page_postprocessors_page \gobbleoneargument \fi
% \ifdefined\page_postprocessors_box \else \let\page_postprocessors_box \gobbleoneargument \fi
\newtoks\t_page_postprocessors_box
\newtoks\t_page_postprocessors_page
\newtoks\t_page_postprocessors_column
\newconstant\b_page_postprocessor
\def\page_apply_postprocessors_box#1%
{\b_page_postprocessor#1\relax
\the\t_page_postprocessors_box}
\def\page_apply_postprocessors_page#1%
{\b_page_postprocessor#1\relax
\the\t_page_postprocessors_page}
\def\page_apply_postprocessors_column#1%
{\b_page_postprocessor#1\relax
\the\t_page_postprocessors_column}
%D Floats.
\def\page_otr_flush_all_floats
{%\flushnotes already done
\ifconditional\c_page_floats_some_waiting
\page_otr_command_flush_all_floats
\fi}
\def\page_otr_insert_dummy_page
{\par
\ifvmode
\page_otr_flush_all_floats
\fixedspace
\vfill
\page_otr_command_next_page
\fi}
\def\page_otr_flush_pending_content
{\vkern\zeropoint\relax
\ifvoid\normalpagebox \else
\unvbox\normalpagebox
\penalty\outputpenalty
\fi}
\newconstant\c_page_postponed_mode % \c_page_postponed_mode\plusone
\newbox \b_page_otr_saved
\installoutputroutine\savepagecontent
{\global\setbox\b_page_otr_saved\box\normalpagebox}
\permanent\protected\def\flushpagecontent
{\ifvoid\b_page_otr_saved\else\unvbox\b_page_otr_saved\fi}
% Test case: assumes one group level for output routine, todo:
% a toks.
%
% \starttext
%
% \startbuffer[makeup]
% \startpagemakeup[pagestate=start,page=no]
% \color[red]{
% \vfill
% \dorecurse{3}{
% \samplefile{klein}
% \vfill
% }
% }
% \stoppagemakeup
% \stopbuffer
%
% \startcolor[green]
% \dorecurse{10}{
% \dontleavehmode{\bf 1:#1:} \samplefile{sapolsky}\par
% }
% \stopcolor
%
% \startpostponing % [+3]
% \getbuffer[makeup]
% \stoppostponing
%
% \startcolor[blue]
% \dorecurse{25}{
% \dontleavehmode{\bf 2:#1:} \samplefile{sapolsky}\par
% }
% \stopcolor
%
% \stoptext
\def\page_otr_construct_and_shipout#1#2#3%
{\forgetall
\page_boxes_shipout{\page_boxes_constructed_page#1#2}% \hbox removed
\page_otr_flush_pending_content
% not really needed, replaced by \flushsavedfloats
\page_otr_check_for_pending_inserts
% but does not hurt either (we're still in the otr!)
\inpagebodytrue % needed for enabling \blank ! brrr
\pagebodymode\plusone % todo: \plustwo when spread
\page_otr_command_flush_saved_floats
\page_otr_command_set_vsize % this is needed for interacting components, like floats and multicolumns
\strc_pagenumbers_increment_counters % should hook into an every
\page_adapts_synchronize
\page_otr_check_for_pending_inserts
\page_otr_command_flush_facing_floats
\page_floats_flush_page_floats % before postponed blocks
\page_spread_flush % defined later
\ifnum#3=\plusone
% this is tricky! we need to make sure we are in the output group
\ifnum\c_page_postponed_mode=\plusone
\aftergroup\page_postponed_blocks_flush
\else
\page_postponed_blocks_flush
\fi
\else
\page_postponed_blocks_flush
\fi}
% Can't we get rid of this hackery? It's used in some widgets
% stuff so probably not.
\newbox\b_page_otr_special
\def\page_otr_flush_special_content
{\ifvoid\b_page_otr_special \else
\box\b_page_otr_special
\fi}
\def\page_otr_add_special_content
{\dowithnextboxcs\page_otr_add_special_content_indeed\hbox}
\def\page_otr_add_special_content_indeed
{\wd\nextbox\zeropoint
\ht\nextbox\zeropoint
\dp\nextbox\zeropoint
\global\setbox\b_page_otr_special\hbox
{%\hskip-\maxdimen % not here, fails in acrobat (clips)
\box\b_page_otr_special\box\nextbox}}% was \unhbox, is now box again
\let\flushatshipout\page_otr_add_special_content
\maxdeadcycles=1000
\newtoks\afterpage \newtoks\aftereverypage
\newtoks\beforepage \newtoks\beforeeverypage
\newif\ifarrangingpages \arrangingpagesfalse
\newconstant\pageornamentstate % 0=on 1=one-off 2=always-off
% \appendtoks
% \ifcase\pageornamentstate \or
% \pageornamentstate\zerocount
% \fi
% \to \everyaftershipout
\appendtoks
\ifcase\pageornamentstate \or
\global\pageornamentstate\zerocount
\fi
\to \everyaftershipout
% Mark synchronization
\newconditional\c_page_marks_building_successive_pages \settrue\c_page_marks_building_successive_pages
\def\page_marks_synchronize_page#1% box
{\strc_markings_synchronize\v!page{#1}{\ifconditional\c_page_marks_building_successive_pages\v!keep\fi}}
\def\page_marks_synchronize_column#1#2#3#4% first last column box
{\ifnum#3=#1\relax
\strc_markings_synchronize{\number#3,\v!column:\number#3,\v!first,\v!column:\v!first}{#4}{}%
\orelse\ifnum#3=#2\relax
\strc_markings_synchronize{\number#3,\v!column:\number#3,\v!last, \v!column:\v!last }{#4}{}%
\else
\strc_markings_synchronize{\number#3,\v!column:\number#3 }{#4}{}%
\fi}
% Page body building
\newconditional\c_page_boxes_save_page_body
\newbox \b_page_boxes_saved_page_body
\def\page_boxes_constructed_page_body#1#2%
{\ifconditional\c_page_boxes_save_page_body \global\setbox\b_page_boxes_saved_page_body \fi \vpack \bgroup
\boxmaxdepth\maxdimen % new
\dontcomplain
\page_marks_synchronize_page {#2}% we could consider doing this for \pagebox (needs testing)
\page_boxes_construct_content \pagebox{#1}{#2}%
\page_backgrounds_add_to_main \pagebox
\page_boxes_apply_offsets \pagebox
\page_info_add_to_box \pagebox
\ifcase\pageornamentstate
\page_backgrounds_add_to_paper \pagebox
\fi
\anch_positions_register_page \pagebox
\ifarrangingpages
\page_boxes_apply_shift_paper \pagebox % \v!paper
\else
\page_boxes_apply_clip_paper \pagebox
\page_marks_add_page \pagebox
\page_boxes_apply_replicate \pagebox
\page_boxes_apply_scale \pagebox
\page_boxes_apply_mirror_paper \pagebox
\page_boxes_apply_orientate_paper \pagebox
\page_marks_add_more \pagebox
\page_boxes_apply_center \pagebox
\page_backgrounds_add_to_print \pagebox
\page_boxes_apply_mirror_print \pagebox
\page_boxes_apply_orientate_print \pagebox
\page_boxes_apply_shift_print \pagebox % \v!page
\page_boxes_apply_offset \pagebox
\page_boxes_apply_negate_print \pagebox
\fi
\box\pagebox
\egroup \ifconditional\c_page_boxes_save_page_body \copy\b_page_boxes_saved_page_body \fi}
\appendtoks
\restoreglobalbodyfont
\pickupattributes
\to \everybeforepagebody
% if we really need this ... we need to bypass \permanent
% \ifdefined\nestednewbox \else \newbox\nestednextbox \fi % hm, still needed?
%
% \prependtoks
% \let\nextbox\nestednextbox
% \to \everybeforepagebody
\def\page_boxes_constructed_page#1#2%
{\vpack\bgroup % intercept spurious spaces
\the\everybeforepagebody
\starttextproperties
\checkmarginblocks
\the\beforeeverypage
\normalexpanded{\global\beforepage\emptytoks\the\beforepage}%
\inpagebodytrue
\pagebodymode\plusone % todo: \plustwo when spread
\page_boxes_constructed_page_body#1#2%
\normalexpanded{\global\afterpage \emptytoks\the\afterpage }%
\the\aftereverypage
\resetpagebreak
\resetlayouttextlines % will go to \aftereverypage
\stoptextproperties
\the\everyafterpagebody
\egroup}
\permanent\def\doifelsetopofpage
{\ifdim\pagegoal=\maxdimen
\expandafter\firstoftwoarguments
\orelse\ifdim\pagegoal=\vsize
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
\aliased\let\doiftopofpageelse\doifelsetopofpage
% %D Idea:
%
% \newinsert\thispageinsert % <- installinsertion
%
% \def\flushatthispage
% {\bgroup
% \dowithnextbox{\insert\thispageinsert{\box\nextbox}\egroup}%
% \hbox}
%
% \appendtoks
% \ifvoid\thispageinsert\else\hbox{\smashedbox\thispageinsert}\fi
% \to \everyshipout
% not yet in i-* file
\installcorenamespace{markedpage}
% todo: just define at the lua end ... less hassle
\permanent\tolerant\protected\def\markpage [#1]#*[#2]{\clf_markpage {#1}{#2}}
\permanent \def\markedpages [#1]{\clf_markedpages {#1}} % expandable
\permanent\protected \def\doifelsemarkedpage#1{\clf_doifelsemarkedpage{#1}}
\permanent\protected \def\startmarkpages [#1]{\clf_startmarkpages {#1}}
\permanent\protected \def\stopmarkpages {\clf_stopmarkpages }
%D Experimental:
\newconstant\c_page_force_strut_depth_trace_mode
\installtextracker
{otr.forcestrutdepth}
{\c_page_force_strut_depth_trace_mode\plusone}
{\c_page_force_strut_depth_trace_mode\zerocount}
\installoutputroutine\forcestrutdepth
{\clf_forcestrutdepth\normalpagebox\strutdp\c_page_force_strut_depth_trace_mode
\unvbox\normalpagebox}
\installoutputroutine\forcestrutdepthplus % experimental
{\clf_forcestrutdepthplus\normalpagebox\strutdp\c_page_force_strut_depth_trace_mode
\unvbox\normalpagebox}
% maybe better:
%
% \installoutputroutine\doforcestrutdepth
% {\clf_forcestrutdepth\normalpagebox\strutdp\c_page_force_strut_depth_trace_mode
% \unvbox\normalpagebox}
%
% \protected\def\forcestrutdepth
% {\par\ifvmode\ifinner\else\doforcestrutdepth\fi\fi}
% Also experimental:
\permanent\protected\def\doifelsependingpagecontent{\clf_doifelsependingpagecontent}
% \permanent\protected\let\doifelsependingpagecontent\clf_doifelsependingpagecontent
\protect \endinput
|