diff options
Diffstat (limited to 'tex/context/base/page-sel.mkiv')
-rw-r--r-- | tex/context/base/page-sel.mkiv | 347 |
1 files changed, 347 insertions, 0 deletions
diff --git a/tex/context/base/page-sel.mkiv b/tex/context/base/page-sel.mkiv new file mode 100644 index 000000000..9192d1430 --- /dev/null +++ b/tex/context/base/page-sel.mkiv @@ -0,0 +1,347 @@ +%D \module +%D [ file=page-sel, % moved from page-imp +%D version=1998.01.15, +%D title=\CONTEXT\ Page Macros, +%D subtitle=Page Selection, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright=PRAGMA] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +%D This will become runtime loaded code. + +\writestatus{loading}{ConTeXt Page Macros / Page Selection} + +\unprotect + +%D One can (mis)use this mechanism, in close cooperation +%D with \PDFTEX\ to arrange pages of already produced files. +%D +%D \starttyping +%D \insertpages[file.pdf][1,3][n=30,width=18cm] +%D \stoptyping +%D +%D The pages are inserted in the text area, and even pages +%D are repositioned according to the width. In this example +%D empty pages are added after page 1 and 3. +%D +%D Selecting pages can be accomplished by: +%D +%D \starttyping +%D \filterpages[file.pdf][1,3,5][n=30,width=18cm] +%D \stoptyping +%D +%D One may pass \type {odd} or \type {even} instead of a +%D comma separated list. A third alternative is: +%D +%D \starttyping +%D \copypages[file.pdf][n=30,scale=950] +%D \stoptyping +%D +%D This macros inserts the page, according to the settings +%D provided. + +\def\insertpages + {\dotripleempty\doinsertpages} + +\def\doinsertpages[#1][#2][#3]% + {\doifassignmentelse{#2} + {\dodoinsertpages[#1][][#2]} + {\dodoinsertpages[#1][#2][#3]}} + +\def\dodoinsertpages[#1][#2][#3]% + {\bgroup + \dontcomplain + \getfiguredimensions[#1]% + \getparameters[\??ip][\c!n=\noffigurepages,\c!width=\!!zeropoint,#3]% + \doifinset0{#2}{\emptyhbox\page}% + \dorecurse\@@ipn + {\dofilterpage{#1}\recurselevel + \doifinset\recurselevel{#2}{\emptyhbox\page}}% + \egroup} + +\def\filterpages + {\dotripleempty\dofilterpages} + +\def\dofilterpages[#1][#2][#3]% % \noffigurepages not yet supported + {\bgroup + \dontcomplain + \getfiguredimensions[#1]% + \getparameters[\??ip][\c!n=\noffigurepages,\c!width=\!!zeropoint,#3]% + \doifelse{#2}\v!even + {\dorecurse\@@ipn + {\ifodd\recurselevel\relax\else\dofilterpage{#1}\recurselevel\fi}} + {\doifelse{#2}\v!odd + {\dorecurse\@@ipn + {\ifodd\recurselevel\relax\dofilterpage{#1}\recurselevel\fi}} + {\def\dodocommand##1{\ifnum##1>\@@ipn\else\dofilterpage{#1}{##1}\fi}% + \def\docommand ##1{\dowithrange{##1}\dodocommand}% + \processcommalist[#2]\docommand}}% + \egroup} + +\def\dofilterpage#1#2% + {\hbox to \textwidth + {\ifdoublesided\ifdim\@@ipwidth>\zeropoint\relax\ifodd\realpageno\else + \hfill + \def\dowithfigure{\hskip-\@@ipwidth}% + \fi\fi\fi + \setbox0\hbox + {\externalfigure[#1][\c!page=#2,\c!height=\textheight]}% + \wd0\zeropoint + \box0} + \page} + +\def\copypages + {\dodoubleempty\docopypages} + +\def\docopypages[#1][#2]% + {\bgroup + \getfiguredimensions[#1]% + \getparameters[\??ip] + [\c!n=\noffigurepages, + \c!marking=\v!off, + \c!scale=\!!thousand, + \c!offset=\!!zeropoint, + #2]% + \dorecurse\@@ipn + {\vbox to \textheight + {\hsize\textwidth + \scratchdimen\@@ipoffset + \centeredbox + {\doifelse\@@ipmarking\v!on\cuthbox\hbox + {\ifdim\scratchdimen>\zeropoint\relax + \advance\vsize -2\scratchdimen + \advance\hsize -2\scratchdimen + \externalfigure[#1][\c!page=\recurselevel,#2,\c!scale=,\c!factor=\v!max,\c!offset=\v!overlay]% + \else + \externalfigure[#1][\c!page=\recurselevel,#2,\c!offset=\v!overlay]% + \fi}}} + \page} + \egroup} + +%D \macros +%D {combinepages} +%D +%D Yet another way of postprocessing is handles by \type +%D {\combinepages}. This macro builds a matrix of pages from a +%D file, for example: +%D +%D \starttyping +%D \setuppapersize +%D [A4][A4] % or [A4,landscape][A4,landscape] +%D +%D \setuplayout +%D [header=0pt,footer=1cm, +%D backspace=1cm,topspace=1cm, +%D width=middle,height=middle] +%D +%D \setupfootertexts +%D [presentation---\currentdate\space---\space\pagenumber] +%D +%D \starttext +%D \combinepages[slides][nx=2,ny=3,frame=on] +%D \stoptext +%D \stoptyping +%D +%D One can influence the way the pages are combined. (This +%D will be explained some time.) + +\def\combinepages + {\dodoubleempty\docombinepages} + +\def\docombinepages[#1][#2]% a=perpag b=free + {\bgroup + \dontcomplain + \getfiguredimensions[#1]% + \getparameters + [\??ip] + [\c!alternative=\v!a, + \c!n=\noffigurepages,\c!nx=2,\c!ny=2,\c!start=1,\c!stop=\!!maxcard, + \c!distance=\bodyfontsize, + \c!bottom=\vfill,\c!top=\vss, + \c!left=\hss,\c!right=\hss, + \c!before=\page,\c!after=\page,\c!inbetween=\blank, + \c!frame=,\c!background=,\c!backgroundcolor=, + #2]% + \def\@@ipname{#1}% + \@@ipbefore + \expandcheckedcsname{\??ip::\c!alternative:}\@@ipalternative\v!b + \@@ipafter + \egroup} + +\setvalue{\??ip::\c!alternative:\v!a}% + {\global\combinedpagescounter\@@ipstart + \doloop + {\vbox to \textheight + {\hsize\textwidth % ? ? + \scratchdimen\@@ipdistance + \!!widtha \dimexpr(\hsize-\@@ipnx\scratchdimen+\scratchdimen)/\@@ipnx\relax + \!!heighta\dimexpr(\vsize-\@@ipny\scratchdimen+\scratchdimen)/\@@ipny\relax + \dorecurse\@@ipny + {\hbox to \hsize + {\dorecurse\@@ipnx + {\vbox to \!!heighta + {\hsize\!!widtha + \vsize\!!heighta + \@@iptop + \hbox to \hsize + {\@@ipleft + \ifnum\combinedpagescounter>\@@ipstop\relax + \globallet\@@ipn\!!zerocount + \else\ifnum\combinedpagescounter>\@@ipn \else + \externalfigure[\@@ipname] + [\c!object=\v!no, + \c!page=\number\combinedpagescounter, + \c!factor=\v!max, + \c!background=\@@ipbackground, + \c!backgroundcolor=\@@ipbackgroundcolor, + \c!frame=\@@ipframe]% + \fi\fi + \@@ipright} + \@@ipbottom}% + \global\advance\combinedpagescounter\plusone + \hfil}% + \hfilneg} + \vfil}% + \vfilneg}% + \page + \ifnum\combinedpagescounter>\@@ipn \exitloop\fi}} + +\setvalue{\??ip::\c!alternative:\v!c}% + {\global\combinedpagescounter\@@ipstart + \doloop + {\vbox to \textheight + {\hsize\textwidth % ? ? + \scratchdimen\@@ipdistance + \!!widtha \dimexpr(\hsize-\@@ipnx\scratchdimen+\scratchdimen)/\@@ipnx\relax + \!!heighta\dimexpr(\vsize-\@@ipny\scratchdimen+\scratchdimen)/\@@ipny\relax + \hbox to \hsize + {\dorecurse\@@ipnx + {\@@ipleft + \vbox to \textheight + {\hsize\!!widtha + {\dorecurse\@@ipny + {\@@iptop + \hbox to \hsize + {\vbox to \!!heighta + {\hsize\!!widtha + \vsize\!!heighta + \ifnum\combinedpagescounter>\@@ipstop\relax + \globallet\@@ipn\!!zerocount + \else\ifnum\combinedpagescounter>\@@ipn \else + \externalfigure[\@@ipname] + [\c!object=\v!no, + \c!page=\number\combinedpagescounter, + \c!factor=\v!max, + \c!background=\@@ipbackground, + \c!backgroundcolor=\@@ipbackgroundcolor, + \c!frame=\@@ipframe]% + \fi\fi}} + \global\advance\combinedpagescounter\plusone + \@@ipbottom}% + \vfil}% + \vfilneg} + \hfil}% + \hfilneg}} + \page + \ifnum\combinedpagescounter>\@@ipn \exitloop\fi}} + +\setvalue{\??ip::\c!alternative:\v!horizontal}{\getvalue{\??ip::\c!alternative:\v!a}} +\setvalue{\??ip::\c!alternative:\v!vertical }{\getvalue{\??ip::\c!alternative:\v!c}} + +\setvalue{\??ip::\c!alternative:\v!b}% + {\global\combinedpagescounter\@@ipstart + \doloop + {\startbaselinecorrection + \scratchdimen\@@ipdistance + \!!widtha\dimexpr(\hsize-\@@ipnx\scratchdimen+\scratchdimen)/\@@ipnx\relax + \hbox to \hsize + {\dorecurse\@@ipnx + {\global\advance\combinedpagescounter\plusone + \ifnum\combinedpagescounter>\@@ipn \else + \normalexpanded{\noexpand\externalfigure[\@@ipname] + [\c!page=\number\combinedpagescounter, + \c!width=\the\!!widtha,% todo \freezedimenmacro + \c!background=\@@ipbackground, + \c!backgroundcolor=\@@ipbackgroundcolor, + \c!frame=\@@ipframe]}% + \hfill + \fi}\hfillneg}% + \stopbaselinecorrection + \ifnum\combinedpagescounter<\@@ipn\relax + \@@ipinbetween + \else + \exitloop + \fi}} + +% This macro cuts a page into n parts that can be pasted +% together. + +\def\slicepages + {\dotripleempty\doslicepages} + +\def\doslicepages[#1][#2][#3]% + {\ifthirdargument + \dodoslicepages[#1][#2][#3]% + \else + \dodoslicepages[#1][#2][#2]% + \fi} + +\newcounter\slicedpagenumber + +\def\dodoslicepages[#1][#2][#3]% + {\bgroup + \dontcomplain + \globallet\slicedpagenumber\!!zerocount + \getfiguredimensions[#1] + \getparameters + [\??ip] + [\c!n=1, + \c!offset=\!!zeropoint, + \c!hoffset=\!!zeropoint,\c!voffset=\!!zeropoint, + \c!width=\figurewidth,\c!height=\figureheight,#2] + \ifnum\@@ipn>\zerocount + \definepapersize + [\s!dummy][\c!height=\@@ipheight,\c!width=\@@ipwidth] + \setuppapersize + [\s!dummy][\s!dummy] + \setuplayout + [\c!backspace=\!!zeropoint,\c!topspace=\!!zeropoint, + \c!height=\v!middle,\c!width=\v!middle, + \c!textdistance=\!!zeropoint, + \c!header=\!!zeropoint,\c!footer=\!!zeropoint] + \fi + \dorecurse\noffigurepages + {\global\let\slicedpagenumber\recurselevel + \ifnum\@@ipn>\plusone + \dorecurse\@@ipn + {\let\xslice\recurselevel + \dorecurse\@@ipn + {\let\yslice\recurselevel + \clip + [\c!nx=\@@ipn,\c!ny=\@@ipn,\c!x=\xslice,\c!y=\yslice] + {\scale + [\c!scale=\@@ipn000] + {\externalfigure[#1][\c!page=\slicedpagenumber]}} + \page}} + \else + \ifodd\slicedpagenumber\relax + \getparameters[\??ip][#2] + \else + \getparameters[\??ip][#3] + \fi + \hskip\@@ipoffset + \clip + [\c!hoffset=\@@iphoffset,\c!voffset=\@@ipvoffset, + \c!height=\@@ipheight,\c!width=\@@ipwidth] + {\externalfigure[#1][\c!page=\slicedpagenumber]} + \page + \fi} + \egroup} + +% \starttext \slicepages[slice1.pdf][n=3] \stoptext + +\protect \endinput |