diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/page-sel.mkvi')
-rw-r--r-- | Master/texmf-dist/tex/context/base/page-sel.mkvi | 369 |
1 files changed, 369 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/page-sel.mkvi b/Master/texmf-dist/tex/context/base/page-sel.mkvi new file mode 100644 index 00000000000..cb9bcb509eb --- /dev/null +++ b/Master/texmf-dist/tex/context/base/page-sel.mkvi @@ -0,0 +1,369 @@ +%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 ADE \& \CONTEXT\ Development Team}] +%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 code relates to old texexec features and one can wonder if it needs +%D to be in the core. So, this could become runtime loaded code. Some of +%D the alternatives need checking. + +\writestatus{loading}{ConTeXt Page Macros / Page Selection} + +\unprotect + +%D One can (mis)use this mechanism to (re)arrange pages of already produced +%D 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 are repositioned +%D according to the width. In this example empty pages are added after page +%D 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 comma separated list. A +%D 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 provided. + +\installcorenamespace{withpages} + +\installsetuponlycommandhandler \??withpages {withpages} +% \installdirectcommandhandler \??withpages {withpages} + +\newcount\c_page_selectors_n + +\unexpanded\def\insertpages + {\dotripleempty\page_selectors_insert} + +\def\page_selectors_insert[#filename][#emptylist][#settings]% + {\doifassignmentelse{#emptylist} + {\page_selectors_insert_indeed[#filename][][#emptylist]} + {\page_selectors_insert_indeed[#filename][#emptylist][#settings]}} + +\def\page_selectors_insert_indeed[#filename][#emptylist][#settings]% + {\bgroup + \dontcomplain + \getfiguredimensions[#filename]% + \setupcurrentwithpages[\c!width=\zeropoint,\c!n=\noffigurepages,#settings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax + \scratchwidth\directwithpagesparameter\c!width\relax + \doifinset0{#emptylist} + {\emptyhbox\page}% + \dorecurse\c_page_selectors_n + {\page_selectors_filter_a_page{#filename}\recurselevel + \doifinset\recurselevel{#emptylist} + {\emptyhbox\page}}% + \egroup} + +\unexpanded\def\filterpages + {\dotripleempty\page_selectors_filter} + +\def\page_selectors_filter[#filename][#selection][#settings]% % \noffigurepages not yet supported + {\bgroup + \dontcomplain + \getfiguredimensions[#filename]% + \setupcurrentwithpages[\c!width=\zeropoint,\c!n=\noffigurepages,#settings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax + \scratchwidth\directwithpagesparameter\c!width\relax + \edef\p_selection{#selection}% + \ifx\p_selection\v!even + \dorecurse\c_page_selectors_n + {\ifodd\recurselevel\else + \page_selectors_filter_a_page{#filename}\recurselevel + \fi}% + \else\ifx\p_selection\v!odd + \dorecurse\c_page_selectors_n + {\ifodd\recurselevel\relax + \page_selectors_filter_a_page{#filename}\recurselevel + \fi}% + \else + \def\page_selectors_filter_step_indeed#page% + {\ifnum#page>\c_page_selectors_n\else + \page_selectors_filter_a_page{#filename}{#page}% + \fi}% + \def\page_selectors_filter_step#step% + {\dowithrange{#step}\page_selectors_filter_step_indeed}% + \processcommacommand[\p_selection]\page_selectors_filter_step + \fi\fi + \egroup} + +\def\page_selectors_filter_a_page#filename#page% + {\hbox to \textwidth + {\ifdim\scratchwidth>\zeropoint + \rightorleftpageaction{\scratchwidth\zeropoint}{\hfill}% + \fi + \setbox\scratchbox\hbox + {\hskip-\scratchwidth + \externalfigure[#filename][\c!page=#page,\c!height=\textheight]\hss}% + \wd\scratchbox\zeropoint + \box\scratchbox} + \page} + +\unexpanded\def\copypages + {\dotripleempty\page_selectors_copy} + +\def\page_selectors_copy[#filename][#settings][#figuresettings]% + {\bgroup + \getfiguredimensions[#filename]% + \setupcurrentwithpages[\c!marking=\v!off,\c!offset=\zeropoint,\c!n=\noffigurepages,#settings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax + \scratchoffset\directwithpagesparameter\c!offset\relax + \dorecurse\c_page_selectors_n + {\vbox to \textheight + {\hsize\textwidth + \centeredbox + {\doifelse{\directwithpagesparameter\c!marking}\v!on\cuthbox\hbox % only place where cuthbox is used + {\ifdim\scratchoffset>\zeropoint\relax + \advance\vsize -2\scratchoffset + \advance\hsize -2\scratchoffset + \externalfigure[#filename][\c!page=\recurselevel,#figuresettings,\c!scale=,\c!factor=\v!max,\c!offset=\v!overlay]% + \else + \externalfigure[#filename][\c!page=\recurselevel,#figuresettings,\c!offset=\v!overlay]% + \fi}}} + \page} + \egroup} + +%D \macros +%D {combinepages} +%D +%D Yet another way of postprocessing is handles by \type {\combinepages}. This macro +%D builds a matrix of pages from a 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 will be explained some +%D time.) + +\installcorenamespace{combinepagesalternative} + +\unexpanded\def\combinepages + {\dodoubleempty\page_selectors_combine} + +\def\page_selectors_combine[#filename][#settings]% a=perpag b=free + {\bgroup + \dontcomplain + \getfiguredimensions[#filename]% + \setupcurrentwithpages + [\c!alternative=\v!a, + \c!n=\noffigurepages,\c!nx=\plustwo,\c!ny=\plustwo, + \c!start=\plusone,\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=, + \c!name={#filename}, + #settings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax + \directwithpagesparameter\c!before + \scratchnx\directwithpagesparameter\c!nx + \scratchny\directwithpagesparameter\c!ny + \scratchdistance\directwithpagesparameter\c!distance\relax + \scratchwidth\dimexpr(\textwidth-\scratchnx\scratchdistance+\scratchdistance)/\scratchnx\relax + \scratchheight\dimexpr(\textheight-\scratchny\scratchdistance+\scratchdistance)/\scratchny\relax + \expandnamespaceparameter\??combinepagesalternative\directwithpagesparameter\c!alternative\v!b + \directwithpagesparameter\c!after + \egroup} + +\setvalue{\??combinepagesalternative\v!a}% + {\global\combinedpagescounter\directwithpagesparameter\c!start\relax + \doloop + {\vbox to \textheight + {\dorecurse\scratchny + {\hbox to \textwidth + {\dorecurse\scratchnx + {\vbox to \scratchheight + {\hsize\scratchwidth + \vsize\scratchheight + \directwithpagesparameter\c!top + \hbox to \hsize + {\directwithpagesparameter\c!left + \ifnum\combinedpagescounter>\directwithpagesparameter\c!stop\relax + \global\c_page_selectors_n\zerocount + \else\ifnum\combinedpagescounter>\c_page_selectors_n \else + \externalfigure + [\directwithpagesparameter\c!name] + [\c!object=\v!no, + \c!page=\number\combinedpagescounter, + \c!factor=\v!max, + \c!background=\directwithpagesparameter\c!background, + \c!backgroundcolor=\directwithpagesparameter\c!backgroundcolor, + \c!frame=\directwithpagesparameter\c!frame]% + \fi\fi + \directwithpagesparameter\c!right} + \directwithpagesparameter\c!bottom}% + \global\advance\combinedpagescounter\plusone + \hfil}% + \hfilneg} + \vfil}% + \vfilneg}% + \page + \ifnum\combinedpagescounter>\c_page_selectors_n + \exitloop + \fi}} + +\setvalue{\??combinepagesalternative\v!c}% + {\global\combinedpagescounter\directwithpagesparameter\c!start\relax + \doloop + {\vbox to \textheight + {\hbox to \textwidth + {\dorecurse\scratchnx + {\directwithpagesparameter\c!left + \vbox to \textheight + {\hsize\scratchwidth + \dorecurse\scratchny + {\directwithpagesparameter\c!top + \hbox to \hsize + {\vbox to \scratchheight + {\hsize\scratchwidth + \vsize\scratchheight + \ifnum\combinedpagescounter>\directwithpagesparameter\c!stop\relax + \global\c_page_selectors_n\zerocount + \else\ifnum\combinedpagescounter>\c_page_selectors_n \else + \externalfigure + [\directwithpagesparameter\c!name] + [\c!object=\v!no, + \c!page=\number\combinedpagescounter, + \c!factor=\v!max, + \c!background=\directwithpagesparameter\c!background, + \c!backgroundcolor=\directwithpagesparameter\c!backgroundcolor, + \c!frame=\directwithpagesparameter\c!frame]% + \fi\fi}} + \global\advance\combinedpagescounter\plusone + \directwithpagesparameter\c!bottom}}% + \hfil}% + \hfilneg}}% + \page + \ifnum\combinedpagescounter>\c_page_selectors_n + \exitloop + \fi}} + +\setvalue{\??combinepagesalternative\v!horizontal}{\getvalue{\??combinepagesalternative\v!a}} +\setvalue{\??combinepagesalternative\v!vertical }{\getvalue{\??combinepagesalternative\v!c}} + +\setvalue{\??combinepagesalternative\v!b}% + {\global\combinedpagescounter\directwithpagesparameter\c!start\relax + \doloop + {\startbaselinecorrection + \hbox to \textwidth + {\dorecurse\scratchnx + {\global\advance\combinedpagescounter\plusone + \ifnum\combinedpagescounter>\c_page_selectors_n \else + \normalexpanded{\externalfigure + [\directwithpagesparameter\c!name] + [\c!page=\number\combinedpagescounter, + \c!width=\the\scratchwidth, + \c!background=\directwithpagesparameter\c!background, + \c!backgroundcolor=\directwithpagesparameter\c!backgroundcolor, + \c!frame=\directwithpagesparameter\c!frame]}% + \hfill + \fi}% + \hfillneg}% + \stopbaselinecorrection + \ifnum\combinedpagescounter<\c_page_selectors_n\relax + \directwithpagesparameter\c!inbetween + \else + \exitloop + \fi}} + +% This macro cuts a page into n parts that can be pasted together. + +\unexpanded\def\slicepages + {\dotripleempty\page_selectors_slice} + +\def\page_selectors_slice[#filename][#oddsettings][#evensettings]% + {\ifthirdargument + \page_selectors_slice_indeed[#filename][#oddsettings][#evensettings]% + \else + \page_selectors_slice_indeed[#filename][#oddsettings][#oddsettings]% + \fi} + +\let\slicedpagenumber\!!zerocount +\let\slicedpagestepx \!!zerocount +\let\slicedpagestepy \!!zerocount + +\def\page_selectors_slice_indeed[#filename][#oddsettings][#evensettings]% + {\bgroup + \dontcomplain + \global\let\slicedpagenumber\!!zerocount + \getfiguredimensions[#filename]% + \setupcurrentwithpages + [\c!offset=\zeropoint,\c!hoffset=\zeropoint,\c!voffset=\zeropoint, + \c!width=\figurewidth,\c!height=\figureheight,\c!n=\noffigurepages,#oddsettings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax + \ifnum\c_page_selectors_n>\zerocount + \definepapersize + [\s!dummy][\c!height=\directwithpagesparameter\c!height,\c!width=\directwithpagesparameter\c!width]% + \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\c_page_selectors_n>\plusone + \dorecurse\c_page_selectors_n + {\let\slicedpagestepx\recurselevel + \dorecurse\c_page_selectors_n + {\let\slicedpagestepy\recurselevel + \clip + [\c!nx=\c_page_selectors_n,\c!ny=\c_page_selectors_n,\c!x=\slicedpagestepx,\c!y=\slicedpagestepy] + {\scale + [\c!scale=\number\c_page_selectors_n000] + {\externalfigure[#filename][\c!page=\slicedpagenumber]}}% + \page}}% + \else + \ifodd\slicedpagenumber\relax + \setupcurrentwithpages[#oddsettings]% + \else + \setupcurrentwithpages[#evensettings]% + \fi + \hskip\directwithpagesparameter\c!offset\relax + \clip + [\c!hoffset=\directwithpagesparameter\c!hoffset,\c!voffset=\directwithpagesparameter\c!voffset, + \c!height=\directwithpagesparameter\c!height,\c!width=\directwithpagesparameter\c!width] + {\externalfigure[#filename][\c!page=\slicedpagenumber]}% + \page + \fi} + \egroup} + +% \starttext \slicepages[slice1.pdf][n=3] \stoptext + +\protect \endinput |