1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
29
30
31
32
33
34
35
36
37
38
39
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
52
53
54
55
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
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}
107 \cdef\currenttextstate {\namedlayoutelementparameter{#vertical}\c!state}
108
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
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
140
141
142
143
144
145
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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
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
221
222
223\defcsname\??layouttextstrut\v!yes\endcsname{\setstrut\strut}
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}}
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
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
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
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
273
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
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
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
351
352
353
354
355
356
357
358
359
360
361\def\page_layouts_place_text_line_unknown#vertical#height
362 {\global\resyncaftertextline\conditionaltrue
363 \begingroup
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
375
376\permanent\protected\def\resetlayouttextlines
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
392
393\permanent\tolerant\protected\def\settextcontent[#vertical]#spacer[#horizontal]#spacer[#S#one]#spacer[#S#two]#spacer[#S#three]
394 {\ifarguments\or\or\or
395 \defcsname\namedlayoutelementhash{#vertical:#horizontal}\c!middletext\endcsname
396 {\page_layouts_process_element_double{#one}{#one}}
397 \or
398 \defcsname\namedlayoutelementhash{#vertical:#horizontal}\begincsname\??layouttextcontent\v!text:#one\endcsname\c!middletext\endcsname
399 {\page_layouts_process_element_double{#two}{#two}}
400 \or
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
408
409\permanent\tolerant\protected\def\resettextcontent[#vertical]#spacer[#horizontal]#spacer[#S#tag]
410 {\ifarguments\or\or
411 \cdef\currentlayoutelement{#vertical:#horizontal}
412 \resetlayoutelementparameter\c!lefttext
413 \resetlayoutelementparameter\c!middletext
414 \resetlayoutelementparameter\c!righttext
415 \or
416
417
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
426
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
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
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}
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
457\lettonothing\page_layouts_place_extra_text_right
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
530
531
532
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
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
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
671 {\hsize#width\relax
672 \layoutelementparameter\c!before
673 \setlayoutcomponentattribute\currentlayoutelement
674 \hbox \layoutcomponentboxattribute to #width{#content}
675 \layoutelementparameter\c!after}}
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695\appendtoks \placerightmarginblock \kern\rightmarginwidth \to \rightmargintextcontent
696\appendtoks \placeleftmarginblock \kern\leftmarginwidth \to \leftmargintextcontent
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
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}
721 \orelse\ifarguments\or\or\or\or
722 \defcsname\namedlayoutelementhash {#vertical}#tag\endcsname{\setuptexts[#vertical][#horizontal][#a]\relax}
723 \or
724 \defcsname\namedlayoutelementhash{#vertical:#horizontal}#tag\endcsname{\setuptexts[#vertical][#horizontal][#a][#b]\relax}
725 \or
726 \defcsname\namedlayoutelementhash {#vertical}#tag\endcsname{\setuptexts[#vertical][#horizontal][#a][#b][#c]\relax}
727 \or
728 \defcsname\namedlayoutelementhash{#vertical:#horizontal}#tag\endcsname{\setuptexts[#vertical][#horizontal][#a][#b][#c][#d]\relax}
729 \fi}
730
731
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
747
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
756
757
758
759
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
767 {\strc_pagenumbers_place_location}
768
769\def\page_layouts_reset_page_number_location
770 {\ifrelax\m_page_layouts_page_number_location_v\else
771
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
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
825 \orelse\ifx\p_strc_pagenumbers_location\v!none
826
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
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
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
860
861\newbox\b_page_layouts_element
862
863\def\page_layouts_insert_elements
864 {\ifcase\pageornamentstate
865 \page_layouts_place_elements_indeed
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
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
901
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
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
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
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
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
996
997
998
999
1000
1001
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
1015
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
1041 \global\expandafter\dimensiondef\csname\??vzdistance\the\mofcolumns\endcsname
1042 \ifabsdim\scratchdimen>\c_page_scale_lines\lineheight
1043 \zeropoint
1044 \orelse\ifdim\pagelastshrink>\zeropoint
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
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!xoffset2\emwidth
1081 \s!width 2\emwidth
1082 \hpack
1083 \s!yoffset \scratchdimen
1084 \s!xoffset2\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
1108
1109
1110
1111
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
1116 {\setbox#1\hpack to \makeupwidth
1117 {\hss
1118 \setlayoutcomponentattribute{\v!page:\v!text}
1119 \vpack \layoutcomponentboxattribute to \textheight
1120 {\offinterlineskip
1121 \freezetextwidth
1122 \hsize\textwidth
1123 \boxmaxdepth\maxdepth
1124 \page_otr_flush_top_content
1125 \noindent
1126 \page_otr_command_package_contents#2#3}
1127 \hss}
1128 \dp#1\zeropoint}
1129
1130\protect \endinput
1131 |