page-plg.mkxl /size: 6244 b    last modification: 2021-10-28 13:51
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 checked cq.\
17%D optimized. Beware: method has become alternative!
18
19%D This feature has been present for a while but has never been exploited: pluggable
20%D pagebuilders. The next example code demonstrates the application of one such a
21%D plug-in. This variant support \type {page}, \type {leftpage} and \type
22%D {rightpage} definitions where specific areas are placed with the \type
23%D {\pagearea} command.
24%D
25%D \starttyping
26%D \setupheadertexts[the header text]
27%D \setupfootertexts[a pretty long left footer text][something right]
28%D \setupbottomtexts[a not so long bottom text][another right thing]
29%D \setuptexttexts  [margin][something marginal][indeed]
30%D
31%D \startpagelayout[leftpage]
32%D   \setupTABLE[offset=overlay]
33%D   \setupTABLE[c][1][width=\leftmarginwidth]
34%D   \setupTABLE[c][2][width=\textwidth]
35%D   \setupTABLE[c][3][width=\rightmarginwidth]
36%D   \bTABLE
37%D     \bTR
38%D       \bTD[nx=3,background=color,backgroundcolor=green]
39%D         \pagearea[header][text][middle]
40%D       \eTD
41%D     \eTR
42%D     \bTR
43%D       \bTD \pagearea[text][margin][left] \eTD
44%D       \bTD[nx=2] \pagearea[text] \eTD
45%D     \eTR
46%D     \bTR
47%D       \bTD[nx=3,offset=overlay]
48%D         {\bTABLE
49%D            \bTR
50%D              \bTD \pagearea[footer][text][left] \eTD
51%D              \bTD \pagearea[bottom][text][left] \eTD
52%D            \eTR
53%D          \eTABLE}
54%D        \eTD
55%D     \eTR
56%D   \eTABLE
57%D \stoppagelayout
58%D
59%D \startpagelayout[rightpage]
60%D   \setupTABLE[offset=overlay]
61%D   \setupTABLE[c][1][width=\leftmarginwidth]
62%D   \setupTABLE[c][2][width=\textwidth]
63%D   \setupTABLE[c][3][width=\rightmarginwidth]
64%D   \bTABLE
65%D     \bTR
66%D       \bTD[nx=3] \pagearea[header][text][middle] \eTD
67%D     \eTR
68%D     \bTR
69%D       \bTD \pagearea[text][margin][left] \eTD
70%D       \bTD[nx=2] \pagearea[text] \eTD
71%D     \eTR
72%D     \bTR
73%D       \bTD[nx=3,offset=overlay]
74%D         {\bTABLE
75%D            \bTR
76%D              \bTD \pagearea[bottom][text][right] \eTD
77%D              \bTD \pagearea[footer][text][right] \eTD
78%D            \eTR
79%D          \eTABLE}
80%D       \eTD
81%D     \eTR
82%D   \eTABLE
83%D \stoppagelayout
84%D
85%D \setupcolors[state=start]
86%D
87%D \setuppagenumbering[alternative=doublesided,location=]
88%D
89%D \setuplayout[alternative=makeup]
90%D
91%D \definetextbackground
92%D   [test]
93%D   [state=start,
94%D    background=color,
95%D    backgroundcolor=yellow]
96%D
97%D \starttext
98%D
99%D \dorecurse{10}{\input tufte \par}
100%D
101%D \input tufte \starttest \input tufte \stoptest \input tufte
102%D
103%D \starttabulate
104%D \NC test \NC \starttest \input tufte  \stoptest \NC \NR
105%D \stoptabulate
106%D
107%D \dorecurse{10}{\input tufte \par}
108%D
109%D \stoptext
110%D \stoptyping
111
112\unprotect
113
114\startcontextdefinitioncode
115
116\installcorenamespace{layoutmakeupalternative}
117
118\def\page_boxes_construct_content_makeup#1#2#3% targetbox flusher box
119  {\setbox#1\hbox
120     {\vbox to \textheight
121        {\offinterlineskip
122         \vskip\dimexpr-1\topskip+\strutheight\relax % could be an option
123         \textwidth\makeupwidth
124         \hsize\textwidth
125         \boxmaxdepth\maxdepth
126         \noindent
127         \page_otr_command_package_contents#2#3}}%
128   \wd#1\makeupwidth
129   \ht#1\textheight
130   \dp#1\zeropoint
131   \hsize\paperwidth
132   \vsize\paperheight
133   \setbox#1\vbox{\csname\??layoutmakeupalternative\doifbothsidesoverruled\v!page\v!rightpage\v!leftpage\endcsname}%
134   \wd#1\paperwidth
135   \ht#1\paperheight
136   \dp#1\zeropoint}
137
138\installlayoutalternative\v!makeup{\page_boxes_construct_content_makeup}
139
140\newbox\b_page_area
141
142\permanent\tolerant\protected\def\pagearea[#1]#*[#2]#*[#3]%
143  {\ifarguments
144     \expandafter\gobblethreeoptionals
145   \or
146     \expandafter\page_area_one
147   \or
148     \expandafter\page_area_two
149   \or
150     \expandafter\page_area_three
151   \fi[#1][#2][#3]}
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   \orelse\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
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   \orelse\ifcsname\??layoutbackgrounds#1#2\endcsname
185     \page_area_indeed_yes{#1}{#2}%
186   \else
187     \box\b_page_area
188   \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\defcsname\??layoutmakeupalternative\v!leftpage \endcsname{\csname\??layoutmakeupalternative\v!page\endcsname}
202\defcsname\??layoutmakeupalternative\v!rightpage\endcsname{\csname\??layoutmakeupalternative\v!page\endcsname}
203
204\permanent\protected\def\startpagelayout
205  {\bgroup
206   \catcode\endoflineasciicode\ignorecatcode
207   \page_layouts_start_layout}
208
209\aliased\let\stoppagelayout\relax
210
211\def\page_layouts_start_layout[#1]#2\stoppagelayout
212  {\egroup
213   \defcsname\??layoutmakeupalternative#1\endcsname{#2}}
214
215\stopcontextdefinitioncode
216
217\protect \endinput
218