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
101
102\def\page_boxes_apply_replicate
103 {\ifnum{\layoutparameter\c!nx}>\plusone
104 \expandafter\page_boxes_apply_replicate_indeed
105 \orelse\ifnum{\layoutparameter\c!ny}>\plusone
106 \expandafter\page_boxes_apply_replicate_indeed
107 \else
108 \expandafter\gobbleoneargument
109 \fi}
110
111\def\page_boxes_apply_replicate_indeed#box
112 {\setbox#box\vpack
113 {\offinterlineskip
114 \dorecurse{\layoutparameter\c!ny}
115 {\hpack{\dorecurse{\layoutparameter\c!nx}{\copy#box\kern\layoutparameter\c!dx}\unskip}
116 \vskip{\layoutparameter\c!dy}}
117 \unskip}}
118
119\def\page_boxes_apply_orientate_paper#box
120 {\ifnum\the\c_page_target_paper_orientation\the\c_page_target_paper_reverse>\zerocount
121 \page_boxes_apply_orientate_indeed\c_page_target_paper_orientation\c_page_target_paper_reverse{#box}
122 \fi}
123
124\def\page_boxes_apply_orientate_print#box
125 {\ifnum\the\c_page_target_print_orientation\the\c_page_target_print_reverse>\zerocount
126 \page_boxes_apply_orientate_indeed\c_page_target_print_orientation\c_page_target_print_reverse{#box}
127 \fi}
128
129\def\page_boxes_apply_orientate_indeed#odd#even#box
130 {\setbox#box\vpack
131 {\edef\p_rotation{\number\ifdoublesided\ifodd\realpageno#odd\else#even\fi\else#odd\fi}
132 \dorotatebox\p_rotation\hpack{\box#box}}}
133
134\def\page_boxes_apply_mirror#box
135 {\setbox#box\vpack{\mirror{\box#box}}}
136
137\def\page_boxes_apply_mirror_paper#box{\ifconditional\c_page_target_paper_mirror\page_boxes_apply_mirror{#box}\fi}
138\def\page_boxes_apply_mirror_print#box{\ifconditional\c_page_target_print_mirror\page_boxes_apply_mirror{#box}\fi}
139
140\aliased\let\page_boxes_apply_negate\negatecolorbox
141
142\def\page_boxes_apply_negate_print#box
143 {\ifconditional\c_page_target_print_negate
144 \page_boxes_apply_negate#box
145 \orelse\ifconditional\c_page_target_paper_negate
146 \page_boxes_apply_negate#box
147 \fi}
148
149\let\p_page_layouts_scale\relax
150\let\p_page_layouts_sx \relax
151\let\p_page_layouts_sy \relax
152
153\def\page_boxes_apply_scale#box
154 {\edef\p_page_layouts_scale{\layoutparameter\c!scale}
155 \ifdim\p_page_layouts_scale\points=\onepoint
156 \edef\p_page_layouts_sx{\layoutparameter\c!sx}
157 \edef\p_page_layouts_sy{\layoutparameter\c!sy}
158 \ifdim\p_page_layouts_sx\points=\onepoint
159 \ifdim\layoutparameter\c!sy\points=\onepoint
160
161 \else
162 \page_boxes_apply_scale_indeed\p_page_layouts_sx\p_page_layouts_sy{#box}
163 \fi
164 \else
165 \page_boxes_apply_scale_indeed\p_page_layouts_sx\p_page_layouts_sy{#box}
166 \fi
167 \else
168 \page_boxes_apply_scale_indeed\p_page_layouts_scale\p_page_layouts_scale{#box}
169 \fi}
170
171\def\page_boxes_apply_scale_indeed#sx#sy#box
172 {\setbox#box\vpack{\scale[\c!sx=#sx,\c!sy=#sy]{\box#box}}
173 \paperwidth #sx\paperwidth
174 \paperheight#sy\paperheight}
175
176
177
178
179
180
181
182
183
184
185
186
187
188\newconditional\c_page_boxes_clip_print \c_page_boxes_clip_print\conditionaltrue
189
190\def\page_boxes_apply_clip_print_left
191 {\ifconditional\c_page_boxes_clip_print
192 \expandafter\page_boxes_apply_clip_print_indeed\expandafter\conditionalfalse
193 \else
194 \expandafter\gobbleoneargument
195 \fi}
196
197\def\page_boxes_apply_clip_print_right
198 {\ifconditional\c_page_boxes_clip_print
199 \expandafter\page_boxes_apply_clip_print_indeed\expandafter\conditionaltrue
200 \else
201 \expandafter\gobbleoneargument
202 \fi}
203
204\def\page_boxes_apply_clip_print_indeed#right#box
205 {\scratchoffset\pagebackgroundoffset
206 \scratchwidth \wd#box
207 \scratchheight\ht#box
208 \scratchdepth \dp#box
209 \setbox#box\hpack
210 {\advanceby\scratchheight{\scratchdepth2\scratchoffset}
211 \advanceby\scratchwidth\scratchoffset
212 \ifconditional#right\relax
213 \scratchdimen\scratchoffset
214 \kern\scratchdimen
215 \else
216 \scratchdimen\zeropoint
217 \fi
218 \lower\scratchoffset\hpack
219 {\clip
220 [\c!hoffset=\scratchdimen,
221 \c!voffset=\scratchoffset,
222 \c!width=\scratchwidth,
223 \c!height=\scratchheight]
224 {\box#box}}}
225 \wd#box\scratchwidth
226 \ht#box\scratchheight
227 \dp#box\scratchdepth}
228
229\def\page_boxes_apply_clip_paper
230 {\scratchoffset{\layoutparameter\c!clipoffset}
231 \ifdim\scratchoffset>\zeropoint
232 \expandafter\page_boxes_apply_clip_paper_indeed
233 \else
234 \expandafter\gobbleoneargument
235 \fi}
236
237\def\page_boxes_apply_clip_paper_indeed#box
238 {\scratchwidth \wd#box
239 \scratchheight\ht#box
240 \scratchdepth \dp#box
241 \setbox#box\hpack
242 {\advanceby\scratchheight{\scratchdepth2\scratchoffset}
243 \advanceby\scratchwidth\scratchoffset
244 \doifbothsides
245 {\advanceby\scratchwidth\scratchoffset
246 \scratchdimen\scratchoffset
247 \kern\scratchdimen}
248 {\scratchdimen\zeropoint}
249 {\scratchdimen\scratchoffset
250 \kern\scratchdimen}
251 \lower\scratchoffset\hpack
252 {\clip
253 [\c!hoffset=\scratchdimen,
254 \c!voffset=\scratchoffset,
255 \c!width=\scratchwidth,
256 \c!height=\scratchheight]
257 {\box#box}}}
258 \wd#box\scratchwidth
259 \ht#box\scratchheight
260 \dp#box\scratchdepth}
261
262
263
264
265
266
267
268
269
270
271
272\def\page_boxes_apply_offsets#1
273 {\setbox#1\vpack to \paperheight
274 {\hsize\paperwidth
275 \vkern\topspace
276 \hkern{\doifbothsides\backspace\backspace{\paperwidth\backspace\makeupwidth}}
277
278
279
280 \box#1}
281 \dp#1\zeropoint}
282
283
284
285
286
287
288
289
290
291
292
293
294\newconditional\c_page_areas_enabled
295\newbox \b_page_areas_registered
296
297\permanent\protected\def\enabletextarearegistration
298 {\global\c_page_areas_enabled\conditionaltrue}
299
300\def\page_areas_registered_box
301 {\ifconditional\c_page_areas_enabled
302 \expandafter\page_areas_registered_box_indeed
303 \else
304 \expandafter\page_areas_registered_box_forget
305 \fi}
306
307\def\page_areas_registered_box_forget#1#2#3
308 {\box#3}
309
310\def\page_areas_registered_box_indeed#1#2#3
311 {\anch_mark_flow_box{#3}}
312
313\def\page_areas_register_boxed#1
314 {\begingroup
315 \setbox\scratchbox\vpack{#1}
316 \wd\scratchbox\makeupwidth
317 \vpack{\page_areas_registered_box00\scratchbox}
318 \endgroup}
319
320\def\page_areas_register_direct#1#2
321 {\scratchdepth\dp#2
322 \dp#2\strutdepth
323 \anch_mark_flow_only{#2}
324 \dp#2\scratchdepth
325 #1#2}
326
327\protect \endinput
328 |