summaryrefslogtreecommitdiff
path: root/tex/context/base/page-ini.mkiv
blob: 15783a99bc38b8df2ccf63121e93472a4791e7b4 (plain)
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
%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}

%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

\unexpanded\def\page_otr_shipout
  {\ifconditional\c_otr_shipout_enabled
     \expandafter\page_otr_shipout_yes
   \else
     \expandafter\page_otr_shipout_nop
   \fi}

\let\page_otr_shipout_yes\normalshipout

\unexpanded\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

%D Floats.

\def\page_otr_flush_all_floats
  {%\flushnotes already done
   \ifconditional\c_page_floats_some_waiting
     \begingroup
     \c_page_floats_n_of_top\plusthousand
     \c_page_floats_n_of_bottom\zerocount
     % this is needed in case a float that has been stored
     % ends up at the current page; this border case occurs when
     % the calculated room is 'eps' smaller that the room available
     % when just flushing; so now we have (maybe optional):
     \pagebaselinecorrection % hm, needs checking, not needed when no floats
     % alas, this is tricky but needed (first surfaced in prikkels)
     \page_otr_command_flush_floats
     \endgroup
   \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
  {\vskip\zeropoint\relax % brrr .. get rid of this
   \ifvoid\normalpagebox \else
     \unvbox\normalpagebox
     \penalty\outputpenalty
   \fi}

\def\page_otr_construct_and_shipout#1#2%
  {\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_floats_flush_page_floats % before postponed blocks
   \page_spread_flush % defined later
   \page_postponed_blocks_flush}

% 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][]%
   \else\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\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 \vbox \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 \to \everybeforepagebody

\ifdefined\nestednewbox \else \newbox\nestednextbox \fi % hm, still needed?

\prependtoks
    \let\nextbox\nestednextbox
\to \everybeforepagebody

\def\page_boxes_constructed_page#1#2%
  {\vbox\bgroup % intercept spurious spaces
     \the\everybeforepagebody
     \starttextproperties
     \checkmarginblocks
     \the\beforeeverypage
     \normalexpanded{\global\beforepage\emptytoks\the\beforepage}%
     \inpagebodytrue
     \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}

\def\doifelsetopofpage
  {\ifdim\pagegoal=\maxdimen
     \expandafter\firstoftwoarguments
   \else\ifdim\pagegoal=\vsize
     \doubleexpandafter\firstoftwoarguments
   \else
     \doubleexpandafter\secondoftwoarguments
   \fi\fi}

\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
%
% %D Idea:
%
% \definemarkedpage[nobackgrounds]
% \markpage[nobackgrounds]
% \doifmarkedpageelse{nobackgrounds}

\protect \endinput