page-plg.mkiv /size: 6140 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=page-pls,
3%D        version=2003.03.16,
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Page Setup,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Page Macros / Extra Page Building}
15
16%D This still needs some work, especially the dimensions need to be
17%D checked cq.\ optimized. Beware: method has become alternative!
18
19%D This feature has been present for a while but has never been
20%D exploited: pluggable pagebuilders. The next example code
21%D demonstrates the application of one such a plug-in. This variant
22%D support \type {page}, \type {leftpage} and \type {rightpage}
23%D definitions where specific areas are placed with the \type
24%D {\pagearea} command.
25%D
26%D \starttyping
27%D \setupheadertexts[the header text]
28%D \setupfootertexts[a pretty long left footer text][something right]
29%D \setupbottomtexts[a not so long bottom text][another right thing]
30%D \setuptexttexts  [margin][something marginal][indeed]
31%D
32%D \startpagelayout[leftpage]
33%D   \setupTABLE[offset=overlay]
34%D   \setupTABLE[c][1][width=\leftmarginwidth]
35%D   \setupTABLE[c][2][width=\textwidth]
36%D   \setupTABLE[c][3][width=\rightmarginwidth]
37%D   \bTABLE
38%D     \bTR
39%D       \bTD[nx=3,background=color,backgroundcolor=green]
40%D         \pagearea[header][text][middle]
41%D       \eTD
42%D     \eTR
43%D     \bTR
44%D       \bTD \pagearea[text][margin][left] \eTD
45%D       \bTD[nx=2] \pagearea[text] \eTD
46%D     \eTR
47%D     \bTR
48%D       \bTD[nx=3,offset=overlay]
49%D         {\bTABLE
50%D            \bTR
51%D              \bTD \pagearea[footer][text][left] \eTD
52%D              \bTD \pagearea[bottom][text][left] \eTD
53%D            \eTR
54%D          \eTABLE}
55%D        \eTD
56%D     \eTR
57%D   \eTABLE
58%D \stoppagelayout
59%D
60%D \startpagelayout[rightpage]
61%D   \setupTABLE[offset=overlay]
62%D   \setupTABLE[c][1][width=\leftmarginwidth]
63%D   \setupTABLE[c][2][width=\textwidth]
64%D   \setupTABLE[c][3][width=\rightmarginwidth]
65%D   \bTABLE
66%D     \bTR
67%D       \bTD[nx=3] \pagearea[header][text][middle] \eTD
68%D     \eTR
69%D     \bTR
70%D       \bTD \pagearea[text][margin][left] \eTD
71%D       \bTD[nx=2] \pagearea[text] \eTD
72%D     \eTR
73%D     \bTR
74%D       \bTD[nx=3,offset=overlay]
75%D         {\bTABLE
76%D            \bTR
77%D              \bTD \pagearea[bottom][text][right] \eTD
78%D              \bTD \pagearea[footer][text][right] \eTD
79%D            \eTR
80%D          \eTABLE}
81%D       \eTD
82%D     \eTR
83%D   \eTABLE
84%D \stoppagelayout
85%D
86%D \setupcolors[state=start]
87%D
88%D \setuppagenumbering[alternative=doublesided,location=]
89%D
90%D \setuplayout[alternative=makeup]
91%D
92%D \definetextbackground
93%D   [test]
94%D   [state=start,
95%D    background=color,
96%D    backgroundcolor=yellow]
97%D
98%D \starttext
99%D
100%D \dorecurse{10}{\input tufte \par}
101%D
102%D \input tufte \starttest \input tufte \stoptest \input tufte
103%D
104%D \starttabulate
105%D \NC test \NC \starttest \input tufte  \stoptest \NC \NR
106%D \stoptabulate
107%D
108%D \dorecurse{10}{\input tufte \par}
109%D
110%D \stoptext
111%D \stoptyping
112
113\unprotect
114
115\installcorenamespace{layoutmakeupalternative}
116
117\def\page_boxes_construct_content_makeup#1#2#3% targetbox flusher box
118  {\setbox#1\hbox
119     {\vbox to \textheight
120        {\offinterlineskip
121         \vskip\dimexpr-1\topskip+\strutheight\relax % could be an option
122         \textwidth\makeupwidth
123         \hsize\textwidth
124         \boxmaxdepth\maxdepth
125         \noindent
126         \page_otr_command_package_contents#2#3}}%
127   \wd#1\makeupwidth
128   \ht#1\textheight
129   \dp#1\zeropoint
130   \hsize\paperwidth
131   \vsize\paperheight
132   \setbox#1\vbox{\csname\??layoutmakeupalternative\doifbothsidesoverruled\v!page\v!rightpage\v!leftpage\endcsname}%
133   \wd#1\paperwidth
134   \ht#1\paperheight
135   \dp#1\zeropoint}
136
137\installlayoutalternative\v!makeup{\page_boxes_construct_content_makeup}
138
139\newbox\b_page_area
140
141\unexpanded\def\pagearea
142  {\dotripleempty\page_area}
143
144\def\page_area
145  {\ifthirdargument
146     \expandafter\page_area_three
147   \else\ifsecondargument
148     \doubleexpandafter\page_area_two
149   \else
150     \doubleexpandafter\page_area_one
151   \fi\fi}
152
153\def\page_area_three[#1][#2][#3]%
154  {\edef\m_page_area_three{#3}%
155   \ifx\m_page_area_three\v!left
156     \let\m_page_area_three\c!lefttext
157   \else\ifx\m_page_area_three\v!right
158     \let\m_page_area_three\c!righttext
159   \else
160     \let\m_page_area_three\c!middletext
161   \fi\fi
162   \page_area_indeed{#1}{#2}\m_page_area_three}
163
164\def\page_area_two[#1][#2][#3]%
165  {\edef\m_page_area_three{\doifbothsidesoverruled\c!righttext\c!righttext\c!lefttext}%
166   \page_area_indeed{#1}{#2}\m_page_area_three}
167
168\def\page_area_one[#1][#2][#3]%
169  {\edef\m_page_area_one{#1}
170   \ifx\m_page_area_one\v!text % copy due to trial runs in TABLE
171     \iftrialtypesetting
172       \fakebox\pagebox
173     \else
174       \page_backgrounds_add_to_text\pagebox
175       \page_grids_add_to_box\pagebox
176       \box\pagebox
177     \fi
178   \fi}
179
180\def\page_area_indeed#1#2#3%
181  {\setbox\b_page_area\vbox{\getspecificlayouttext{#1}{#2}{#3}}%
182   \iftrialtypesetting
183     \fakebox\b_page_area
184   \else\ifcsname\??layoutbackgrounds#1#2\endcsname
185     \page_area_indeed_yes{#1}{#2}%
186   \else
187     \box\b_page_area
188   \fi\fi}
189
190\def\page_area_indeed_yes#1#2%
191  {% todo: \localbackgroundframed{\??layoutbackgrounds#1#2}{#1:#2}
192   \localframed % todo:
193     [\??layoutbackgrounds#1#2]
194     [\c!width=\wd\b_page_area,
195      \c!height=\ht\b_page_area,
196      \c!offset=\v!overlay]
197     {\box\b_page_area}}
198
199% to be done nicely (proper namespacing)
200
201\setvalue{\??layoutmakeupalternative\v!leftpage }{\csname\??layoutmakeupalternative\v!page\endcsname}
202\setvalue{\??layoutmakeupalternative\v!rightpage}{\csname\??layoutmakeupalternative\v!page\endcsname}
203
204\unexpanded\def\startpagelayout
205  {\bgroup
206   \catcode\endoflineasciicode\ignorecatcode
207   \page_layouts_start_layout}
208
209\let\stoppagelayout\relax
210
211\def\page_layouts_start_layout[#1]#2\stoppagelayout
212  {\egroup
213   \setvalue{\??layoutmakeupalternative#1}{#2}}
214
215\protect \endinput
216