summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/page-plg.mkiv
blob: b59a05a945410ca4550c4305d69719472ba584d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
%D \module
%D   [       file=page-pls,
%D        version=2003.03.16,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Page Setup,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Page Macros / Extra Page Building}

%D This still needs some work, especially the dimensions need to be
%D checked cq.\ optimized. Beware: method has become alternative!

%D This feature has been present for a while but has never been
%D exploited: pluggable pagebuilders. The next example code
%D demonstrates the application of one such a plug-in. This variant
%D support \type {page}, \type {leftpage} and \type {rightpage}
%D definitions where specific areas are placed with the \type
%D {\pagearea} command.
%D
%D \starttyping
%D \setupheadertexts[the header text]
%D \setupfootertexts[a pretty long left footer text][something right]
%D \setupbottomtexts[a not so long bottom text][another right thing]
%D \setuptexttexts  [margin][something marginal][indeed]
%D
%D \startpagelayout[leftpage]
%D   \setupTABLE[offset=overlay]
%D   \setupTABLE[c][1][width=\leftmarginwidth]
%D   \setupTABLE[c][2][width=\textwidth]
%D   \setupTABLE[c][3][width=\rightmarginwidth]
%D   \bTABLE
%D     \bTR
%D       \bTD[nx=3,background=color,backgroundcolor=green]
%D         \pagearea[header][text][middle]
%D       \eTD
%D     \eTR
%D     \bTR
%D       \bTD \pagearea[text][margin][left] \eTD
%D       \bTD[nx=2] \pagearea[text] \eTD
%D     \eTR
%D     \bTR
%D       \bTD[nx=3,offset=overlay]
%D         {\bTABLE
%D            \bTR
%D              \bTD \pagearea[footer][text][left] \eTD
%D              \bTD \pagearea[bottom][text][left] \eTD
%D            \eTR
%D          \eTABLE}
%D        \eTD
%D     \eTR
%D   \eTABLE
%D \stoppagelayout
%D
%D \startpagelayout[rightpage]
%D   \setupTABLE[offset=overlay]
%D   \setupTABLE[c][1][width=\leftmarginwidth]
%D   \setupTABLE[c][2][width=\textwidth]
%D   \setupTABLE[c][3][width=\rightmarginwidth]
%D   \bTABLE
%D     \bTR
%D       \bTD[nx=3] \pagearea[header][text][middle] \eTD
%D     \eTR
%D     \bTR
%D       \bTD \pagearea[text][margin][left] \eTD
%D       \bTD[nx=2] \pagearea[text] \eTD
%D     \eTR
%D     \bTR
%D       \bTD[nx=3,offset=overlay]
%D         {\bTABLE
%D            \bTR
%D              \bTD \pagearea[bottom][text][right] \eTD
%D              \bTD \pagearea[footer][text][right] \eTD
%D            \eTR
%D          \eTABLE}
%D       \eTD
%D     \eTR
%D   \eTABLE
%D \stoppagelayout
%D
%D \setupcolors[state=start]
%D
%D \setuppagenumbering[alternative=doublesided,location=]
%D
%D \setuplayout[alternative=makeup]
%D
%D \definetextbackground
%D   [test]
%D   [state=start,
%D    background=color,
%D    backgroundcolor=yellow]
%D
%D \starttext
%D
%D \dorecurse{10}{\input tufte \par}
%D
%D \input tufte \starttest \input tufte \stoptest \input tufte
%D
%D \starttabulate
%D \NC test \NC \starttest \input tufte  \stoptest \NC \NR
%D \stoptabulate
%D
%D \dorecurse{10}{\input tufte \par}
%D
%D \stoptext
%D \stoptyping

\unprotect

\installcorenamespace{layoutmakeupalternative}

\def\page_boxes_construct_content_makeup#1#2#3% targetbox flusher box
  {\setbox#1\hbox
     {\vbox to \textheight
        {\offinterlineskip
         \vskip\dimexpr-1\topskip+\strutheight\relax % could be an option
         \textwidth\makeupwidth
         \hsize\textwidth
         \boxmaxdepth\maxdepth
         \noindent
         \page_otr_command_package_contents#2#3}}%
   \wd#1\makeupwidth
   \ht#1\textheight
   \dp#1\zeropoint
   \hsize\paperwidth
   \vsize\paperheight
   \setbox#1\vbox{\csname\??layoutmakeupalternative\doifbothsidesoverruled\v!page\v!rightpage\v!leftpage\endcsname}%
   \wd#1\paperwidth
   \ht#1\paperheight
   \dp#1\zeropoint}

\installlayoutalternative\v!makeup{\page_boxes_construct_content_makeup}

\newbox\b_page_area

\unexpanded\def\pagearea
  {\dotripleempty\page_area}

\def\page_area
  {\ifthirdargument
     \expandafter\page_area_three
   \else\ifsecondargument
     \doubleexpandafter\page_area_two
   \else
     \doubleexpandafter\page_area_one
   \fi\fi}

\def\page_area_three[#1][#2][#3]%
  {\edef\m_page_area_three{#3}%
   \ifx\m_page_area_three\v!left
     \let\m_page_area_three\c!lefttext
   \else\ifx\m_page_area_three\v!right
     \let\m_page_area_three\c!righttext
   \else
     \let\m_page_area_three\c!middletext
   \fi\fi
   \page_area_indeed{#1}{#2}\m_page_area_three}

\def\page_area_two[#1][#2][#3]%
  {\edef\m_page_area_three{\doifbothsidesoverruled\c!righttext\c!righttext\c!lefttext}%
   \page_area_indeed{#1}{#2}\m_page_area_three}

\def\page_area_one[#1][#2][#3]%
  {\edef\m_page_area_one{#1}
   \ifx\m_page_area_one\v!text % copy due to trial runs in TABLE
     \iftrialtypesetting
       \fakebox\pagebox
     \else
       \page_backgrounds_add_to_text\pagebox
       \page_grids_add_to_box\pagebox
       \box\pagebox
     \fi
   \fi}

\def\page_area_indeed#1#2#3%
  {\setbox\b_page_area\vbox{\getspecificlayouttext{#1}{#2}{#3}}%
   \iftrialtypesetting
     \fakebox\b_page_area
   \else\ifcsname\??layoutbackgrounds#1#2\endcsname
     \page_area_indeed_yes{#1}{#2}%
   \else
     \box\b_page_area
   \fi\fi}

\def\page_area_indeed_yes#1#2%
  {% todo: \localbackgroundframed{\??layoutbackgrounds#1#2}{#1:#2}
   \localframed % todo:
     [\??layoutbackgrounds#1#2]
     [\c!width=\wd\b_page_area,
      \c!height=\ht\b_page_area,
      \c!offset=\v!overlay]
     {\box\b_page_area}}

% to be done nicely (proper namespacing)

\setvalue{\??layoutmakeupalternative\v!leftpage }{\csname\??layoutmakeupalternative\v!page\endcsname}
\setvalue{\??layoutmakeupalternative\v!rightpage}{\csname\??layoutmakeupalternative\v!page\endcsname}

\unexpanded\def\startpagelayout
  {\bgroup
   \catcode\endoflineasciicode\ignorecatcode
   \page_layouts_start_layout}

\let\stoppagelayout\relax

\def\page_layouts_start_layout[#1]#2\stoppagelayout
  {\egroup
   \setvalue{\??layoutmakeupalternative#1}{#2}}

\protect \endinput