1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Page Macros Boxing}
15
16\unprotect
17
18
19
20
21
22\def\page_boxes_apply_center#box
23 {\printpaperwidth \v_page_target_scale\printpaperwidth \relax
24 \printpaperheight\v_page_target_scale\printpaperheight\relax
25 \ifdim\printpaperheight>\ht#box\relax
26 \page_boxes_apply_center_indeed#box
27 \orelse\ifdim\printpaperwidth>\wd#box\relax
28 \page_boxes_apply_center_indeed#box
29 \fi}
30
31\def\page_boxes_apply_center_indeed_l_r#box
32 {\v_page_target_left
33 \v_page_target_left_fill
34 \box#box
35 \v_page_target_right_fill
36 \v_page_target_right}
37
38\def\page_boxes_apply_center_indeed_r_l#box
39 {\v_page_target_right
40 \v_page_target_right_fill
41 \box#box
42 \v_page_target_left_fill
43 \v_page_target_left}
44
45\def\page_boxes_apply_center_indeed#box
46 {\setbox#box\vpack to \printpaperheight
47 {\v_page_target_top
48 \v_page_target_top_fill
49 \hpack to \printpaperwidth
50 {\ifconditional\c_page_target_print_doublesided
51 \doifbothsides
52 {\page_boxes_apply_center_indeed_l_r#box}
53 {\page_boxes_apply_center_indeed_l_r#box}
54 {\page_boxes_apply_center_indeed_r_l#box}
55 \else
56 \page_boxes_apply_center_indeed_l_r#box
57 \fi}
58 \par
59 \v_page_target_bottom_fill
60 \v_page_target_bottom}}
61
62\def\page_boxes_apply_offset_indeed#box
63 {\scratchwidth \wd#box
64 \scratchheight\ht#box
65 \scratchdepth \dp#box
66 \setbox#box\vpack
67 {\offinterlineskip
68 \vskip\topoffset
69
70 \hskip\doifbothsides\backoffset
71 \box#box}
72 \wd#box\scratchwidth
73 \ht#box\scratchheight
74 \dp#box\scratchdepth}
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91\def\page_boxes_apply_offset
92 {\unless\ifzeropt\topoffset
93 \expandafter\page_boxes_apply_offset_indeed
94 \orunless\ifzeropt\backoffset
95 \expandafter\page_boxes_apply_offset_indeed
96 \else
97 \expandafter\gobbleoneargument
98 \fi}
99
100\def\page_boxes_apply_replicate
101 {\ifnum\layoutparameter\c!nx>\plusone
102 \expandafter\page_boxes_apply_replicate_indeed
103 \orelse\ifnum\layoutparameter\c!ny>\plusone
104 \expandafter\page_boxes_apply_replicate_indeed
105 \else
106 \expandafter\gobbleoneargument
107 \fi}
108
109\def\page_boxes_apply_replicate_indeed#box
110 {\setbox#box\vpack
111 {\offinterlineskip
112 \dorecurse{\layoutparameter\c!ny}
113 {\hpack{\dorecurse{\layoutparameter\c!nx}{\copy#box\kern\layoutparameter\c!dx}\unskip}
114 \vskip\layoutparameter\c!dy}
115 \unskip}}
116
117\def\page_boxes_apply_orientate_paper#box
118 {\ifnum\the\c_page_target_paper_orientation\the\c_page_target_paper_reverse>\zerocount
119 \page_boxes_apply_orientate_indeed\c_page_target_paper_orientation\c_page_target_paper_reverse{#box}
120 \fi}
121
122\def\page_boxes_apply_orientate_print#box
123 {\ifnum\the\c_page_target_print_orientation\the\c_page_target_print_reverse>\zerocount
124 \page_boxes_apply_orientate_indeed\c_page_target_print_orientation\c_page_target_print_reverse{#box}
125 \fi}
126
127\def\page_boxes_apply_orientate_indeed#odd#even#box
128 {\setbox#box\vpack
129 {\edef\p_rotation{\number\ifdoublesided\ifodd\realpageno#odd\else#even\fi\else#odd\fi}
130 \dorotatebox\p_rotation\hpack{\box#box}}}
131
132\def\page_boxes_apply_mirror#box
133 {\setbox#box\vpack{\mirror{\box#box}}}
134
135\def\page_boxes_apply_mirror_paper#box{\ifconditional\c_page_target_paper_mirror\page_boxes_apply_mirror{#box}\fi}
136\def\page_boxes_apply_mirror_print#box{\ifconditional\c_page_target_print_mirror\page_boxes_apply_mirror{#box}\fi}
137
138\aliased\let\page_boxes_apply_negate\negatecolorbox
139
140\def\page_boxes_apply_negate_print#box
141 {\ifconditional\c_page_target_print_negate
142 \page_boxes_apply_negate#box
143 \orelse\ifconditional\c_page_target_paper_negate
144 \page_boxes_apply_negate#box
145 \fi}
146
147\let\p_page_layouts_scale\relax
148\let\p_page_layouts_sx \relax
149\let\p_page_layouts_sy \relax
150
151\def\page_boxes_apply_scale#box
152 {\edef\p_page_layouts_scale{\layoutparameter\c!scale}
153 \ifdim\p_page_layouts_scale\points=\onepoint
154 \edef\p_page_layouts_sx{\layoutparameter\c!sx}
155 \edef\p_page_layouts_sy{\layoutparameter\c!sy}
156 \ifdim\p_page_layouts_sx\points=\onepoint
157 \ifdim\layoutparameter\c!sy\points=\onepoint
158
159 \else
160 \page_boxes_apply_scale_indeed\p_page_layouts_sx\p_page_layouts_sy{#box}
161 \fi
162 \else
163 \page_boxes_apply_scale_indeed\p_page_layouts_sx\p_page_layouts_sy{#box}
164 \fi
165 \else
166 \page_boxes_apply_scale_indeed\p_page_layouts_scale\p_page_layouts_scale{#box}
167 \fi}
168
169\def\page_boxes_apply_scale_indeed#sx#sy#box
170 {\setbox#box\vpack{\scale[\c!sx=#sx,\c!sy=#sy]{\box#box}}
171 \paperwidth #sx\paperwidth
172 \paperheight#sy\paperheight}
173
174
175
176
177
178
179
180
181
182
183
184
185
186\newconditional\c_page_boxes_clip_print \c_page_boxes_clip_print\conditionaltrue
187
188\def\page_boxes_apply_clip_print_left
189 {\ifconditional\c_page_boxes_clip_print
190 \expandafter\page_boxes_apply_clip_print_indeed\expandafter\conditionalfalse
191 \else
192 \expandafter\gobbleoneargument
193 \fi}
194
195\def\page_boxes_apply_clip_print_right
196 {\ifconditional\c_page_boxes_clip_print
197 \expandafter\page_boxes_apply_clip_print_indeed\expandafter\conditionaltrue
198 \else
199 \expandafter\gobbleoneargument
200 \fi}
201
202\def\page_boxes_apply_clip_print_indeed#right#box
203 {\scratchoffset\pagebackgroundoffset
204 \scratchwidth \wd#box
205 \scratchheight\ht#box
206 \scratchdepth \dp#box
207 \setbox#box\hpack
208 {\advanceby\scratchheight\dimexpr\scratchdepth2\scratchoffset\relax
209 \advanceby\scratchwidth \scratchoffset
210 \ifconditional#right\relax
211 \scratchdimen\scratchoffset
212 \kern\scratchdimen
213 \else
214 \scratchdimen\zeropoint
215 \fi
216 \lower\scratchoffset\hpack
217 {\clip
218 [\c!hoffset=\scratchdimen,
219 \c!voffset=\scratchoffset,
220 \c!width=\scratchwidth,
221 \c!height=\scratchheight]
222 {\box#box}}}
223 \wd#box\scratchwidth
224 \ht#box\scratchheight
225 \dp#box\scratchdepth}
226
227\def\page_boxes_apply_clip_paper
228 {\scratchoffset\layoutparameter\c!clipoffset\relax
229 \ifdim\scratchoffset>\zeropoint
230 \expandafter\page_boxes_apply_clip_paper_indeed
231 \else
232 \expandafter\gobbleoneargument
233 \fi}
234
235\def\page_boxes_apply_clip_paper_indeed#box
236 {\scratchwidth \wd#box
237 \scratchheight\ht#box
238 \scratchdepth \dp#box
239 \setbox#box\hpack
240 {\advanceby\scratchheight\dimexpr\scratchdepth2\scratchoffset\relax
241 \advanceby\scratchwidth \scratchoffset
242 \doifbothsides
243 {\advanceby\scratchwidth\scratchoffset
244 \scratchdimen\scratchoffset
245 \kern\scratchdimen}
246 {\scratchdimen\zeropoint}
247 {\scratchdimen\scratchoffset
248 \kern\scratchdimen}
249 \lower\scratchoffset\hpack
250 {\clip
251 [\c!hoffset=\scratchdimen,
252 \c!voffset=\scratchoffset,
253 \c!width=\scratchwidth,
254 \c!height=\scratchheight]
255 {\box#box}}}
256 \wd#box\scratchwidth
257 \ht#box\scratchheight
258 \dp#box\scratchdepth}
259
260
261
262
263
264
265
266
267
268
269
270\def\page_boxes_apply_offsets#1
271 {\setbox#1\vpack to \paperheight
272 {\hsize\paperwidth
273 \vkern\topspace
274 \hkern\doifbothsides\backspace\backspace{\dimexpr\paperwidth\backspace\makeupwidth\relax}
275
276
277
278 \box#1}
279 \dp#1\zeropoint}
280
281
282
283
284
285
286
287
288
289
290
291
292\newconditional\c_page_areas_enabled
293\newbox \b_page_areas_registered
294
295\permanent\protected\def\enabletextarearegistration
296 {\global\c_page_areas_enabled\conditionaltrue}
297
298\def\page_areas_registered_box
299 {\ifconditional\c_page_areas_enabled
300 \expandafter\page_areas_registered_box_indeed
301 \else
302 \expandafter\page_areas_registered_box_forget
303 \fi}
304
305\def\page_areas_registered_box_forget#1#2#3
306 {\box#3}
307
308\def\page_areas_registered_box_indeed#1#2#3
309 {\anch_mark_flow_box{#3}}
310
311\def\page_areas_register_boxed#1
312 {\begingroup
313 \setbox\scratchbox\vpack{#1}
314 \wd\scratchbox\makeupwidth
315 \vpack{\page_areas_registered_box00\scratchbox}
316 \endgroup}
317
318\def\page_areas_register_direct#1#2
319 {\scratchdepth\dp#2
320 \dp#2\strutdepth
321 \anch_mark_flow_only{#2}
322 \dp#2\scratchdepth
323 #1#2}
324
325\protect \endinput
326 |