page-txt.mklx /size: 44 Kb    last modification: 2024-01-16 09:03
1% macros=mkvi
2% macros=mkvi
3
4%D \module
5%D   [       file=page-txt, % copied from main-001,
6%D        version=1997.03.31,
7%D          title=\CONTEXT\ Page Macros,
8%D       subtitle=Texts,
9%D         author=Hans Hagen,
10%D           date=\currentdate,
11%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
12%C
13%C This module is part of the \CONTEXT\ macro||package and is
14%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
15%C details.
16
17\writestatus{loading}{ConTeXt Page Macros / Texts}
18
19\unprotect
20
21\newtoks\toptextcontent     \newtoks\leftedgetextcontent
22\newtoks\headertextcontent  \newtoks\leftmargintextcontent
23\newtoks\footertextcontent  \newtoks\rightmargintextcontent
24\newtoks\bottomtextcontent  \newtoks\rightedgetextcontent
25
26\newtoks\texttextcontent
27
28%D \macros
29%D  {setuptop, setupheader, setuptext,setupfooter, setupbottom}
30%D
31%D The macros in this module sometimes look a bit more complicated than needed,
32%D which is a direct result of the fact that their ancestors are quite old and
33%D upward compatibility is a must.
34%D
35%D \showsetup{setuptop}
36%D \showsetup{setupheader}
37%D \showsetup{setuptext}
38%D \showsetup{setupfooter}
39%D \showsetup{setupbottom}
40
41\installcorenamespace{layouttexts}
42\installcorenamespace{layouttextsline}
43\installcorenamespace{layouttextsreset}
44\installcorenamespace{layouttextssynchronize}
45\installcorenamespace{layouttextstrut}
46\installcorenamespace{layouttextspecial}
47\installcorenamespace{layouttextcontent}
48
49\installcommandhandler \??layouttexts {layoutelement} \??layouttexts
50
51% \appendtoks
52%     \resetlayoutelementparameter\c!lefttext   % resolves better
53%     \resetlayoutelementparameter\c!middletext
54%     \resetlayoutelementparameter\c!righttext
55% \to \everydefinelayoutelement
56
57\definelayoutelement[\v!top   ]
58\definelayoutelement[\v!header]
59\definelayoutelement[\v!text  ]
60\definelayoutelement[\v!footer]
61\definelayoutelement[\v!bottom]
62
63\definelayoutelement[\v!top   :\v!text]  [\v!top   ][\c!lefttext=,\c!middletext=,\c!righttext=]
64\definelayoutelement[\v!header:\v!text]  [\v!header][\c!lefttext=,\c!middletext=,\c!righttext=]
65\definelayoutelement[\v!text  :\v!text]  [\v!text  ][\c!lefttext=,\c!middletext=,\c!righttext=]
66\definelayoutelement[\v!footer:\v!text]  [\v!footer][\c!lefttext=,\c!middletext=,\c!righttext=]
67\definelayoutelement[\v!bottom:\v!text]  [\v!bottom][\c!lefttext=,\c!middletext=,\c!righttext=]
68
69\definelayoutelement[\v!top   :\v!margin][\v!top   ][\c!lefttext=,\c!middletext=,\c!righttext=]
70\definelayoutelement[\v!header:\v!margin][\v!header][\c!lefttext=,\c!middletext=,\c!righttext=]
71\definelayoutelement[\v!text  :\v!margin][\v!text  ][\c!lefttext=,\c!middletext=,\c!righttext=]
72\definelayoutelement[\v!footer:\v!margin][\v!footer][\c!lefttext=,\c!middletext=,\c!righttext=]
73\definelayoutelement[\v!bottom:\v!margin][\v!bottom][\c!lefttext=,\c!middletext=,\c!righttext=]
74
75\definelayoutelement[\v!top   :\v!edge]  [\v!top   ][\c!lefttext=,\c!middletext=,\c!righttext=]
76\definelayoutelement[\v!header:\v!edge]  [\v!header][\c!lefttext=,\c!middletext=,\c!righttext=]
77\definelayoutelement[\v!text  :\v!edge]  [\v!text  ][\c!lefttext=,\c!middletext=,\c!righttext=]
78\definelayoutelement[\v!footer:\v!edge]  [\v!footer][\c!lefttext=,\c!middletext=,\c!righttext=]
79\definelayoutelement[\v!bottom:\v!edge]  [\v!bottom][\c!lefttext=,\c!middletext=,\c!righttext=]
80
81\permanent\tolerant\protected\def\setuplayouttext[#vertical]#spacer[#horizontal]#spacer[#S#settings]%
82  {\ifnum\lastarguments>\plustwo
83     \setuplayoutelement[#vertical:#horizontal][#settings]%
84   \else
85     \setuplayoutelement[#vertical][#horizontal]%
86   \fi}
87
88\appendtoks
89    \ifempty\currentlayoutelement\else
90        \page_layouts_synchronize_element\currentlayoutelement % brr, can be vertical:horizontal
91    \fi
92\to \everysetuplayoutelement
93
94\mutable\lettonothing\currenttextstate
95\mutable\lettonothing\previoustextstate
96
97\def\page_layouts_reset_element_status#vertical%
98  {\gdefcsname\??layouttextsreset#vertical\endcsname{\page_layouts_set_element_status_normal#vertical}}
99
100\def\page_layouts_set_element_status_normal#vertical%
101  {\gletcsname\namedlayoutelementhash#vertical\c!state\endcsname\v!normal
102   \gletcsname\??layouttextsreset#vertical\endcsname\relax
103   \page_layouts_synchronize_element{#vertical}}
104
105\def\page_layouts_synchronize_element#vertical%
106  {\xdef\previoustextstate{\csname\??layouttextssynchronize#vertical\endcsname}% can be a let
107   \cdef\currenttextstate {\namedlayoutelementparameter{#vertical}\c!state}%
108  %\writestatus{>>}{[#vertical:\currenttextstate/\previoustextstate]}%
109   \ifx\currenttextstate\previoustextstate \else
110     \page_layouts_synchronize_element_indeed{#vertical}%
111   \fi}
112
113\def\page_layouts_synchronize_element_indeed#vertical%
114  {\ifx\currenttextstate \v!high \calculatevsizes\page_backgrounds_recalculate \orelse
115   \ifx\previoustextstate\v!high \calculatevsizes\page_backgrounds_recalculate \orelse
116   \ifx\currenttextstate \v!none \calculatevsizes\page_backgrounds_recalculate \orelse
117   \ifx\previoustextstate\v!none \calculatevsizes\page_backgrounds_recalculate \fi
118   \gletcsname\??layouttextssynchronize#vertical\endcsname\currenttextstate}
119
120\permanent\protected\def\setuptop   {\setuplayouttext[\v!top   ]}
121\permanent\protected\def\setupheader{\setuplayouttext[\v!header]}
122\permanent\protected\def\setuptext  {\setuplayouttext[\v!text  ]}
123\permanent\protected\def\setupfooter{\setuplayouttext[\v!footer]}
124\permanent\protected\def\setupbottom{\setuplayouttext[\v!bottom]}
125
126%D We inherit some settings:
127
128\setuplayoutelement
129  [  \c!leftstyle=\layoutelementparameter\c!style,
130   \c!middlestyle=\layoutelementparameter\c!style,
131    \c!rightstyle=\layoutelementparameter\c!style,
132     \c!leftcolor=\layoutelementparameter\c!color,
133   \c!middlecolor=\layoutelementparameter\c!color,
134    \c!rightcolor=\layoutelementparameter\c!color,
135     \c!leftwidth=\layoutelementparameter\c!width,
136   \c!middlewidth=\layoutelementparameter\c!width,
137    \c!rightwidth=\layoutelementparameter\c!width]
138
139%D \macros
140%D  {noheaderandfooterlines,notopandbottomlines}
141%D
142%D Although not really needed, the following shortcuts sometimes come in handy.
143%D
144%D \showsetup{noheaderandfooterlines}
145%D \showsetup{notopandbottomlines}
146
147\permanent\protected\def\noheaderandfooterlines
148  {\setuplayoutelement[\v!header][\c!state=\v!empty]%
149   \setuplayoutelement[\v!footer][\c!state=\v!empty]}
150
151\permanent\protected\def\notopandbottomlines
152  {\setuplayoutelement[\v!top   ][\c!state=\v!empty]%
153   \setuplayoutelement[\v!bottom][\c!state=\v!empty]}
154
155%D \macros
156%D  {setuptoptexts,setupheadertexts,setuptexttexts,setupfootertexts,setupbottomtexts}
157%D
158%D The next macros take one or more arguments. The exact setup depends on the number
159%D of arguments. Although not that intuitive, the current scheme evolved out of the
160%D original. When margin and edge texts as well as middle texts showed up, the
161%D current odd|/|even scheme surfaced.
162%D
163%D \showsetup{setuptoptexts}
164%D \showsetup{setupheadertexts}
165%D \showsetup{setuptexttexts}
166%D \showsetup{setupfootertexts}
167%D \showsetup{setupbottomtexts}
168%D
169%D Only the following have checking for pagenumber, date and mark built in, so when
170%D someone uses the key|/|value interface these things have to be set explicitly as
171%D part of the text.
172
173\permanent\protected\def\setuptoptexts   {\setuptexts[\v!top   ]}
174\permanent\protected\def\setupheadertexts{\setuptexts[\v!header]}
175\permanent\protected\def\setuptexttexts  {\setuptexts[\v!text  ]}
176\permanent\protected\def\setupfootertexts{\setuptexts[\v!footer]}
177\permanent\protected\def\setupbottomtexts{\setuptexts[\v!bottom]}
178
179\mutable\lettonothing\currentlayoutelementstate
180
181\permanent\tolerant\protected\def\setuptexts[#vertical]#spacer[#horizontal]#spacer[#S#a]#spacer[#S#b]#spacer[#S#c]#spacer[#S#d]%
182  {\ifarguments
183     % there is always one
184   \or
185     \cdef\currentlayoutelement{#vertical:\v!text}%
186     \resetlayoutelementparameter\c!lefttext
187     \resetlayoutelementparameter\c!righttext
188     \resetlayoutelementparameter\c!middletext
189     \cdef\currentlayoutelement{#vertical:\v!margin}%
190     \resetlayoutelementparameter\c!lefttext
191     \resetlayoutelementparameter\c!righttext
192     \resetlayoutelementparameter\c!middletext
193     \cdef\currentlayoutelement{#vertical:\v!edge}%
194     \resetlayoutelementparameter\c!lefttext
195     \resetlayoutelementparameter\c!righttext
196     \resetlayoutelementparameter\c!middletext
197   \or
198     \cdef\currentlayoutelement{#vertical:\v!text}%
199     \resetlayoutelementparameter\c!lefttext
200     \resetlayoutelementparameter\c!righttext
201     \setlayoutelementparameter  \c!middletext{\page_layouts_process_element_single{#horizontal}}%
202   \or
203     \cdef\currentlayoutelement{#vertical:\v!text}%
204     \setlayoutelementparameter\c!lefttext {\page_layouts_process_element_single{#horizontal}}%
205     \setlayoutelementparameter\c!righttext{\page_layouts_process_element_single{#a}}%
206   \or
207     \cdef\currentlayoutelement{#vertical:#horizontal}%
208     \setlayoutelementparameter\c!lefttext {\page_layouts_process_element_single{#a}}%
209     \setlayoutelementparameter\c!righttext{\page_layouts_process_element_single{#b}}%
210   \or
211     \cdef\currentlayoutelement{#vertical:\v!text}%
212     \setlayoutelementparameter\c!lefttext {\page_layouts_process_element_double{#horizontal}{#c}}%
213     \setlayoutelementparameter\c!righttext{\page_layouts_process_element_double{#a}{#b}}%
214   \or
215     \cdef\currentlayoutelement{#vertical:#horizontal}%
216     \setlayoutelementparameter\c!lefttext {\page_layouts_process_element_double{#a}{#d}}%
217     \setlayoutelementparameter\c!righttext{\page_layouts_process_element_double{#b}{#c}}%
218   \fi}
219
220%D Left and right texts are swapped on odd and even pages, but only when double
221%D sided typesetting is enabled.
222
223\defcsname\??layouttextstrut\v!yes\endcsname{\setstrut\strut} % maybe more variants
224
225\lettonothing\m_page_layouts_element_content
226
227\protected\def\page_layouts_process_element_single#content%
228  {\edef\m_page_layouts_element_content{\detokenize{#content}}% so no \v!xxx
229   \ifcsname\??layouttextspecial\m_page_layouts_element_content\endcsname
230     \lastnamedcs
231   \else
232     \doifelsemarking\m_page_layouts_element_content
233       {\getmarking[\m_page_layouts_element_content][\v!first]}%
234       {#content}%
235   \fi}
236
237\protected\def\page_layouts_process_element_double#first#second%
238  {\doifelseoddpage
239     {\page_layouts_process_element_single{#first}}
240     {\page_layouts_process_element_single{#second}}}
241
242\protected\def\page_layouts_process_element_indeed#style#color#width%
243  {\begingroup
244   \lefttoright % new
245   \uselayoutelementstyleandcolor#style#color%
246   \begincsname\??layouttextstrut\layoutelementparameter\c!strut\endcsname
247   \ignorecrlf
248   \edef\p_width{\layoutelementparameter#width}%
249   \ifempty\p_width\else
250     \expandafter\page_layouts_process_element_limited
251   \fi\p_text
252   \endgroup}
253
254\def\page_layouts_process_element_limited#content% are the {}{}{} still needed?
255  {\limitated
256      left     \p_width
257      text     {#content}%
258      sentinel {\unknown}%
259   \relax}
260
261\defcsname\??layouttextspecial\v!pagenumber\endcsname{\page_layouts_place_page_number}
262\defcsname\??layouttextspecial\v!date      \endcsname{\currentdate}
263
264%D When specified, the texts are automatically limited in length.
265
266\appendtoks \page_layouts_place_text_line\v!top   \topheight    \to \toptextcontent
267\appendtoks \page_layouts_place_text_line\v!header\headerheight \to \headertextcontent
268\appendtoks \page_layouts_place_text_line\v!text  \textheight   \to \texttextcontent
269\appendtoks \page_layouts_place_text_line\v!footer\footerheight \to \footertextcontent
270\appendtoks \page_layouts_place_text_line\v!bottom\bottomheight \to \bottomtextcontent
271
272%D Texts can be disabled, moved up and ignored, depending in the \type {status}
273%D variable. This is handled by the next couple of macros.
274
275\newinteger\c_page_layouts_element_state_n
276
277\mutable\lettonothing\textlinestatus
278
279\def\page_layouts_set_element_status#vertical%
280  {\c_page_layouts_element_state_n=0\namedlayoutelementparameter#vertical\c!n\relax
281   \ifcase\c_page_layouts_element_state_n
282     \edef\textlinestatus{\namedlayoutelementparameter#vertical\c!state}%
283   \else
284     \xdefcsname\namedlayoutelementhash#vertical\c!n\endcsname{\the\numexpr\c_page_layouts_element_state_n+\minusone}%
285     \let\textlinestatus\v!stop
286   \fi}
287
288\appendtoks
289   \ifinset\v!header\floatspecification\xdefcsname\namedlayoutelementhash\v!header\c!n\endcsname{1}\fi
290   \ifinset\v!footer\floatspecification\xdefcsname\namedlayoutelementhash\v!footer\c!n\endcsname{1}\fi
291\to \everybeforeflushedpagefloat
292
293\protected\def\page_layouts_place_text_line#vertical%
294  {\page_layouts_set_element_status#vertical\relax
295   \ifcsname\??layouttextsline\textlinestatus\endcsname
296     \expandafter\lastnamedcs
297   \else
298     \expandafter\page_layouts_place_text_line_unknown
299   \fi#vertical}
300
301\permanent\protected\def\doifelselayouttextline#vertical% shown or not
302  {\cdef\currentlayoutelementstate{\namedlayoutelementparameter{#vertical}\c!state}%
303   \ifx\currentlayoutelementstate\v!normal
304     \expandafter\firstoftwoarguments
305   \orelse\ifx\currentlayoutelementstate\v!start
306     \expandafter\firstoftwoarguments
307   \else
308     \expandafter\secondoftwoarguments
309   \fi}
310
311\permanent\protected\def\doifelselayoutsomeline#vertical% present or not
312  {\cdef\currentlayoutelementstate{\namedlayoutelementparameter{#vertical}\c!state}%
313   \ifx\currentlayoutelementstate\v!none
314     \expandafter\secondoftwoarguments
315   \orelse\ifx\currentlayoutelementstate\v!high
316     \expandafter\secondoftwoarguments
317   \else
318     \expandafter\firstoftwoarguments
319   \fi}
320
321\aliased\let\doiflayouttextlineelse\doifelselayouttextline
322\aliased\let\doiflayoutsomelineelse\doifelselayoutsomeline
323
324\newconditional\resyncaftertextline
325
326\defcsname\??layouttextsline\v!normal\endcsname{\page_layouts_place_text_line_indeed}
327\defcsname\??layouttextsline\empty   \endcsname{\page_layouts_place_text_line_indeed}
328
329\letcsname\??layouttextsline\v!none\endcsname\gobbletwoarguments
330\letcsname\??layouttextsline\v!stop\endcsname\gobbletwoarguments
331
332\defcsname\??layouttextsline\v!high\endcsname#vertical#height%
333  {\global\resyncaftertextline\conditionaltrue
334   \page_layouts_reset_element_status#vertical}
335
336\defcsname\??layouttextsline\v!empty\endcsname#vertical#height%
337  {\page_layouts_reset_element_status#vertical}
338
339\defcsname\??layouttextsline\v!start\endcsname#vertical#height%
340  {\page_layouts_reset_element_status#vertical%
341   \page_layouts_place_text_line_indeed#vertical#height}
342
343\defcsname\??layouttextsline\v!nomarking\endcsname#vertical#height%
344  {\bgroup
345   \page_layouts_reset_element_status#vertical%
346   \inhibitgetmarking\conditionaltrue
347   \page_layouts_place_text_line_indeed#vertical#height%
348   \egroup}
349
350% \setupheadertexts            [11]
351% \definetext [title] [header] [aa]
352% \setupheadertexts            [11] [22]
353% \definetext [title] [header] [aa] [bb]
354% \setupheadertexts            [text] [11] [22]
355% \definetext [title] [header] [text] [aa] [bb]
356% \setupheadertexts            [11] [22] [33] [44]
357% \definetext [title] [header] [aa] [bb] [cc] [dd]
358% \setupheadertexts            [text] [11] [22] [33] [44]
359% \definetext [title] [header] [text] [aa] [bb] [cc] [dd]
360
361\def\page_layouts_place_text_line_unknown#vertical#height%
362  {\global\resyncaftertextline\conditionaltrue
363   \begingroup % new
364   \page_layouts_reset_element_status#vertical%
365   \begincsname\namedlayoutelementhash{#vertical}\textlinestatus\endcsname
366   \begincsname\namedlayoutelementhash{#vertical:\v!text}\textlinestatus\endcsname
367   \begincsname\namedlayoutelementhash{#vertical:\v!margin}\textlinestatus\endcsname
368   \begincsname\namedlayoutelementhash{#vertical:\v!edge}\textlinestatus\endcsname
369   \page_layouts_place_text_line_indeed#vertical#height%
370   \endgroup}
371
372\letcsname\??layouttextsline\s!unknown\endcsname\page_layouts_place_text_line_unknown
373
374%D The following macro has to be called after a page is flushed.
375
376\permanent\protected\def\resetlayouttextlines % public
377  {\begincsname\??layouttextsreset\v!top   \endcsname
378   \begincsname\??layouttextsreset\v!header\endcsname
379   \begincsname\??layouttextsreset\v!text  \endcsname
380   \begincsname\??layouttextsreset\v!footer\endcsname
381   \begincsname\??layouttextsreset\v!bottom\endcsname
382   \ifconditional\resyncaftertextline
383     \calculateglobalvsizes
384     \page_backgrounds_recalculate
385     \global\resyncaftertextline\conditionalfalse
386   \fi}
387
388\permanent\def\getspecificlayouttext#vertical#horizontal#what%
389  {\begincsname\namedlayoutelementhash{#vertical:#horizontal}#what\endcsname}
390
391% \settext[header][text][middle][xxx][yyy]
392
393\permanent\tolerant\protected\def\settextcontent[#vertical]#spacer[#horizontal]#spacer[#S#one]#spacer[#S#two]#spacer[#S#three]% header text middle text/text
394  {\ifarguments\or\or\or % 3
395     \defcsname\namedlayoutelementhash{#vertical:#horizontal}\c!middletext\endcsname
396       {\page_layouts_process_element_double{#one}{#one}}%
397   \or % 4
398     \defcsname\namedlayoutelementhash{#vertical:#horizontal}\begincsname\??layouttextcontent\v!text:#one\endcsname\c!middletext\endcsname
399       {\page_layouts_process_element_double{#two}{#two}}%
400   \or % 5
401     \defcsname\namedlayoutelementhash{#vertical:#horizontal}\begincsname\??layouttextcontent\v!text:#one\endcsname\c!middletext\endcsname
402       {\page_layouts_process_element_double{#two}{#three}}%
403   \fi}
404
405\let\currentlayoutelement\relax
406
407%D This will be redefined, so no \type {\frozen} here!
408
409\permanent\tolerant\protected\def\resettextcontent[#vertical]#spacer[#horizontal]#spacer[#S#tag]% header text middle
410  {\ifarguments\or\or % 2
411     \cdef\currentlayoutelement{#vertical:#horizontal}%
412     \resetlayoutelementparameter\c!lefttext
413     \resetlayoutelementparameter\c!middletext
414     \resetlayoutelementparameter\c!righttext
415   \or % 3
416%      \cdef\currentlayoutelement{#vertical:#horizontal}%
417%      \letcsname\layoutelementhash\begincsname\??layouttextcontent\v!text:#tag\endcsname\c!middletext\endcsname\empty
418     \letcsname\namedlayoutelementhash{#vertical:#horizontal}\begincsname\??layouttextcontent\v!text:#tag\endcsname\c!middletext\endcsname\empty
419   \fi}
420
421\letcsname\??layouttextcontent\v!text:\c!middle\endcsname\c!middletext
422\letcsname\??layouttextcontent\v!text:\c!left  \endcsname\c!lefttext
423\letcsname\??layouttextcontent\v!text:\c!right \endcsname\c!righttext
424
425%D The placement of a whole line is handled by the next two macros. These are hooked
426%D into the general purpose token list registers mentioned before.
427
428\mutable\let\currentlayouttextline\relax
429
430\def\page_layouts_place_text_line_indeed#vertical#height%
431  {\let\currentlayouttextline#vertical%
432   \ifdim#height>\zeropoint\relax  % prevents pagenumbers when zero height
433     \page_layouts_place_text_line_left_or_right{#height}%
434   \fi}
435
436\def\page_layouts_place_text_line_left_or_right#height%
437  {\goleftonpage
438   \setbox\b_page_layouts_element\vbox to #height
439     {\vsize#height\relax
440     %\hsize\zeropoint % hack so that e.g. after=\hairline gives predictable results
441      \hsize\totaltextwidth
442      \normalbaselines
443      \enforced\let\\\ignoredlinebreak
444      \enforced\let\crlf\ignoredlinebreak
445      \namedlayoutelementparameter\currentlayouttextline\c!before
446      \doifbothsidesoverruled
447        \page_layouts_place_text_line_right
448        \page_layouts_place_text_line_right
449        \page_layouts_place_text_line_left
450      \namedlayoutelementparameter\currentlayouttextline\c!after
451      \vkern\zeropoint}% keep the \dp, beware of \vtops, never change this!
452   \dp\b_page_layouts_element\zeropoint
453   \box\b_page_layouts_element
454   \vkern-#height\relax}
455
456\lettonothing\page_layouts_place_extra_text_left  % historic
457\lettonothing\page_layouts_place_extra_text_right % historic
458
459\def\page_layouts_place_text_line_right
460  {\hpack
461     {\ifdim\leftedgewidth>\zeropoint
462        \page_layouts_left_edge_element\c!lefttext\c!leftstyle\c!leftcolor\c!leftwidth
463      \fi
464      \ifdim\leftmarginwidth>\zeropoint
465        \page_layouts_left_margin_element\c!lefttext\c!leftstyle\c!leftcolor\c!leftwidth\zerocount
466      \fi
467      \ifdim\makeupwidth>\zeropoint
468        \page_layouts_text_body_element_l_m_r_e
469      \fi
470      \ifdim\rightmarginwidth>\zeropoint
471        \page_layouts_right_margin_element\c!righttext\c!rightstyle\c!rightcolor\c!rightwidth\plusone
472      \fi
473      \ifdim\rightedgewidth>\zeropoint
474        \page_layouts_right_edge_element\c!righttext\c!rightstyle\c!rightcolor\c!rightwidth
475      \fi}}
476
477\def\page_layouts_place_text_line_left
478  {\hpack
479     {\ifdim\leftedgewidth>\zeropoint
480        \page_layouts_left_edge_element\c!righttext\c!rightstyle\c!rightcolor\c!rightwidth
481      \fi
482      \ifdim\leftmarginwidth>\zeropoint
483        \page_layouts_left_margin_element\c!righttext\c!rightstyle\c!rightcolor\c!rightwidth\plusone
484      \fi
485      \ifdim\makeupwidth>\zeropoint
486        \page_layouts_text_body_element_e_r_m_l
487      \fi
488      \ifdim\rightmarginwidth>\zeropoint
489        \page_layouts_right_margin_element\c!lefttext\c!leftstyle\c!leftcolor\c!leftwidth\zerocount
490      \fi
491      \ifdim\rightedgewidth>\zeropoint
492        \page_layouts_right_edge_element\c!lefttext\c!leftstyle\c!leftcolor\c!leftwidth
493      \fi}}
494
495\def\page_layouts_left_edge_element_indeed#text#style#color#width%
496  {\letfromlayoutelementparameter\p_text#text%
497   \ifempty\p_text
498     \kern\leftedgewidth
499   \else
500     \hbox to \leftedgewidth\bgroup
501       \hss
502       \page_layouts_process_element_indeed#style#color#width%
503     \egroup
504   \fi}
505
506\def\page_layouts_left_edge_element#text#style#color#width%
507  {\cdef\currentlayoutelement{\currentlayouttextline:\v!edge}%
508   \page_layouts_place_element_indeed\leftedgewidth
509     {\page_layouts_left_edge_element_indeed#text#style#color#width}%
510   \kern\leftedgedistance}
511
512\def\page_layouts_right_edge_element_indeed#text#style#color#width%
513  {\letfromlayoutelementparameter\p_text#text%
514   \ifempty\p_text
515     \kern\rightedgewidth
516   \else
517      \hbox to \rightedgewidth\bgroup
518        \page_layouts_process_element_indeed#style#color#width%
519        \hss
520      \egroup
521   \fi}
522
523\def\page_layouts_right_edge_element#text#style#color#width%
524  {\cdef\currentlayoutelement{\currentlayouttextline:\v!edge}%
525   \kern\rightedgedistance
526   \page_layouts_place_element_indeed\rightedgewidth
527     {\page_layouts_right_edge_element_indeed#text#style#color#width}}
528
529% margin needs checking!
530
531% \hbox to \leftmarginwidth{\hss\layoutelementparameter\c!margintext}%
532% \hbox to \rightmarginwidth{\layoutelementparameter\c!margintext\hss}%
533
534\def\page_layouts_left_margin_element_indeed#text#style#color#width#margintoo%
535  {\letfromlayoutelementparameter\p_text#text%
536   \ifempty\p_text
537     \kern\leftmarginwidth
538   \else
539     \hbox to \leftmarginwidth\bgroup
540       \hss
541       \page_layouts_process_element_indeed#style#color#width%
542     \egroup
543   \fi
544   \ifcase#margintoo\or
545     \letfromlayoutelementparameter\p_text\c!margintext
546     \ifempty\p_text\else
547       \kern-\leftmarginwidth
548       \hbox to \leftmarginwidth\bgroup
549         \hss
550         \p_text % styling ?
551       \egroup
552     \fi
553   \fi}
554
555\def\page_layouts_left_margin_element#text#style#color#width#margintoo%
556  {\cdef\currentlayoutelement{\currentlayouttextline:\v!margin}%
557   \page_layouts_place_element_indeed\leftmarginwidth
558     {\page_layouts_left_margin_element_indeed#text#style#color#width#margintoo}%
559   \kern\leftmargindistance}
560
561\def\page_layouts_right_margin_element_indeed#text#style#color#width#margintoo%
562  {\letfromlayoutelementparameter\p_text#text%
563   \ifempty\p_text
564     \kern\rightmarginwidth
565   \else
566     \hbox to \rightmarginwidth\bgroup
567       \page_layouts_process_element_indeed#style#color#width%
568       \hss
569     \egroup
570   \fi
571   \ifcase#margintoo\or
572     \letfromlayoutelementparameter\p_text\c!margintext
573     \ifempty\p_text\else
574       \kern-\rightmarginwidth
575       \hbox to \rightmarginwidth\bgroup
576         \p_text % ? styling
577         \hss
578       \egroup
579     \fi
580   \fi}
581
582\def\page_layouts_right_margin_element#text#style#color#width#margintoo%
583  {\cdef\currentlayoutelement{\currentlayouttextline:\v!margin}%
584   \kern\rightmargindistance
585   \page_layouts_place_element_indeed\rightmarginwidth
586     {\page_layouts_right_margin_element_indeed#text#style#color#width#margintoo}}
587
588\def\page_layouts_text_body_element_indeed_l_m_r_e
589  {\letfromlayoutelementparameter\p_text\c!lefttext
590   \ifempty\p_text
591     \ifempty\page_layouts_place_extra_text_left\else
592       \hbox to \makeupwidth\bgroup
593         \page_layouts_place_extra_text_left
594         \hss
595       \egroup
596       \kern-\makeupwidth
597     \fi
598   \else
599     \hbox to \makeupwidth\bgroup
600       \page_layouts_place_extra_text_left
601       \page_layouts_process_element_indeed\c!leftstyle\c!leftcolor\c!leftwidth
602       \hss
603     \egroup
604     \kern-\makeupwidth
605   \fi
606   \letfromlayoutelementparameter\p_text\c!middletext
607   \ifempty\p_text\else
608     \hbox to \makeupwidth\bgroup
609       \hss
610       \page_layouts_process_element_indeed\c!middlestyle\c!middlecolor\c!middlewidth
611       \hss
612     \egroup
613     \kern-\makeupwidth
614   \fi
615   \letfromlayoutelementparameter\p_text\c!righttext
616   \ifempty\p_text
617     \kern\makeupwidth
618   \else
619     \hbox to \makeupwidth\bgroup
620       \hss
621       \page_layouts_process_element_indeed\c!rightstyle\c!rightcolor\c!rightwidth
622     \egroup
623   \fi}
624
625\def\page_layouts_text_body_element_indeed_e_r_m_l
626  {\letfromlayoutelementparameter\p_text\c!righttext
627   \ifempty\p_text\else
628     \hbox to \makeupwidth\bgroup
629       \page_layouts_process_element_indeed\c!rightstyle\c!rightcolor\c!rightwidth
630       \hss
631     \egroup
632     \kern-\makeupwidth
633   \fi
634   \letfromlayoutelementparameter\p_text\c!middletext
635   \ifempty\p_text\else
636     \hbox to \makeupwidth\bgroup
637       \hss
638       \page_layouts_process_element_indeed\c!middlestyle\c!middlecolor\c!middlewidth
639       \hss
640     \egroup
641     \kern-\makeupwidth
642   \fi
643   \letfromlayoutelementparameter\p_text\c!lefttext
644   \ifempty\p_text
645     \ifempty\page_layouts_place_extra_text_right
646       \kern\makeupwidth
647     \else
648       \hbox to \makeupwidth\bgroup
649         \hss
650         \page_layouts_place_extra_text_right
651       \egroup
652     \fi
653   \else
654     \hbox to \makeupwidth\bgroup
655       \hss
656       \page_layouts_process_element_indeed\c!leftstyle\c!leftcolor\c!leftwidth
657       \page_layouts_place_extra_text_right
658     \egroup
659   \fi}
660
661\def\page_layouts_text_body_element_l_m_r_e
662  {\cdef\currentlayoutelement{\currentlayouttextline:\v!text}%
663   \page_layouts_place_element_indeed\makeupwidth\page_layouts_text_body_element_indeed_l_m_r_e}
664
665\def\page_layouts_text_body_element_e_r_m_l
666  {\cdef\currentlayoutelement{\currentlayouttextline:\v!text}%
667   \page_layouts_place_element_indeed\makeupwidth\page_layouts_text_body_element_indeed_e_r_m_l}
668
669\def\page_layouts_place_element_indeed#width#content%
670  {\vbox % to \vsize
671     {\hsize#width\relax
672      \layoutelementparameter\c!before
673      \setlayoutcomponentattribute\currentlayoutelement
674      \hbox \layoutcomponentboxattribute to #width{#content}%
675      \layoutelementparameter\c!after}}
676
677%D Although it is far better to use backgrounds for this purpose, one can add a rule
678%D in the following way. This method makes the rules disappear in case of an empty
679%D text line. Consider this a feature.
680%D
681%D \starttyping
682%D \setupheadertexts[left][right]
683%D
684%D \setupheader[text][after=\hrule,style=bold]
685%D
686%D \starttext
687%D   \input tufte \page
688%D   \setupheader[state=empty]
689%D   \input tufte \page
690%D \stoptext
691%D \stoptyping
692
693%D This code will move to \type {page-flt.tex}.
694
695\appendtoks \placerightmarginblock \kern-\rightmarginwidth \to \rightmargintextcontent
696\appendtoks \placeleftmarginblock  \kern-\leftmarginwidth  \to \leftmargintextcontent
697
698%D \macros
699%D   {definetext}
700%D
701%D Some macros ago, we implemented the \type {status} option \type {unknown}. This
702%D one is used to take care of symbolic texts handlers.
703%D
704%D \showsetup{definetext}
705%D
706%D The next example demonstrates how we can use this mechanism to provide page
707%D (event) dependent text lines.
708%D
709%D \starttyping
710%D \definetext[chapter][footer][pagenumber]
711%D \setuphead[chapter][header=high,footer=chapter]
712%D \setupheadertexts[pagenumber]
713%D \setupfootertexts[left][right]
714%D \chapter{eerste} \dorecurse{20}{\input tufte \relax}
715%D \chapter{tweede} \dorecurse{20}{\input tufte \relax}
716%D \stoptyping
717
718\permanent\tolerant\protected\def\definetext[#tag]#spacer[#vertical]#spacer[#horizontal]#spacer[#S#a]#spacer[#S#b]#spacer[#S#c]#spacer[#S#d]%
719  {\ifnum\lastarguments<\plusfour
720     \defcsname\namedlayoutelementhash            {#vertical}#tag\endcsname{\setuptexts[#vertical][#horizontal]\relax}% 1, 2, 3
721   \orelse\ifarguments\or\or\or\or
722     \defcsname\namedlayoutelementhash            {#vertical}#tag\endcsname{\setuptexts[#vertical][#horizontal][#a]\relax}% 4
723   \or
724     \defcsname\namedlayoutelementhash{#vertical:#horizontal}#tag\endcsname{\setuptexts[#vertical][#horizontal][#a][#b]\relax}% 5
725   \or
726     \defcsname\namedlayoutelementhash            {#vertical}#tag\endcsname{\setuptexts[#vertical][#horizontal][#a][#b][#c]\relax}% 6
727   \or
728     \defcsname\namedlayoutelementhash{#vertical:#horizontal}#tag\endcsname{\setuptexts[#vertical][#horizontal][#a][#b][#c][#d]\relax}% 7
729   \fi}
730
731%D A few more page breakers:
732
733\installpagebreakmethod \v!empty
734  {\page_otr_flush_all_floats
735   \page_otr_command_next_page
736   \ifcstok{\namedlayoutelementparameter\v!header\c!state}\v!stop\else\setuplayoutelement[\v!header][\c!state=\v!empty]\fi
737   \ifcstok{\namedlayoutelementparameter\v!footer\c!state}\v!stop\else\setuplayoutelement[\v!footer][\c!state=\v!empty]\fi
738   \page_otr_insert_dummy_page}
739
740\installpagebreakmethod \v!header
741  {\ifcstok{\namedlayoutelementparameter\v!header\c!state}\v!stop\else\setuplayoutelement[\v!header][\c!state=\v!empty]\fi}
742
743\installpagebreakmethod \v!footer
744  {\ifcstok{\namedlayoutelementparameter\v!footer\c!state}\v!stop\else\setuplayoutelement[\v!footer][\c!state=\v!empty]\fi}
745
746%D While the header and footer lines are moved away from the main text, the top and
747%D bottom lines are centered.
748
749\setuplayoutelement[\v!top   ][\c!state=\v!normal,\c!n=0,\c!before=\vss,\c!after=\vss,\c!strut=]
750\setuplayoutelement[\v!header][\c!state=\v!normal,\c!n=0,\c!before=,    \c!after=\vss,\c!strut=\v!yes]
751\setuplayoutelement[\v!text  ][\c!state=\v!normal,\c!n=0,\c!before=\vss,\c!after=\vss,\c!strut=]
752\setuplayoutelement[\v!footer][\c!state=\v!normal,\c!n=0,\c!before=\vss,\c!after=,    \c!strut=\v!yes]
753\setuplayoutelement[\v!bottom][\c!state=\v!normal,\c!n=0,\c!before=\vss,\c!after=\vss,\c!strut=]
754
755%D Moved here from strc-pag:
756%D
757%D We reset a previous location but only when it has a pagenumber associated. This
758%D is a rather messy test but better than the MkII way where we use states and keep
759%D settings.
760
761\let\m_page_layouts_page_number_location  \relax
762\let\m_page_layouts_page_number_location_v\relax
763\let\m_page_layouts_page_number_location_h\relax
764\let\m_page_layouts_page_number_location_x\relax
765
766\def\page_layouts_place_page_number   % also elsewhere .. beware, not \protected else
767  {\strc_pagenumbers_place_location}  % test below fails
768
769\def\page_layouts_reset_page_number_location
770  {\ifrelax\m_page_layouts_page_number_location_v\else
771     % this can be done better now, no meaning hackery needed
772     \cdef\currentlayoutelement{\m_page_layouts_page_number_location_v:\m_page_layouts_page_number_location_h}%
773     \edef\tempstring{\detokenizedlayoutelementparameter\m_page_layouts_page_number_location_x}%
774     \iftok{\normalmeaningless\tempstring}{\normalmeaningless\page_layouts_place_page_number}%
775       \resetlayoutelementparameter\m_page_layouts_page_number_location_x
776     \fi
777   \fi}
778
779\def\page_layouts_set_page_number_location
780  {\cdef\currentlayoutelement{\m_page_layouts_page_number_location_v:\m_page_layouts_page_number_location_h}%
781   \letlayoutelementparameter\m_page_layouts_page_number_location_x\page_layouts_place_page_number
782   \ifx\m_page_layouts_page_number_location_x\c!marginedgetext
783     \let\page_layouts_place_extra_text_left \page_layouts_place_page_number_left
784     \let\page_layouts_place_extra_text_right\page_layouts_place_page_number_right
785   \else
786     \lettonothing\page_layouts_place_extra_text_left
787     \lettonothing\page_layouts_place_extra_text_right
788   \fi}
789
790\def\page_layouts_identify_page_number_location
791  {\let\m_page_layouts_page_number_location_v\v!footer
792   \let\m_page_layouts_page_number_location_h\v!text
793   \let\m_page_layouts_page_number_location_x\c!middletext
794   \processallactionsinset[\directpagenumberingparameter\c!location]%
795     [    \v!header=>\let\m_page_layouts_page_number_location_v\v!header,%
796          \v!footer=>\let\m_page_layouts_page_number_location_v\v!footer,%
797          \v!middle=>\let\m_page_layouts_page_number_location_h\v!text
798                     \let\m_page_layouts_page_number_location_x\c!middletext,%
799            \v!left=>\let\m_page_layouts_page_number_location_h\v!text
800                     \let\m_page_layouts_page_number_location_x\c!lefttext,%
801           \v!right=>\let\m_page_layouts_page_number_location_h\v!text
802                     \let\m_page_layouts_page_number_location_x\c!righttext,%
803          \v!inleft=>\let\m_page_layouts_page_number_location_h\v!margin
804                     \let\m_page_layouts_page_number_location_x\c!lefttext,%
805         \v!inright=>\let\m_page_layouts_page_number_location_h\v!margin
806                     \let\m_page_layouts_page_number_location_x\c!righttext,%
807        \v!inmargin=>\let\m_page_layouts_page_number_location_h\v!margin
808                     \def\m_page_layouts_page_number_location_x{\ifdoublesided\c!margintext\else\c!righttext\fi},%
809          \v!margin=>\let\m_page_layouts_page_number_location_h\v!margin
810                     \def\m_page_layouts_page_number_location_x{\ifdoublesided\c!margintext\else\c!righttext\fi},%
811        \v!atmargin=>\let\m_page_layouts_page_number_location_h\v!text
812                     \let\m_page_layouts_page_number_location_x\c!marginedgetext,%
813      \v!marginedge=>\let\m_page_layouts_page_number_location_h\v!text
814                     \let\m_page_layouts_page_number_location_x\c!marginedgetext]}
815
816\protected\def\strc_pagenumbers_set_location
817  {\edef\p_strc_pagenumbers_location{\directpagenumberingparameter\c!location}%
818   \ifx\p_strc_pagenumbers_location\m_page_layouts_page_number_location
819      % unchanged
820   \else
821     \let\m_page_layouts_page_number_location\p_strc_pagenumbers_location
822     \page_layouts_reset_page_number_location
823     \ifempty\p_strc_pagenumbers_location
824       % set otherwise
825     \orelse\ifx\p_strc_pagenumbers_location\v!none
826       % set otherwise
827     \else
828       \page_layouts_identify_page_number_location
829       \page_layouts_set_page_number_location
830     \fi
831   \fi}
832
833\def\page_layouts_place_page_number_left % historic
834  {\begingroup
835   \setbox\scratchbox\hbox{\ignorespaces\layoutelementparameter\c!marginedgetext\removeunwantedspaces}%
836   \ifzeropt\wd\scratchbox\else
837     \edef\p_strc_pagenumbers_width{\directpagenumberingparameter\c!width}%
838     \ifempty\p_strc_pagenumbers_width
839       \box\scratchbox\tfskip
840     \else
841       \hpack to \p_strc_pagenumbers_width{\box\scratchbox\hss}%
842     \fi
843   \fi
844   \endgroup}
845
846\def\page_layouts_place_page_number_right % historic
847  {\begingroup
848   \setbox\scratchbox\hbox{\ignorespaces\layoutelementparameter\c!marginedgetext\removeunwantedspaces}%
849   \ifzeropt\wd\scratchbox\else
850     \edef\p_strc_pagenumbers_width{\directpagenumberingparameter\c!width}%
851     \ifempty\p_strc_pagenumbers_width
852       \tfskip\box\scratchbox
853     \else
854       \hpack to \p_strc_pagenumbers_width{\hss\box\scratchbox}%
855     \fi
856   \fi
857   \endgroup}
858
859\strc_pagenumbers_set_location % initializes
860
861\newbox\b_page_layouts_element
862
863\def\page_layouts_insert_elements
864  {\ifcase\pageornamentstate
865     \page_layouts_place_elements_indeed % we could have a special flag for always ignored
866   \fi}
867
868\def\page_layouts_place_elements_indeed
869  {\setbox\b_page_layouts_element\vpack
870     {\dontcomplain
871      \calculatereducedvsizes
872      \page_layouts_swap_margins\v!text
873      \offinterlineskip
874      \vkern\dimexpr-\topheight-\topdistance\relax
875      \the\toptextcontent
876      \vkern\dimexpr\topheight+\topdistance\relax
877      \the\headertextcontent
878      \vkern\dimexpr\headerheight+\headerdistance+\textdistance\relax
879      \anch_positions_place_anchors
880      \vkern\dimexpr-\textdistance-\textheight\relax
881      \the\texttextcontent
882      \vkern\textheight
883      \expand\everyendoftextbody
884      \vkern\footerdistance
885      \the\footertextcontent
886      \vkern\dimexpr\footerheight+\bottomdistance\relax
887      \the\bottomtextcontent
888      \vkern\bottomheight
889      \vfilll}%
890  \smashbox\b_page_layouts_element
891  \box\b_page_layouts_element}
892
893% only for very special controlled cases or experiments:
894
895\newinteger    \c_page_scale_lines
896\newdimension  \d_page_box_stretch_delta
897\newdimension  \d_page_box_stretch_criterium
898\newconditional\c_page_box_check_stretch
899
900% The stretch setting can depend on the current lineheight and the
901% alignment can be set later. So we need to delay.
902
903\def\page_box_check_limit_stretch_indeed#1%
904  {\edef\p_limitstretch{\layoutparameter\c!limitstretch}%
905   \ifx\p_limitstretch\v!yes
906     \d_page_box_stretch_criterium\zeropoint
907     \settrue\c_page_box_check_stretch
908   \orelse\ifx\p_limitstretch\v!auto
909     % safeguard for depth without limit set
910     \ifnum\bottomraggednessmode=\plusthree
911       \d_page_box_stretch_criterium2\lineheight
912       \settrue\c_page_box_check_stretch
913     \else
914       \d_page_box_stretch_criterium\maxdimen
915       \setfalse\c_page_box_check_stretch
916     \fi
917   \orelse\ifchkdimension\p_limitstretch\or
918     \d_page_box_stretch_criterium\p_limitstretch\relax
919     \settrue\c_page_box_check_stretch
920   \else
921     \d_page_box_stretch_criterium\maxdimen
922     \setfalse\c_page_box_check_stretch
923   \fi
924   \ifconditional\c_page_box_check_stretch
925     \boxfixstretch\d_page_box_stretch_criterium#1\relax
926     \d_page_box_stretch_delta\boxstretchdelta
927   \fi}
928
929\let\page_box_check_limit_stretch\relax % we test for this
930
931\appendtoks
932    \edef\p_limitstretch{\layoutparameter\c!limitstretch}%
933    \ifx\p_limitstretch\v!yes
934      \let\page_box_check_limit_stretch\page_box_check_limit_stretch_indeed
935    \orelse\ifx\p_limitstretch\v!auto
936      \let\page_box_check_limit_stretch\page_box_check_limit_stretch_indeed
937    \orelse\ifchkdimension\p_limitstretch\or
938      \let\page_box_check_limit_stretch\page_box_check_limit_stretch_indeed
939    \else
940      \let\page_box_check_limit_stretch\relax % we test for this
941    \fi
942\to \everysetuplayout
943
944\def\page_layouts_check_stretch#1%
945  {\ifcase\bottomraggednessmode
946     \d_page_box_stretch_delta\zeropoint
947   \orelse\ifrelax\page_box_check_limit_stretch
948     \d_page_box_stretch_delta\zeropoint
949   \else
950     \page_box_check_limit_stretch{#1}%
951   \fi}
952
953\def\page_insert_body#1#2%
954  {\setbox\b_page_layouts_element\vpack
955     {\offinterlineskip
956      \calculatereducedvsizes
957      \calculatehsizes
958      \page_layouts_swap_margins\v!page
959      \vkern\dimexpr\headerheight+\headerdistance+\textdistance\relax
960      \dontleavehmode
961      \hpack to \makeupwidth
962        {\begingroup
963         % \page_layouts_swap_margins\v!page
964           \goleftonpage
965           \ifdim\leftedgewidth>\zeropoint
966             \the\leftedgetextcontent
967             \kern\dimexpr\leftedgewidth+\leftedgedistance\relax
968           \fi
969           \ifdim\leftmarginwidth>\zeropoint
970             \the\leftmargintextcontent
971             \kern\dimexpr\leftmarginwidth+\leftmargindistance\relax
972           \fi
973         \endgroup
974         \page_apply_postprocessors_page{#2}%
975         \settextpagecontent\b_page_layouts_element{#1}{#2}%
976         \page_backgrounds_add_to_text\b_page_layouts_element
977         \page_grids_add_to_box\b_page_layouts_element
978         \box\b_page_layouts_element
979         \begingroup
980           \ifdim\rightmarginwidth>\zeropoint
981             \kern\rightmargindistance
982             \the\rightmargintextcontent
983             \kern\rightmarginwidth
984           \fi
985           \ifdim\rightedgewidth>\zeropoint
986             \kern\rightedgedistance
987             \the\rightedgetextcontent
988             \kern\rightedgewidth
989           \fi
990         \endgroup
991         \hss}}%
992   \smashbox\b_page_layouts_element
993   \box\b_page_layouts_element}
994
995%D Long ago (relative to 2023), when Thanh and I were discussing the \PDFTEX\ hz
996%D features with Hermann Zapf, we side tracked to vertical alignment. Hermann then
997%D suggested to play with vertical scaling because \quotation {No user will notice
998%D it}. Some quick experiment at the moment showed that it could work indeed but we
999%D left it at that (the code stayed around). It is for that reason that this now
1000%D present feature has the key \type {vz}, as variant on \type {hz} (a.k.a.\
1001%D expansion or fontadjust).
1002
1003\newconditional\c_page_scale_trace_vz
1004
1005\installtextracker
1006  {layout.vz}
1007  {\c_page_scale_trace_vz\conditionaltrue}
1008  {\c_page_scale_trace_vz\conditionalfalse}
1009
1010\installcorenamespace{vzdistance}
1011
1012\def\page_scale_text_box_trace
1013  {\writestatus{vz page \the\realpageno}{%
1014      %\s!goal=\the\pagegoal,
1015     %\s!total=\the\pagetotal,
1016       \s!page=\the\pagegoal,
1017       \s!text=\the\textheight,
1018     \s!height=\the\pagelastheight,
1019      \s!depth=\the\pagelastdepth,
1020    \s!stretch=\the\pagelaststretch,
1021     \s!shrink=\the\pagelastshrink,
1022       \s!fill=(\thewithoutunit\pagelastfilstretch,\thewithoutunit\pagelastfillstretch,\thewithoutunit\pagelastfilllstretch)%
1023   }}
1024
1025\def\page_scale_text_box_register_box#1%
1026  {\scratchheight\boxrepack#1%
1027   \scratchdimen\dimexpr\textheight-\scratchheight\relax
1028   \global\expandafter\dimensiondef\csname\??vzdistance\the\mofcolumns\endcsname
1029     \ifabsdim\scratchdimen>\c_page_scale_lines\lineheight
1030       \zeropoint
1031     \else
1032       \scratchheight
1033     \fi
1034   \relax
1035   \ifconditional\c_page_scale_trace_vz
1036     \page_scale_text_box_trace
1037   \fi}
1038
1039\def\page_scale_text_box_register_page
1040  {\scratchdimen\dimexpr\textheight-\pagelastheight\relax % not \pagegoal as that includes footnotes
1041   \global\expandafter\dimensiondef\csname\??vzdistance\the\mofcolumns\endcsname
1042     \ifabsdim\scratchdimen>\c_page_scale_lines\lineheight
1043       \zeropoint
1044     \orelse\ifdim\pagelastshrink>\zeropoint % maybe also stretch
1045       \zeropoint
1046     \else
1047       \pagelastheight
1048     \fi
1049   \relax
1050   \ifconditional\c_page_scale_trace_vz
1051     \page_scale_text_box_trace
1052   \fi}
1053
1054\def\page_scale_text_box
1055  {\scratchdistance\ifcsname\??vzdistance\the\mofcolumns\endcsname\lastnamedcs\else\zeropoint\fi
1056   \ifzeropt\scratchdistance
1057     \expandafter\gobbleoneargument
1058   \else
1059     \expandafter\page_scale_text_box_indeed
1060   \fi}
1061
1062\def\page_scale_text_box_indeed#1%
1063  {\scratchdimen \dimexpr\textheight-\scratchdistance\relax
1064   \scratchheight\ht#1%
1065   \scratchdepth \dp#1%
1066   \scratchwidth \wd#1%
1067   \scratchfloat \floatexpr\textheight/\scratchdistance\relax
1068   \setbox#1\vpack\bgroup
1069     \hpack\bgroup
1070       \normalexpanded{\scale
1071        %[\c!xscale=\plusthousand,\c!yscale=\scratchcounter]
1072         [\c!sx=1,\c!sy=\the\scratchfloat]%
1073         {\box#1}}%
1074     \egroup
1075     \ifconditional\c_page_scale_trace_vz
1076       \nointerlineskip
1077       \srule
1078         \s!height   \scratchdimen
1079         \s!yoffset 2\scratchdimen
1080         \s!xoffset-2\emwidth
1081         \s!width   2\emwidth
1082       \hpack
1083         \s!yoffset \scratchdimen
1084         \s!xoffset-2\emwidth
1085       \bgroup
1086         \edef\tempstring{\semiexpand\formatone{@0.3f}{\the\scratchfloat}}%
1087         \writestatus{vz page \the\realpageno}{scaling \tempstring\space applied}%
1088         \llap{\infofont\tempstring}%
1089       \egroup
1090     \fi
1091   \egroup
1092   \ht#1\scratchheight
1093   \dp#1\scratchdepth
1094   \wd#1\scratchwidth}
1095
1096\appendtoks
1097    \edef\p_lines{\layoutparameter\c!vz}%
1098    \ifx\p_lines\v!yes
1099        \c_page_scale_lines\plusone
1100    \orelse\ifchknumber\p_lines\or
1101        \c_page_scale_lines\lastchknumber
1102    \else
1103        \c_page_scale_lines\zerocount
1104    \fi
1105\to \everysetuplayout
1106
1107%D The main text area has to be combined with some additional (tracing) information.
1108%D
1109%D This will be stored as normal and overloaded in page-lyr and later in page-spr we
1110%D overload the the stored version .. eventually i will clear up the experimental
1111%D mess.
1112
1113\ifdefined\page_otr_flush_top_content\else \let\page_otr_flush_top_content\relax \fi
1114
1115\protected\def\settextpagecontent#1#2#3% #2 and #3 will disappear / is overloaded
1116  {\setbox#1\hpack to \makeupwidth
1117     {\hss                     % so don't change this
1118      \setlayoutcomponentattribute{\v!page:\v!text}%
1119      \vpack \layoutcomponentboxattribute to \textheight
1120        {\offinterlineskip
1121         \freezetextwidth
1122         \hsize\textwidth      % local variant of \sethsize  <<< in columns?
1123         \boxmaxdepth\maxdepth
1124         \page_otr_flush_top_content
1125         \noindent             % content can be < \hsize
1126         \page_otr_command_package_contents#2#3}% this will vbox
1127      \hss}%
1128   \dp#1\zeropoint}
1129
1130\protect \endinput
1131