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