1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18\writestatus{loading}{ConTeXt Page Macros Page Selection}
19
20\unprotect
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\installcorenamespace{withpages}
52
53\installsetuponlycommandhandler \??withpages {withpages}
54
55
56\newcount\c_page_selectors_n
57
58\unexpanded\def\insertpages
59 {\dotripleempty\page_selectors_insert}
60
61\def\page_selectors_insert[#filename][#emptylist][#settings]
62 {\doifelseassignment{#emptylist}
63 {\page_selectors_insert_indeed[#filename][][#emptylist]}
64 {\page_selectors_insert_indeed[#filename][#emptylist][#settings]}}
65
66\def\page_selectors_insert_indeed[#filename][#emptylist][#settings]
67 {\bgroup
68 \dontcomplain
69 \getfiguredimensions[#filename]
70 \setupcurrentwithpages
71 [\c!width=\zeropoint,
72 \c!n=\noffigurepages,
73 \c!category=,
74 #settings]
75 \global\c_page_selectors_n\directwithpagesparameter\c!n\relax
76 \scratchwidth\directwithpagesparameter\c!width\relax
77 \doifinset0{#emptylist}
78 {\emptyhbox\page}
79 \dorecurse\c_page_selectors_n
80 {\page_selectors_filter_a_page{#filename}\recurselevel
81 \doifinset\recurselevel{#emptylist}
82 {\emptyhbox\page}}
83 \egroup}
84
85\unexpanded\def\filterpages
86 {\dotripleempty\page_selectors_filter}
87
88\def\page_selectors_filter[#filename][#selection][#settings]
89 {\bgroup
90 \dontcomplain
91 \getfiguredimensions[#filename]
92 \setupcurrentwithpages
93 [\c!width=\zeropoint,
94 \c!n=\noffigurepages,
95 \c!category=,
96 #settings]
97 \global\c_page_selectors_n\directwithpagesparameter\c!n\relax
98 \scratchwidth\directwithpagesparameter\c!width\relax
99 \edef\p_selection{#selection}
100 \ifx\p_selection\v!even
101 \dorecurse\c_page_selectors_n
102 {\ifodd\recurselevel\else
103 \page_selectors_filter_a_page{#filename}\recurselevel
104 \fi}
105 \else\ifx\p_selection\v!odd
106 \dorecurse\c_page_selectors_n
107 {\ifodd\recurselevel\relax
108 \page_selectors_filter_a_page{#filename}\recurselevel
109 \fi}
110 \else
111 \def\page_selectors_filter_step_indeed#page
112 {\ifnum#page>\c_page_selectors_n\else
113 \page_selectors_filter_a_page{#filename}{#page}
114 \fi}
115 \def\page_selectors_filter_step#step
116 {\dowithrange{#step}\page_selectors_filter_step_indeed}
117 \processcommacommand[\p_selection]\page_selectors_filter_step
118 \fi\fi
119 \egroup}
120
121\def\page_selectors_filter_a_page#filename#page
122 {\hpack to \textwidth
123 {\ifdim\scratchwidth>\zeropoint
124 \rightorleftpageaction{\scratchwidth\zeropoint}{\hfill}
125 \fi
126 \setbox\scratchbox\hpack
127 {\hskip\scratchwidth
128 \edef\p_category{\directwithpagesparameter\c!category}
129 \ifx\p_category\empty
130 \externalfigure[#filename][\c!page=#page,\c!height=\textheight]
131 \else
132 \externalfigure[#filename][\p_category][\c!page=#page]
133 \fi
134 \hss}
135 \wd\scratchbox\zeropoint
136 \box\scratchbox}
137 \page}
138
139\unexpanded\def\copypages
140 {\dotripleempty\page_selectors_copy}
141
142\def\page_selectors_copy[#filename][#settings][#figuresettings]
143 {\bgroup
144 \getfiguredimensions[#filename]
145 \setupcurrentwithpages
146 [\c!marking=\v!off,
147 \c!offset=\zeropoint,
148 \c!n=\noffigurepages,
149 \c!category=,
150 #settings]
151 \global\c_page_selectors_n\directwithpagesparameter\c!n\relax
152 \scratchoffset\directwithpagesparameter\c!offset\relax
153 \dorecurse\c_page_selectors_n
154 {\vbox to \textheight
155 {\hsize\textwidth
156 \centeredbox
157 {\doifelse{\directwithpagesparameter\c!marking}\v!on\cuthbox\hpack
158 {\ifdim\scratchoffset>\zeropoint\relax
159 \advance\vsize 2\scratchoffset
160 \advance\hsize 2\scratchoffset
161 \externalfigure[#filename][\c!page=\recurselevel,#figuresettings,\c!scale=,\c!factor=\v!max,\c!offset=\v!overlay]
162 \else
163 \externalfigure[#filename][\c!page=\recurselevel,#figuresettings,\c!offset=\v!overlay]
164 \fi}}}
165 \page}
166 \egroup}
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\installcorenamespace{combinepagesalternative}
195
196\unexpanded\def\combinepages
197 {\dodoubleempty\page_selectors_combine}
198
199\def\page_selectors_combine[#filename][#settings]
200 {\bgroup
201 \dontcomplain
202 \getfiguredimensions[#filename]
203 \setupcurrentwithpages
204 [\c!alternative=\v!a,
205 \c!n=\noffigurepages,\c!nx=\plustwo,\c!ny=\plustwo,
206 \c!start=\plusone,\c!stop=\maxcard,
207 \c!distance=\bodyfontsize,
208 \c!bottom=\vfill,\c!top=\vss,\c!left=\hss,\c!right=\hss,
209 \c!before=\page,\c!after=\page,\c!inbetween=\blank,
210 \c!frame=,\c!background=,\c!backgroundcolor=,
211 \c!name={#filename},
212 \c!category=,
213 #settings]
214 \global\c_page_selectors_n\directwithpagesparameter\c!n\relax
215 \directwithpagesparameter\c!before
216 \scratchnx\directwithpagesparameter\c!nx
217 \scratchny\directwithpagesparameter\c!ny
218 \scratchdistance\directwithpagesparameter\c!distance\relax
219 \scratchwidth\dimexpr(\textwidth\scratchnx\scratchdistance\scratchdistance)\scratchnx\relax
220 \scratchheight\dimexpr(\textheight\scratchny\scratchdistance\scratchdistance)\scratchny\relax
221 \expandnamespaceparameter\??combinepagesalternative\directwithpagesparameter\c!alternative\v!b
222 \directwithpagesparameter\c!after
223 \egroup}
224
225\setvalue{\??combinepagesalternative\v!a}
226 {\global\combinedpagescounter\directwithpagesparameter\c!start\relax
227 \doloop
228 {\vbox to \textheight
229 {\dorecurse\scratchny
230 {\hbox to \textwidth
231 {\dorecurse\scratchnx
232 {\vbox to \scratchheight
233 {\hsize\scratchwidth
234 \vsize\scratchheight
235 \directwithpagesparameter\c!top
236 \hbox to \hsize
237 {\directwithpagesparameter\c!left
238 \ifnum\combinedpagescounter>\directwithpagesparameter\c!stop\relax
239 \global\c_page_selectors_n\zerocount
240 \else\ifnum\combinedpagescounter>\c_page_selectors_n \else
241 \externalfigure
242 [\directwithpagesparameter\c!name]
243 [\c!object=\v!no,
244 \c!page=\number\combinedpagescounter,
245 \c!factor=\v!max,
246 \c!background=\directwithpagesparameter\c!background,
247 \c!backgroundcolor=\directwithpagesparameter\c!backgroundcolor,
248 \c!frame=\directwithpagesparameter\c!frame]
249 \fi\fi
250 \directwithpagesparameter\c!right}
251 \directwithpagesparameter\c!bottom}
252 \global\advance\combinedpagescounter\plusone
253 \hfil}
254 \hfilneg}
255 \vfil}
256 \vfilneg}
257 \page
258 \ifnum\combinedpagescounter>\c_page_selectors_n
259 \exitloop
260 \fi}}
261
262\setvalue{\??combinepagesalternative\v!c}
263 {\global\combinedpagescounter\directwithpagesparameter\c!start\relax
264 \doloop
265 {\vbox to \textheight
266 {\hbox to \textwidth
267 {\dorecurse\scratchnx
268 {\directwithpagesparameter\c!left
269 \vbox to \textheight
270 {\hsize\scratchwidth
271 \dorecurse\scratchny
272 {\directwithpagesparameter\c!top
273 \hbox to \hsize
274 {\vbox to \scratchheight
275 {\hsize\scratchwidth
276 \vsize\scratchheight
277 \ifnum\combinedpagescounter>\directwithpagesparameter\c!stop\relax
278 \global\c_page_selectors_n\zerocount
279 \else\ifnum\combinedpagescounter>\c_page_selectors_n \else
280 \externalfigure
281 [\directwithpagesparameter\c!name]
282 [\c!object=\v!no,
283 \c!page=\number\combinedpagescounter,
284 \c!factor=\v!max,
285 \c!background=\directwithpagesparameter\c!background,
286 \c!backgroundcolor=\directwithpagesparameter\c!backgroundcolor,
287 \c!frame=\directwithpagesparameter\c!frame]
288 \fi\fi}}
289 \global\advance\combinedpagescounter\plusone
290 \directwithpagesparameter\c!bottom}}
291 \hfil}
292 \hfilneg}}
293 \page
294 \ifnum\combinedpagescounter>\c_page_selectors_n
295 \exitloop
296 \fi}}
297
298\expandafter\let\csname\??combinepagesalternative\v!horizontal\expandafter\endcsname\csname\??combinepagesalternative\v!a\endcsname
299\expandafter\let\csname\??combinepagesalternative\v!vertical \expandafter\endcsname\csname\??combinepagesalternative\v!c\endcsname
300
301\setvalue{\??combinepagesalternative\v!b}
302 {\global\combinedpagescounter\directwithpagesparameter\c!start\relax
303 \doloop
304 {\startbaselinecorrection
305 \hbox to \textwidth
306 {\dorecurse\scratchnx
307 {\global\advance\combinedpagescounter\plusone
308 \ifnum\combinedpagescounter>\c_page_selectors_n \else
309 \normalexpanded{\externalfigure
310 [\directwithpagesparameter\c!name]
311 [\c!page=\number\combinedpagescounter,
312 \c!width=\the\scratchwidth,
313 \c!background=\directwithpagesparameter\c!background,
314 \c!backgroundcolor=\directwithpagesparameter\c!backgroundcolor,
315 \c!frame=\directwithpagesparameter\c!frame]}
316 \hfill
317 \fi}
318 \hfillneg}
319 \stopbaselinecorrection
320 \ifnum\combinedpagescounter<\c_page_selectors_n\relax
321 \directwithpagesparameter\c!inbetween
322 \else
323 \exitloop
324 \fi}}
325
326
327
328\unexpanded\def\slicepages
329 {\dotripleempty\page_selectors_slice}
330
331\def\page_selectors_slice[#filename][#oddsettings][#evensettings]
332 {\ifthirdargument
333 \page_selectors_slice_indeed[#filename][#oddsettings][#evensettings]
334 \else
335 \page_selectors_slice_indeed[#filename][#oddsettings][#oddsettings]
336 \fi}
337
338\let\slicedpagenumber\!!zerocount
339\let\slicedpagestepx \!!zerocount
340\let\slicedpagestepy \!!zerocount
341
342\def\page_selectors_slice_indeed[#filename][#oddsettings][#evensettings]
343 {\bgroup
344 \dontcomplain
345 \glet\slicedpagenumber\!!zerocount
346 \getfiguredimensions[#filename]
347 \setupcurrentwithpages
348 [\c!offset=\zeropoint,
349 \c!hoffset=\zeropoint,
350 \c!voffset=\zeropoint,
351 \c!width=\figurewidth,
352 \c!height=\figureheight,
353 \c!n=\noffigurepages,
354 \c!category=,
355 #oddsettings]
356 \global\c_page_selectors_n\directwithpagesparameter\c!n\relax
357 \ifnum\c_page_selectors_n>\zerocount
358 \definepapersize
359 [\s!dummy][\c!height=\directwithpagesparameter\c!height,\c!width=\directwithpagesparameter\c!width]
360 \setuppapersize
361 [\s!dummy][\s!dummy]
362 \setuplayout
363 [\c!backspace=\zeropoint,\c!topspace=\zeropoint,
364 \c!height=\v!middle,\c!width=\v!middle,
365 \c!textdistance=\zeropoint,
366 \c!header=\zeropoint,\c!footer=\zeropoint]
367 \fi
368 \dorecurse\noffigurepages
369 {\glet\slicedpagenumber\recurselevel
370 \ifnum\c_page_selectors_n>\plusone
371 \dorecurse\c_page_selectors_n
372 {\let\slicedpagestepx\recurselevel
373 \dorecurse\c_page_selectors_n
374 {\let\slicedpagestepy\recurselevel
375 \clip
376 [\c!nx=\c_page_selectors_n,\c!ny=\c_page_selectors_n,\c!x=\slicedpagestepx,\c!y=\slicedpagestepy]
377 {\scale
378 [\c!scale=\number\c_page_selectors_n000]
379 {\externalfigure[#filename][\c!page=\slicedpagenumber]}}
380 \page}}
381 \else
382 \ifodd\slicedpagenumber\relax
383 \setupcurrentwithpages[#oddsettings]
384 \else
385 \setupcurrentwithpages[#evensettings]
386 \fi
387 \hskip\directwithpagesparameter\c!offset\relax
388 \clip
389 [\c!hoffset=\directwithpagesparameter\c!hoffset,\c!voffset=\directwithpagesparameter\c!voffset,
390 \c!height=\directwithpagesparameter\c!height,\c!width=\directwithpagesparameter\c!width]
391 {\externalfigure[#filename][\c!page=\slicedpagenumber]}
392 \page
393 \fi}
394 \egroup}
395
396
397
398\unexpanded\def\trimpages[#1]
399 {\begingroup
400 \getdummyparameters
401 [\c!file=dummy,
402 \c!hoffset=\zeropoint,
403 \c!voffset=\zeropoint,
404 \c!width=17cm,
405 \c!height=24cm,
406 \c!x=\zeropoint,
407 \c!y=\zeropoint,
408 #1]
409 \getfiguredimensions
410 [\dummyparameter\c!file]
411 [\c!object=\v!no]
412 \dorecurse\noffigurepages
413 {\scale
414 [\c!width=\paperwidth,
415 \c!height=\paperheight]
416 {\offset
417 [\c!x=\dummyparameter\c!x,
418 \c!y=\dummyparameter\c!y]
419 {\clip
420 [\c!hoffset=\dummyparameter\c!hoffset,
421 \c!voffset=\dummyparameter\c!voffset,
422 \c!width=\dummyparameter\c!width,
423 \c!height=\dummyparameter\c!height]
424 {
425 \setbox\nextbox\hbox
426 {\externalfigure[\dummyparameter\c!file][\c!page=##1]}
427 \ifdim\wd\nextbox>\ht\nextbox
428 \rotate[\c!rotation=90]{\box\nextbox}
429 \else
430 \box\nextbox
431 \fi}}}}
432 \endgroup}
433
434\protect \endinput
435 |