page-plg.mkxl /size: 7765 b    last modification: 2025-02-21 11:03
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 footer right]
28%D \setupbottomtexts[a not so long left bottom text][another right footer thing]
29%D \setuptexttexts  [margin][something marginal][indeed]
30%D
31%D \startsetups pagelayout:table:left
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 \stopsetups
37%D
38%D \startsetups pagelayout:table:right
39%D     \setupTABLE[offset=overlay]%
40%D     \setupTABLE[c][1][width=\leftmarginwidth]%
41%D     \setupTABLE[c][2][width=\textwidth]%
42%D     \setupTABLE[c][3][width=\rightmarginwidth]%
43%D \stopsetups
44%D
45%D \startpagelayout[leftpage]
46%D   \directsetup{pagelayout:table:left}%
47%D   \bTABLE
48%D     \bTR
49%D       \bTD[nx=3,background=color,backgroundcolor=green]
50%D         \pagearea[header][text][middle]
51%D       \eTD
52%D     \eTR
53%D     \bTR
54%D       \bTD \pagearea[text][margin][left] \eTD
55%D       \bTD[nx=2] \pagearea[text] \eTD
56%D     \eTR
57%D     \bTR
58%D       \bTD[nx=3,offset=overlay]
59%D         {\directsetup{pagelayout:table:left}%
60%D          \bTABLE
61%D            \bTR
62%D              \bTD[nx=2] \pagearea[footer][text][left] \eTD
63%D              \bTD \pagearea[bottom][text][left] \eTD
64%D            \eTR
65%D          \eTABLE}
66%D        \eTD
67%D     \eTR
68%D   \eTABLE
69%D \stoppagelayout
70%D
71%D \startpagelayout[rightpage]
72%D   \directsetup{pagelayout:table:right}%
73%D   \bTABLE
74%D     \bTR
75%D       \bTD[nx=3] \pagearea[header][text][middle] \eTD
76%D     \eTR
77%D     \bTR
78%D       \bTD \pagearea[text][margin][left] \eTD
79%D       \bTD[nx=2] \pagearea[text] \eTD
80%D     \eTR
81%D     \bTR
82%D       \bTD[nx=3,offset=overlay]
83%D         {\directsetup{pagelayout:table:right}%
84%D          \bTABLE
85%D            \bTR
86%D              \bTD \pagearea[bottom][text][right] \eTD
87%D              \bTD[nx=2] \pagearea[footer][text][right] \eTD
88%D            \eTR
89%D          \eTABLE}
90%D       \eTD
91%D     \eTR
92%D   \eTABLE
93%D \stoppagelayout
94%D
95%D \startpagelayout[page]
96%D     \pagelayout[rightpage]
97%D \stoppagelayout
98%D
99%D \enabletrackers[pagelayout]
100%D
101%D \setuppagenumbering[alternative=doublesided,location=middle]
102%D
103%D \setuplayout
104%D   [alternative=makeup,
105%D    backspace=15mm,
106%D    cutspace=20mm,
107%D    leftmargin=15mm,
108%D    rightmargin=25mm,
109%D    topspace=0pt,
110%D    width=10cm]
111%D
112%D \definetextbackground
113%D   [test]
114%D   [state=start,
115%D    background=color,
116%D    backgroundcolor=yellow]
117%D
118%D \starttext
119%D
120%D     \dorecurse{10}{\samplefile{tufte}\par}
121%D
122%D     \samplefile{tufte} \starttest \samplefile{tufte} \stoptest \samplefile{tufte}
123%D
124%D     \starttabulate
125%D     \NC test \NC \starttest \samplefile{tufte} \stoptest \NC \NR
126%D     \stoptabulate
127%D
128%D     \dorecurse{10}{\samplefile{tufte}\par}
129%D
130%D \stoptext
131%D \stoptyping
132
133\unprotect
134
135\startcontextdefinitioncode
136
137\installcorenamespace{layoutmakeupalternative}
138
139\definecolor[\v!makeup:trace][s=.5,a=1,t=.5]
140
141\installtextracker
142  {pagelayout}
143  {\def\page_boxes_show_box{\backgroundline[\v!makeup:trace]}}
144  {\let\page_boxes_show_box\relax}
145
146\let\page_boxes_show_box\relax
147
148\def\page_boxes_construct_content_makeup#1#2#3% targetbox flusher box
149  {\setbox#1\vpack\bgroup
150     \offinterlineskip
151     \calculatereducedvsizes
152     \calculatehsizes
153     \page_layouts_swap_margins\v!page
154     \setbox#1\hbox\bgroup
155       \vbox to \textheight\bgroup
156          \offinterlineskip
157          \vskip{-1\topskip+\strutheight}% could be an option
158          \textwidth\makeupwidth
159          \hsize\textwidth
160          \boxmaxdepth\maxdepth
161          \noindent
162          \hpack to \zeropoint{\anch_positions_place_anchors}%
163          \page_boxes_show_box\bgroup
164            \page_otr_command_package_contents#2#3%
165          \egroup
166       \egroup
167     \egroup
168     \wd#1\makeupwidth
169     \ht#1\textheight
170     \dp#1\zeropoint
171     \hsize\paperwidth
172     \vsize\paperheight
173     \setbox#1\vbox\bgroup
174      %\settexthoffset
175      %\doifbothsidesoverruled\relax\relax{\hkern{-\texthoffset-\cutspace+\backspace}}%
176       \doifbothsidesoverruled\relax\relax{\hkern{-\paperwidth+\backspace+\makeupwidth-\cutspace+\backspace}}%
177       \page_boxes_show_box\bgroup
178         \csname\??layoutmakeupalternative\doifbothsidesoverruled\v!page\v!rightpage\v!leftpage\endcsname
179       \egroup
180     \egroup
181     \wd#1\paperwidth
182     \ht#1\paperheight
183     \dp#1\zeropoint
184    %\smashbox#1%
185     \box#1%
186   \egroup}
187
188\installlayoutalternative\v!makeup{\page_boxes_construct_content_makeup}
189
190\newbox\b_page_area
191
192\permanent\tolerant\protected\def\pagearea[#1]#*[#2]#*[#3]%
193  {\ifarguments
194     \expandafter\gobblethreeoptionals
195   \or
196     \expandafter\page_area_one
197   \or
198     \expandafter\page_area_two
199   \or
200     \expandafter\page_area_three
201   \fi[#1][#2][#3]}
202
203\def\page_area_three[#1][#2][#3]%
204  {\edef\m_page_area_three{#3}%
205   \ifx\m_page_area_three\v!left
206     \let\m_page_area_three\c!lefttext
207   \orelse\ifx\m_page_area_three\v!right
208     \let\m_page_area_three\c!righttext
209   \else
210     \let\m_page_area_three\c!middletext
211   \fi
212   \page_area_indeed{#1}{#2}\m_page_area_three}
213
214\def\page_area_two[#1][#2][#3]%
215  {\edef\m_page_area_three{\doifbothsidesoverruled\c!righttext\c!righttext\c!lefttext}%
216   \page_area_indeed{#1}{#2}\m_page_area_three}
217
218\def\page_area_one[#1][#2][#3]%
219  {\ifcstok{#1}\v!text
220     \iftrialtypesetting
221       \fakebox\pagebox
222     \else
223       \page_backgrounds_add_to_text\pagebox
224       \page_grids_add_to_box\pagebox
225       \box\pagebox
226     \fi
227   \fi}
228
229\def\page_area_indeed#1#2#3%
230  {\setbox\b_page_area\vbox{\getspecificlayouttext{#1}{#2}{#3}}%
231   \iftrialtypesetting
232     \fakebox\b_page_area
233   \orelse\ifcsname\??layoutbackgrounds#1#2\endcsname
234     \page_area_indeed_yes{#1}{#2}%
235   \else
236     \box\b_page_area
237   \fi}
238
239\def\page_area_indeed_yes#1#2%
240  {% todo: \localbackgroundframed{\??layoutbackgrounds#1#2}{#1:#2}
241   \localframed % todo:
242     [\??layoutbackgrounds#1#2]
243     [\c!width=\wd\b_page_area,
244      \c!height=\ht\b_page_area,
245      \c!offset=\v!overlay]
246     {\box\b_page_area}}
247
248% to be done nicely (proper namespacing)
249
250\defcsname\??layoutmakeupalternative\v!leftpage \endcsname{\csname\??layoutmakeupalternative\v!page\endcsname}
251\defcsname\??layoutmakeupalternative\v!rightpage\endcsname{\csname\??layoutmakeupalternative\v!page\endcsname}
252
253\permanent\protected\def\startpagelayout
254  {\bgroup
255   \catcode\endoflineasciicode\ignorecatcode
256   \page_layouts_start_layout}
257
258\aliased\let\stoppagelayout\relax
259
260\def\page_layouts_start_layout[#1]#2\stoppagelayout
261  {\egroup
262   \defcsname\??layoutmakeupalternative#1\endcsname{#2}}
263
264\permanent\protected\def\pagelayout[#1]% new
265  {\csname\??layoutmakeupalternative#1\endcsname}
266
267\stopcontextdefinitioncode
268
269\protect \endinput
270