summaryrefslogtreecommitdiff
path: root/tex/context/base/page-lay.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/page-lay.mkiv')
-rw-r--r--tex/context/base/page-lay.mkiv1208
1 files changed, 578 insertions, 630 deletions
diff --git a/tex/context/base/page-lay.mkiv b/tex/context/base/page-lay.mkiv
index 66ea7b79a..68337b937 100644
--- a/tex/context/base/page-lay.mkiv
+++ b/tex/context/base/page-lay.mkiv
@@ -24,13 +24,6 @@
\unprotect
-%D First we get rid of the funny \TEX\ offset defaults of one
-%D inch by setting them to zero (actually this is already done
-%D elsewhere but it's good to notice).
-
-\voffset \zeropoint
-\hoffset \zeropoint
-
%D The dimensions related to layout areas are represented by
%D real dimensions.
@@ -75,10 +68,10 @@
%D The next series of dimensions are complemented by left
%D and rights ones.
-\newdimen \margindistance
-\newdimen \edgedistance
-\newdimen \marginwidth
-\newdimen \edgewidth
+\newdimen\margindistance
+\newdimen\edgedistance
+\newdimen\marginwidth
+\newdimen\edgewidth
%D Because a distance does not really makes sense when there
%D is no area, we use a zero distance in case there is no
@@ -86,17 +79,17 @@
%D The horizontal distances are:
-\newdimen \leftedgedistance
-\newdimen \rightedgedistance
-\newdimen \leftmargindistance
-\newdimen \rightmargindistance
+\newdimen\leftedgedistance
+\newdimen\rightedgedistance
+\newdimen\leftmargindistance
+\newdimen\rightmargindistance
%D The vertical distances are:
-\newdimen \topdistance
-\newdimen \headerdistance
-\newdimen \footerdistance
-\newdimen \bottomdistance
+\newdimen\topdistance
+\newdimen\headerdistance
+\newdimen\footerdistance
+\newdimen\bottomdistance
%D We need to calculate the extra distances:
@@ -123,16 +116,15 @@
\appendtoks
\ifx\currentlayout\v!reset
- \let\currentlayout\empty
- \letlayoutparameter\c!state\v!normal % global ?
+ \let\currentlayout\empty
+ \letlayoutparameter\c!state\v!normal % global ?
\fi
\globallet\currentlayout\currentlayout
\to \everysetuplayout
\appendtoks
- \recalculatelayout
- \dochecknextlayout
- \presetcenterpagebox
+ \pages_layouts_synchronize
+ \page_layouts_check_next
\to \everysetuplayout
\def\doiflayoutdefinedelse#1%
@@ -144,7 +136,7 @@
\def\layoutdistance#1#2{\ifdim\zeropoint<#1#2\else\zeropoint\fi}
-\def\setlayoutdimensions
+\def\page_layouts_set_dimensions
{\global\naturalmarginwidth \layoutparameter\c!margin
\global\naturaledgewidth \layoutparameter\c!edge
\global\naturalmargindistance \layoutparameter\c!margindistance
@@ -173,7 +165,7 @@
\global\bottomdistance \layoutdistance\bottomheight \naturalbottomdistance
}
-\def\setlayoutdistances % local in \setreducedvsize
+\def\page_layouts_set_distances % local in \setreducedvsize
{\headerdistance\layoutdistance\headerheight\naturalheaderdistance
\footerdistance\layoutdistance\footerheight\naturalfooterdistance}
@@ -192,7 +184,10 @@
\def\outerspacewidth {\rightorleftpageaction\cutspace\backspace}
\def\innerspacewidth {\rightorleftpageaction\backspace\cutspace}
-\newtoks\extralayoutcalculations \def\calculatelayoutextras{\the\extralayoutcalculations}
+\newtoks\extralayoutcalculations
+
+\def\page_layouts_calculate_extras
+ {\the\extralayoutcalculations}
\newtoks\everyswapmargins % watch the order !
@@ -212,6 +207,9 @@
\swapmacros\innersidetotal \outersidetotal
\to \everyswapmargins
+%D The papersize macros have a long history and we don't want
+%D to change the commands so they keep looking a bit complex.
+
%D \macros
%D {definepapersize}
%D
@@ -221,41 +219,7 @@
%D which case the second argument is an assignment.
%D
%D \showsetup{definepapersize}
-
-\unexpanded\def\definepapersize
- {\dodoubleempty\dodefinepapersize}
-
-\unexpanded\def\definepapersize
- {\dotripleempty\dodefinepapersize}
-
-\def\dodefinepapersize[#1][#2][#3]%
- {\ifsecondargument
- \doifsomething{#1} % to be sure
- {\doifassignmentelse{#2}
- {\getparameters
- [\??pp#1]% geen \c!scale, scheelt hash ruimte
- [\c!width=\@@ppwidth,\c!height=\@@ppheight,\c!offset=\@@ppoffset,#2]}
- {\setvalue{\??pp:1:#1}{#2}%
- \setvalue{\??pp:2:#1}{#3}}}%
- \else
- \getparameters[\??pp][#1]%
- \setuppapersize % hm. this will freeze !
- \fi}
-
-%D For the moment we need to fake this macro.
-
-\ifx\setuppapersize\undefined
- \let\setuppapersize\relax
-\fi
-
-%D We set the defaults to the dimensions of an A4 sheet of
-%D paper.
-
-\definepapersize
- [\c!width=210mm,
- \c!height=297mm,
- \c!offset=\zeropoint]
-
+%D
%D Yet undocumented, let's see if it gets noticed.
%D
%D \starttyping
@@ -276,7 +240,7 @@
%D Page 6. \page
%D \stoptext
%D \stoptyping
-
+%D
%D \macros
%D {setuppaper,setuppapersize}
%D
@@ -288,122 +252,270 @@
%D We keep track of these features with the following
%D variables.
-\newconditional\papermirror \newconditional\printmirror
-\newconstant \paperorientation \newconstant \printorientation
-\newconstant \paperreverse \newconstant \printreverse
-\newconditional\paperlandscape \newconditional\printlandscape
- \newconditional\printnegatecolors
- \newconditional\printdoublesided
+\installcommandhandler \??pp {layouttarget} \??pp % so this is a sort of mix, not really a user command / maybe switch handler
+
+\newconditional\c_page_target_paper_mirror
+\newconstant \c_page_target_paper_orientation
+\newconstant \c_page_target_paper_reverse
+\newconditional\c_page_target_paper_landscape
+\newconditional\c_page_target_paper_negate
+
+\newconditional\c_page_target_print_mirror
+\newconstant \c_page_target_print_orientation
+\newconstant \c_page_target_print_reverse
+\newconditional\c_page_target_print_landscape
+\newconditional\c_page_target_print_negate
+\newconditional\c_page_target_print_doublesided
+
+\let\v_page_target_left_fill \relax
+\let\v_page_target_right_fill \relax
+\let\v_page_target_top_fill \relax
+\let\v_page_target_bottom_fill\relax
+
+\let\papersize \empty
+\let\printpapersize\empty
+
+\def\v_page_target_top {\namedlayouttargetparameter\papersize\c!top }
+\def\v_page_target_bottom {\namedlayouttargetparameter\papersize\c!bottom}
+\def\v_page_target_left {\namedlayouttargetparameter\papersize\c!left }
+\def\v_page_target_right {\namedlayouttargetparameter\papersize\c!right }
+\def\v_page_target_method {\rootlayouttargetparameter \c!method}
+\def\v_page_target_scale {\rootlayouttargetparameter \c!scale }
+\def\v_page_target_nx {\numexpr\rootlayouttargetparameter \c!nx \relax}
+\def\v_page_target_ny {\numexpr\rootlayouttargetparameter \c!ny \relax}
+\def\v_page_target_dx {\dimexpr\rootlayouttargetparameter \c!dx \relax}
+\def\v_page_target_dy {\dimexpr\rootlayouttargetparameter \c!dy \relax}
+\def\v_page_target_width {\dimexpr\rootlayouttargetparameter \c!width \relax}
+\def\v_page_target_height {\dimexpr\rootlayouttargetparameter \c!height \relax}
+\def\v_page_target_topoffset{\dimexpr\rootlayouttargetparameter \c!topoffset\relax}
+\def\v_page_target_backspace{\dimexpr\rootlayouttargetparameter \c!backspace\relax}
+\def\v_page_target_offset {\dimexpr\rootlayouttargetparameter \c!offset \relax}
+
+\def\v_page_target_xy {\numexpr\v_page_target_nx*\v_page_target_ny\relax}
+
+% Normally we will not use this command directly but for now it
+% works out okay. In th efuture we might use more of the related
+% commands.
+
+\setuplayouttarget
+ [% these are rather special
+ \c!nx=1,
+ \c!ny=1,
+ \c!dx=\zeropoint,
+ \c!dy=\zeropoint,
+ \c!topspace=\zeropoint,
+ \c!backspace=\zeropoint,
+ \c!width=\zeropoint,
+ \c!height=\zeropoint,
+ %
+ \c!method=\v!normal,
+ \c!option=\v!max,
+ \c!alternative=\v!normal,
+ %
+ \c!scale=1,
+ \c!offset=\zeropoint,
+ %
+ \c!top=,
+ \c!bottom=,
+ \c!left=,
+ \c!right=,
+ %
+ \c!location=]
+
+% \definepapersize[name][A4][A3]
+% \definepapersize[name][settings]
-\let\papersize\empty \let\printpapersize\empty
+\unexpanded\def\definepapersize
+ {\dotripleempty\define_paper_size}
-\def\paperscale{1}
+\def\define_paper_size[#1][#2][#3]%
+ {\edef\currentlayouttarget{#1}%
+ \ifx\currentlayouttarget\empty
+ % invalid target
+ \else
+ \doifassignmentelse{#2}
+ {\definelayouttarget[#1][#2]}
+ {\setevalue{\??pp:1:#1}{#2}%
+ \setevalue{\??pp:2:#1}{#3}}%
+ \fi}
-\unexpanded\def\setuppaper[#1]%
- {\getparameters[\??pp][\c!paper=,\c!page=,#1]%
- \edef\@@ppxy{\the\numexpr\@@ppnx*\@@ppny\relax}%
- \doifelsenothing\@@pppage
- {\doifelsenothing\@@pppaper
- {} % {\setuppapersize} % added, removed, no need for, too tricky, mag-01 (fixed by freezing pp's)
- {\dodosetuppapersize[\papersize][\@@pppaper]}}
- {\doifelsenothing\@@pppaper
- {\dodosetuppapersize[\@@pppage][\printpapersize]}
- {\dodosetuppapersize[\@@pppage][\@@pppaper]}}}
+\appendtoks
+ \letvalue{\??pp:c:\currentlayouttarget}\relax
+\to \everydefinelayouttarget
+
+\def\page_paper_the_paper_size#1{\ifcsname\??pp:1:#1\endcsname\csname\??pp:1:#1\endcsname\else#1\fi}
+\def\page_paper_the_print_size#1{\ifcsname\??pp:2:#1\endcsname\csname\??pp:2:#1\endcsname\else#1\fi}
+
+% \setuppaper [page=A4,paper=A3] % the k/v variant, changes the current page mapping
+% \setuppapersize[A4][a=b,c=d] % the k/v variant, changes nothing, just settings
+% \setuppapersize[A4][A3] % changes the current page mapping
+
+\let\page_paper_reinstate\relax
+\let\page_paper_restore \relax
\unexpanded\def\setuppapersize
- {\dodoubleempty\dosetuppapersize}
-
-\def\dosetuppapersize[#1][#2]%
- {\doifassignmentelse{#1}
- {\setuppaper[#1]}
- {\doifelsenothing{#2}
- {\expanded{\dodosetuppapersize
- [\executeifdefined{\??pp:1:#1}{#1}]%
- [\executeifdefined{\??pp:2:#1}{#1}]}}
- {\doifassignmentelse{#2}
- {\getparameters[\??pp\executeifdefined{\??pp:1:#1}{#1}][#2]}
- {\expanded{\dodosetuppapersize
- [\executeifdefined{\??pp:1:#1}{#1}]%
- [\executeifdefined{\??pp:1:#2}{#2}]}}}}}
-
-\let\reinstatepapersize\relax
-
-\def\adaptpapersize
- {\global\let\reinstatepapersize\restorepapersize
+ {\dodoubleempty\setup_paper_size}
+
+\unexpanded\def\setup_paper_size[#1][#2]%
+ {\iffirstargument
+ \doifassignmentelse{#1}
+ {\setup_paper_size_settings[#1]}
+ {\doifassignmentelse{#2}
+ {\setup_paper_size_settings_by_name[#1][#2]}
+ {\setup_paper_size_change_size[#1][#2]}}%
+ \else
+ \page_paper_restore
+ \fi}
+
+\unexpanded\def\setup_paper_size_settings[#1]%
+ {\let\currentlayouttarget\empty
+ \setupcurrentlayouttarget[#1]%
+ \edef\tmp_layouttarget_paper{\page_paper_the_paper_size{\layouttargetparameter\c!page }}%
+ \edef\tmp_layouttarget_print{\page_paper_the_print_size{\layouttargetparameter\c!paper}}%
+ \ifx\tmp_layouttarget_paper\empty
+ % forget about it
+ \else
+ \ifx\tmp_layouttarget_print\empty
+ \let\tmp_layouttarget_print\tmp_layouttarget_paper
+ \fi
+ \pages_paper_set_current[\tmp_layouttarget_paper][\tmp_layouttarget_print]%
+ \fi
+ \letlayouttargetparameter\c!page \papersize
+ \letlayouttargetparameter\c!paper\printpapersize}
+
+\unexpanded\def\setup_paper_size_settings_by_name[#1][#2]%
+ {\def\currentlayouttarget{\page_paper_the_paper_size{#1}}%
+ \setuplayouttarget[#2]}
+
+\unexpanded\def\setup_paper_size_change_size[#1][#2]%
+ {\doifelsenothing{#2}
+ {\pages_paper_set_current[#1][#1]}
+ {\pages_paper_set_current[#1][#2]}}
+
+\let\setuppaper\setup_paper_size_settings
+
+\unexpanded\def\adaptpapersize
+ {\global\let\page_paper_reinstate\page_paper_reinstate_indeed
\setuppapersize}
+\unexpanded\def\page_paper_reinstate_indeed
+ {\page_paper_restore
+ \global\let\page_paper_reinstate\relax}
+
\appendtoks
- \reinstatepapersize
- \global\let\reinstatepapersize\relax
+ \page_paper_reinstate
\to \everyaftershipout
-\def\dodosetuppapersize[#1][#2]%
- {\ifsecondargument
- \expanded{\dododosetuppapersize[#1][#2]}%
- \calculatehsizes
- \calculatevsizes
- \recalculatebackgrounds
- \recalculatelayout
- \else\iffirstargument
- \setuppapersize[#1][#2]%
- \else\ifx\papersize\undefined\else
- \restorepapersize
- \fi\fi\fi}
-
-% dimen freeze is a bit tricky, but catches local redundant calls
-% with values where e.g width is defined in terms of \paperwidth
-
-\def\dododosetuppapersize[#1][#2]%
- {\xdef\restorepapersize{\noexpand\setuppapersize[#1][#2]}%
- \dosetuppaperorientation{#1}\paperlandscape\paperorientation\paperreverse\papermirror
- \dosetuppaperorientation{#2}\printlandscape\printorientation\printreverse\printmirror
- \def\docommand##1%
- {\doifsomething{##1}{\doifdefined{\??pp##1\c!width}
- {\global\paperwidth \getvalue{\??pp##1\c!width}%
- \global\paperheight\getvalue{\??pp##1\c!height}%
- \ifinpagebody
- \setevalue{\??pp##1\c!height}{\the\paperheight}%
- \setevalue{\??pp##1\c!width }{\the\paperwidth }%
- \fi
- \calculatepaperoffsets{##1}%
- \xdef\papersize{##1}}}}%
- \processcommacommand[#1]\docommand
- \doifdefinedelse{\??pp#1\c!scale}
- {\edef\paperscale{\getvalue{\??pp#1\c!scale}}}
- {\edef\paperscale{1}}%
- \def\docommand##1%
- {\doifsomething{##1}{\doifdefined{\??pp##1\c!width}
- {\global\printpaperwidth \getvalue{\??pp##1\c!width}%
- \global\printpaperheight\getvalue{\??pp##1\c!height}%
- \ifinpagebody
- \setevalue{\??pp##1\c!height}{\the\printpaperheight}%
- \setevalue{\??pp##1\c!width }{\the\printpaperwidth}%
- \fi
- \xdef\printpapersize{##1}}}}%
- \processcommacommand[#2]\docommand
- \global\setdimentoatleast\paperwidth \onepoint
- \global\setdimentoatleast\paperheight \onepoint
- \global\setdimentoatleast\printpaperwidth \onepoint
- \global\setdimentoatleast\printpaperheight\onepoint
- \ifconditional\paperlandscape
+\unexpanded\def\page_paper_set_restore#1#2%
+ {\xdef\page_paper_restore{\pages_paper_set_current_indeed[#1][#2]}}
+
+\unexpanded\def\pages_paper_set_current[#1][#2]%
+ {\normalexpanded{\pages_paper_set_current_indeed
+ [\page_paper_the_paper_size{#1}]%
+ [\page_paper_the_print_size{#2}]}}
+
+\setvalue{\??pp:1:\v!reset }{\global\setfalse\c_page_target_paper_landscape
+ \global\setfalse\c_page_target_paper_mirror
+ \global\setfalse\c_page_target_paper_negate
+ \global\c_page_target_paper_orientation\uprotationangle
+ \global\c_page_target_paper_reverse \uprotationangle}
+\setvalue{\??pp:1:\v!landscape }{\global\settrue\c_page_target_paper_landscape}
+\setvalue{\??pp:1:\v!mirrored }{\global\settrue\c_page_target_paper_mirror}
+\setvalue{\??pp:1:\v!negative }{\global\settrue\c_page_target_paper_negate}
+\setvalue{\??pp:1:\v!rotated }{\global\c_page_target_paper_orientation\rightrotatioangle
+ \global\c_page_target_paper_reverse \leftrotatioangle}
+\setvalue{\??pp:1:\number\rightrotatioangle}{\global\c_page_target_paper_orientation\rightrotatioangle
+ \global\c_page_target_paper_reverse \leftrotatioangle}
+\setvalue{\??pp:1:\number\downrotatioangle }{\global\c_page_target_paper_orientation\downrotatioangle
+ \global\c_page_target_paper_reverse \zerocount}
+\setvalue{\??pp:1:\number\leftrotatioangle }{\global\c_page_target_paper_orientation\leftrotatioangle
+ \global\c_page_target_paper_reverse \rightrotatioangle}
+
+\setvalue{\??pp:1:\v!reset }{\global\setfalse\c_page_target_print_landscape
+ \global\setfalse\c_page_target_print_mirror
+ \global\setfalse\c_page_target_print_negate
+ \global\c_page_target_print_orientation\uprotationangle
+ \global\c_page_target_print_reverse \uprotationangle}
+\setvalue{\??pp:2:\v!landscape }{\global\settrue\c_page_target_print_landscape}
+\setvalue{\??pp:2:\v!mirrored }{\global\settrue\c_page_target_print_mirror}
+\setvalue{\??pp:2:\v!negative }{\global\settrue\c_page_target_print_negate}
+\setvalue{\??pp:2:\v!rotated }{\global\c_page_target_print_orientation\rightrotatioangle
+ \global\c_page_target_print_reverse \leftrotatioangle}
+\setvalue{\??pp:2:\number\rightrotatioangle}{\global\c_page_target_print_orientation\rightrotatioangle
+ \global\c_page_target_print_reverse \leftrotatioangle}
+\setvalue{\??pp:2:\number\downrotatioangle }{\global\c_page_target_print_orientation\downrotatioangle
+ \global\c_page_target_print_reverse \zerocount}
+\setvalue{\??pp:2:\number\leftrotatioangle }{\global\c_page_target_print_orientation\leftrotatioangle
+ \global\c_page_target_print_reverse \rightrotatioangle}
+
+\def\pages_paper_handle_page_option #1{\ifcsname\??pp:1:#1\endcsname\csname\??pp:1:#1\endcsname\fi}
+\def\pages_paper_handle_print_option#1{\ifcsname\??pp:2:#1\endcsname\csname\??pp:2:#1\endcsname\fi}
+
+\unexpanded\def\pages_paper_identify_target#1%
+ {\ifcsname\??pp:c:#1\endcsname
+ \edef\currentlayouttarget{#1}%
+ \fi}
+
+\unexpanded\def\pages_paper_set_current_indeed[#1][#2]%
+ {\edef\tmp_pages_asked_paper{\v!reset,#1}% can be the restores
+ \edef\tmp_pages_asked_print{\v!reset,#2}%
+ %
+ \page_paper_set_restore\tmp_pages_asked_paper\tmp_pages_asked_print
+ %
+ % locate page target
+ \let\currentlayouttarget\empty
+ \processcommacommand[\tmp_pages_asked_paper]\pages_paper_identify_target
+ \ifx\currentlayouttarget\empty
+ \let\currentlayouttarget\currentpage
+ \fi
+ \global\let\papersize\currentlayouttarget
+ \processcommacommand[\tmp_pages_asked_paper]\pages_paper_handle_page_option
+ \global\paperwidth \layouttargetparameter\c!width \relax
+ \global\paperheight\layouttargetparameter\c!height\relax
+ \ifdim\paperwidth<\onepoint
+ \global\paperwidth\onepoint
+ \fi
+ \ifdim\paperheight<\onepoint
+ \global\paperheight\onepoint
+ \fi
+ \ifconditional\c_page_target_paper_landscape
\doglobal\swapdimens\paperwidth\paperheight
\fi
- \ifconditional\printlandscape
- \doglobal\swapdimens\printpaperwidth\printpaperheight
+ \ifinpagebody % local freeze
+ \normalexpanded{\setlayouttargetparemeter\c!height{\the\paperheight}}%
+ \normalexpanded{\setlayouttargetparemeter\c!width {\the\paperwidth }}%
+ \fi
+ %
+ \pages_paper_set_offsets
+ % locate paper target
+ \processcommacommand[\tmp_pages_asked_print]\pages_paper_identify_target
+ \global\let\printpapersize\currentlayouttarget
+ \processcommacommand[\tmp_pages_asked_print]\pages_paper_handle_print_option
+ \global\printpaperwidth \layouttargetparameter\c!width \relax
+ \global\printpaperheight\layouttargetparameter\c!height\relax
+ \ifdim\printpaperwidth<\onepoint
+ \global\printpaperwidth\paperwidth
+ \fi
+ \ifdim\printpaperheight<\onepoint
+ \global\printpaperheight\paperheight
+ \fi
+ \ifconditional\c_page_target_print_landscape
+ \globalswapdimens\printpaperwidth\printpaperheight
\fi
% this check can be confusing, so we've added the possibility
% to bypass this test: \setuppapersize[option=fit]
- \doif\@@ppoption\v!max % \v!fit is
- {\bgroup
+ \edef\tmp_pages_asked_option{\rootlayouttargetparameter\c!option}%
+ \ifx\tmp_pages_asked_option\v!max % \v!fit is
+ \begingroup
% we need to pre-swap else we get the wrong paper size
- \ifnum\paperorientation=\rightrotatioangle
+ \ifnum\c_page_target_paper_orientation=\rightrotatioangle
\swapdimens\paperwidth\paperheight
- \else\ifnum\paperorientation=\leftrotatioangle
+ \else\ifnum\c_page_target_paper_orientation=\leftrotatioangle
\swapdimens\paperwidth\paperheight
\fi\fi
- \ifnum\printorientation=\rightrotatioangle
+ \ifnum\c_page_target_print_orientation=\rightrotatioangle
\swapdimens\printpaperwidth\printpaperheight
- \else\ifnum\printorientation=\leftrotatioangle
+ \else\ifnum\c_page_target_print_orientation=\leftrotatioangle
\swapdimens\printpaperwidth\printpaperheight
\fi\fi
\ifdim\paperheight>\printpaperheight
@@ -414,54 +526,25 @@
\global\printpaperwidth\paperwidth
\writestatus\m!system{print width forced to paper width}%
\fi
- \egroup}}
-
-\def\dosetuppaperorientation#1#2#3#4#5%
- {\global\setfalse#2%
- \global\setfalse#5%
- \global#3\uprotationangle
- \global#4\uprotationangle
- \global\setfalse\printnegatecolors
- \processallactionsinset
- [#1]
- [ \v!landscape=>\global\settrue#2,
- \v!mirrored=>\global\settrue#5,
- \v!rotated=>\global#3\rightrotatioangle
- \global#4\leftrotatioangle,
- \v!negative=>\global\settrue\printnegatecolors,
- 90=>\global#3\rightrotatioangle
- \global#4\leftrotatioangle,
- 180=>\global#3\downrotatioangle
- \global#4\zerocount,
- 270=>\global#3\leftrotatioangle
- \global#4\rightrotatioangle]}
-
-\ifx\calculatepaperoffsets\undefined
-
- \def\calculatepaperoffsets#1%
- {\scratchdimen\getvalue{\??pp#1\c!offset}%
- \global\advance\paperwidth -2\scratchdimen
- \global\advance\paperheight-2\scratchdimen}
-
-\fi
-
-\let\restorepapersize\relax
+ \endgroup
+ \fi
+ %\writestatus{layout target}{(\the\paperwidth,\the\paperheight) -> (\the\printpaperwidth,\the\printpaperheight)}%
+ \pages_layouts_synchronize}
-\ifx\setups\undefined \unexpanded\def\setups[#1]{\setdefaultpenalties} \fi
+\ifx\pages_paper_set_offsets\undefined
-% \newtoks \everybeforelayout \relax
-% \newtoks \everyafterlayout \relax
+ \def\pages_paper_set_offsets % will move
+ {\global\paperoffset\v_page_target_offset
+ \global\advance\paperwidth -2\paperoffset
+ \global\advance\paperheight-2\paperoffset}
-\def\recalculatelayout
- {\doifsomething{\layoutparameter\c!page\layoutparameter\c!paper}
- {\expanded{\dododosetuppapersize[\layoutparameter\c!page][\layoutparameter\c!paper]}}%
- \dorecalculatelayout}
+\fi
-\ifdefined\docheckgridsnapping \else \let\docheckgridsnapping\relax \fi
+\ifdefined\setups \else \unexpanded\def\setups[#1]{\setdefaultpenalties} \fi % still needed?
+\ifdefined\docheckgridsnapping \else \let\docheckgridsnapping\relax \fi
-\def\dorecalculatelayout
- {%\the\everybeforelayout
- \setups[\layoutparameter\c!preset]%
+\def\pages_layouts_synchronize
+ {\setups[\layoutparameter\c!preset]%
\global\leftmarginwidth \layoutparameter\c!leftmargin
\global\rightmarginwidth\layoutparameter\c!rightmargin
\global\leftedgewidth \layoutparameter\c!leftedge
@@ -472,43 +555,45 @@
\global\topheight \layoutparameter\c!top
\global\backspace \layoutparameter\c!backspace
\global\topspace \layoutparameter\c!topspace
- \setlayoutdimensions % the rest of the `dimensions'
+ \page_layouts_set_dimensions
\docheckgridsnapping
\doprocesslocalsetups{\layoutparameter\c!setups}% depends on gridsnapping !
\simplesetupwhitespace
\simplesetupblank
\setupinterlinespace[\v!reset]% \synchronizegloballinespecs
- \global\cutspace\layoutparameter\c!cutspace
- \relax
- \doifelse{\layoutparameter\c!width}\v!middle
- {\ifdim\cutspace=\zeropoint
- \global\cutspace\backspace
- \fi
- \global\makeupwidth\dimexpr\paperwidth-\backspace-\cutspace\relax}
- {\doifelse{\layoutparameter\c!width}\v!fit
- {\ifdim\cutspace=\zeropoint
- \global\cutspace\backspace
- \fi
- \global\makeupwidth\dimexpr\paperwidth-\cutspace\relax
- \scratchdimen\dimexpr\backspace
- -\leftedgewidth -\leftedgedistance
- -\leftmarginwidth-\leftmargindistance\relax
- \ifdim\scratchdimen<\zeropoint
- \scratchdimen\zeropoint
- \fi
- \global\advance\makeupwidth\dimexpr
- -\rightmargindistance-\rightmarginwidth
- -\rightedgedistance -\rightedgewidth
- -\scratchdimen\relax}
- {\global\makeupwidth\layoutparameter\c!width\relax
- \ifdim\cutspace=\zeropoint
- \global\cutspace\dimexpr\paperwidth-\makeupwidth-\backspace\relax
- % \else
- % A kind of inconsistent specification, but used
- % in for instance s-pre-19.tex; the cutspace is
- % used only for determining some kind of right
- % margin; don't use this in doublesided mode
- \fi}}%
+ \global\cutspace\layoutparameter\c!cutspace\relax
+ \edef\layout_parameter_width{\layoutparameter\c!width}%
+ \ifx\layout_parameter_width\v!middle
+ \ifdim\cutspace=\zeropoint
+ \global\cutspace\backspace
+ \fi
+ \global\makeupwidth\dimexpr\paperwidth-\backspace-\cutspace\relax
+ \else\ifx\layout_parameter_width\v!fit
+ \ifdim\cutspace=\zeropoint
+ \global\cutspace\backspace
+ \fi
+ \global\makeupwidth\dimexpr\paperwidth-\cutspace\relax
+ \scratchdimen\dimexpr\backspace
+ -\leftedgewidth -\leftedgedistance
+ -\leftmarginwidth-\leftmargindistance\relax
+ \ifdim\scratchdimen<\zeropoint
+ \scratchdimen\zeropoint
+ \fi
+ \global\advance\makeupwidth\dimexpr
+ -\rightmargindistance-\rightmarginwidth
+ -\rightedgedistance -\rightedgewidth
+ -\scratchdimen\relax
+ \else
+ \global\makeupwidth\layout_parameter_width\relax
+ \ifdim\cutspace=\zeropoint
+ \global\cutspace\dimexpr\paperwidth-\makeupwidth-\backspace\relax
+ % \else
+ % A kind of inconsistent specification, but used
+ % in for instance s-pre-19.tex; the cutspace is
+ % used only for determining some kind of right
+ % margin; don't use this in doublesided mode
+ \fi
+ \fi\fi
\scratchdimen\layoutparameter\c!bottomspace\relax
%\ifdim\scratchdimen=\zeropoint
% \scratchdimen\topspace
@@ -516,27 +601,30 @@
\global\bottomspace\layoutparameter\c!bottomspace\relax
\global\layoutlines0\number\layoutparameter\c!lines\relax % may be empty
\ifcase\layoutlines
- \doifelse{\layoutparameter\c!height}\v!middle
- {\ifdim\bottomspace=\zeropoint
- \global\bottomspace\topspace
- \fi
- \global\makeupheight\dimexpr\paperheight-\topspace-\bottomspace\relax}
- {\doifelse{\layoutparameter\c!height}\v!fit
- {\ifdim\bottomspace=\zeropoint
- \global\bottomspace\topspace
- \fi
- \global\makeupheight\dimexpr\paperheight-\bottomspace\relax
- \scratchdimen\dimexpr\topspace-\topheight-\topdistance\relax
- \ifdim\scratchdimen<\zeropoint
- \scratchdimen\zeropoint
- \fi
- \global\advance\makeupheight\dimexpr-\bottomdistance-\bottomheight-\scratchdimen\relax}
- {\global\makeupheight\layoutparameter\c!height\relax
- \ifdim\bottomspace=\zeropoint
- \global\bottomspace\dimexpr\paperheight-\makeupheight-\topspace\relax
- \else
- % inconsistent specification
- \fi}}%
+ \edef\layout_parameter_height{\layoutparameter\c!height}%
+ \ifx\layout_parameter_height\v!middle
+ \ifdim\bottomspace=\zeropoint
+ \global\bottomspace\topspace
+ \fi
+ \global\makeupheight\dimexpr\paperheight-\topspace-\bottomspace\relax
+ \else\ifx\layout_parameter_height\v!fit
+ \ifdim\bottomspace=\zeropoint
+ \global\bottomspace\topspace
+ \fi
+ \global\makeupheight\dimexpr\paperheight-\bottomspace\relax
+ \scratchdimen\dimexpr\topspace-\topheight-\topdistance\relax
+ \ifdim\scratchdimen<\zeropoint
+ \scratchdimen\zeropoint
+ \fi
+ \global\advance\makeupheight\dimexpr-\bottomdistance-\bottomheight-\scratchdimen\relax
+ \else
+ \global\makeupheight\layoutparameter\c!height\relax
+ \ifdim\bottomspace=\zeropoint
+ \global\bottomspace\dimexpr\paperheight-\makeupheight-\topspace\relax
+ % \else
+ % inconsistent specification
+ \fi
+ \fi\fi
\else
% beware, when the bodyfont changes (switched) this will change as well; implementing
% a global lineheight is tricky: should we take the bodyfont interlinespace or the one set
@@ -546,39 +634,47 @@
\layoutparameter\c!lines\lineheight-\strutheight+\topskip+
\headerdistance+\headerheight+\footerdistance+\footerheight\relax
\fi
- \backoffset\layoutparameter\c!horoffset
- \topoffset \layoutparameter\c!veroffset
- \global\setdimentoatleast\makeupwidth\onepoint
- \global\setdimentoatleast\makeupheight \onepoint
- % \checkcurrentlayout % here ?
- % \the\everyafterlayout
- \calculatelayoutextras
+ \backoffset\layoutparameter\c!horoffset\relax
+ \topoffset \layoutparameter\c!veroffset\relax
+ \ifdim\makeupwidth<\onepoint
+ \global\makeupwidth\onepoint
+ \fi
+ \ifdim\makeupheight<\onepoint
+ \global\makeupheight\onepoint
+ \fi
+ % \page_layouts_check_next % here ?
+ \page_layouts_calculate_extras
+ \page_target_check_centering
\calculatehsizes
\calculatevsizes
- \calculatepseudocolumns
+ \page_layouts_check_pseudo_columns
\recalculatebackgrounds}
-\def\calculatepseudocolumns
+\def\page_layouts_check_pseudo_columns
{\global\layoutcolumns\layoutparameter\c!columns
\global\layoutcolumndistance\layoutparameter\c!columndistance
\global\layoutcolumnwidth\dimexpr\makeupwidth-\layoutcolumns\layoutcolumndistance+\layoutcolumndistance\relax
- \global\divide\layoutcolumnwidth\layoutcolumns
- \dorecurse\layoutcolumns
- {\setxvalue{\??ly:c:\recurselevel}%
- {\the\numexpr\recurselevel-\plusone\relax\dimexpr\layoutcolumnwidth+\layoutcolumndistance\relax}}}
+ \ifnum\layoutcolumns>\plusone
+ \global\divide\layoutcolumnwidth\layoutcolumns
+ \dorecurse\layoutcolumns\page_layouts_check_pseudo_column
+ \fi}
-%\dorecurse\layoutcolumns
-% {\setxvalue{\??ly:c:\recurselevel}{\the\dimexpr
-% (\numexpr(\recurselevel-1)\dimexpr(\layoutcolumnwidth+\layoutcolumndistance))}}
+\def\page_layouts_check_pseudo_column
+ {\setxvalue{\??ly:c:\recurselevel}%
+ {\the\numexpr\recurselevel-\plusone\relax\dimexpr\layoutcolumnwidth+\layoutcolumndistance\relax}}
+
+\letvalue{\??ly:c:0}\zeropoint
\def\layoutcolumnoffset#1%
- {\executeifdefined{\??ly:c:#1}\zeropoint}
+ {\csname\??ly:c:\ifcsname\??ly:c:#1\endcsname#1\else0\fi\endcsname}
-\def\checklayout
- {\ifdim\makeupheight=\layoutlines\lineheight \else \recalculatelayout \fi}
+\def\pages_layouts_synchronize_at_start
+ {\ifdim\makeupheight=\layoutlines\lineheight \else % weird check
+ \pages_layouts_synchronize
+ \fi}
\appendtoks
- \checklayout
+ \pages_layouts_synchronize_at_start % still needed?
\to \everystarttext
% document:
@@ -587,48 +683,60 @@
%
% \startstandardmakeup[page=blank] ... \stopstandardmakeup
-\def\changetolayout#1%
+\ifdefined\lastpage \else \let\lastpage\!!plusone \fi
+
+\def\page_layouts_change#1%
{%\writestatus\m!layouts{changing to layout #1}%
\xdef\currentlayout{#1}%
- \recalculatelayout}
+ \pages_layouts_synchronize}
-\def\checkcurrentoddlayout
- {\ifcsname\namedlayouthash\v!odd\c!state\endcsname
- \doif{\namedlayoutparameter\v!odd\c!state}\v!start{\changetolayout\v!odd}%
- \fi}
+\let\changetolayout\page_layouts_change % also public
+
+\def\v_real_page_normal {\the\realpageno}
+\def\v_real_page_reverse{-\the\realpageno}
-\def\checkcurrentevenlayout
- {\ifcsname\namedlayouthash\v!even\c!state\endcsname
- \doif{\namedlayoutparameter\v!even\c!state}\v!start{\changetolayout\v!even}%
+\def\v_real_page_odd_or_even
+ {\ifodd\pagenoshift
+ \ifodd\realpageno\v!even\else\v!odd \fi
+ \else
+ \ifodd\realpageno\v!odd \else\v!even\fi
\fi}
-\ifx\lastpage\undefined
- \def\lastpage{1}
-\fi
+\let\v_real_page_current\v!current
-\def\reverserealfolio
- {\ifnum\lastpage>\plusone
- \ifnum\lastpage=\realfolio
- \v!last
- \else\ifnum\plusone=\realfolio
- \v!first
- \else
- \the\numexpr\realfolio-\lastpage\relax
- \fi\fi
+\def\v_real_page_named
+ {\ifnum\lastpage=\realpageno
+ \v!last
+ \else\ifnum\plusone=\realpageno
+ \v!first
\else
- \!!zerocount
- \fi}
+ \s!unknown
+ \fi\fi}
-\def\checkcurrentlayout % public and used in naw, so keep this name
- {\ifcsname\namedlayouthash\realfolio\c!state\endcsname
- \doif{\namedlayoutparameter\realfolio\c!state}\v!start{\changetolayout\realfolio}%
- \else\ifcsname\namedlayouthash\reverserealfolio\c!state\endcsname
- \doif{\namedlayoutparameter\reverserealfolio\c!state}\v!start{\changetolayout\reverserealfolio}%
- \else\ifcsname\namedlayouthash\v!current\c!state\endcsname
- \changetolayout\v!current % no start test ?
+\def\page_layouts_check_default_indeed#1%
+ {\doif{\namedlayoutparameter#1\c!state}\v!start{\page_layouts_change{#1}}}
+
+\def\page_layouts_check_default
+ {\ifcsname\namedlayouthash\v_real_page_normal \c!state\endcsname \page_layouts_check_default_indeed\v_real_page_normal \else
+ \ifcsname\namedlayouthash\v_real_page_reverse \c!state\endcsname \page_layouts_check_default_indeed\v_real_page_revers \else
+ \ifcsname\namedlayouthash\v_real_page_named \c!state\endcsname \page_layouts_check_default_indeed\v_real_page_named \else
+ \ifcsname\namedlayouthash\v_real_page_current \c!state\endcsname \page_layouts_check_default_indeed\v_real_page_current \else
+ \ifcsname\namedlayouthash\v_real_page_odd_or_even\c!state\endcsname \page_layouts_check_default_indeed\v_real_page_odd_or_even\fi\fi\fi\fi\fi}
+
+\def\installlayoutmethod#1#2%
+ {\setgvalue{\??ly:m:#1}{#2}}
+
+\installlayoutmethod\v!default{\page_layouts_check_default}
+\installlayoutmethod\v!normal {\page_layouts_check_default}
+
+\def\page_layouts_check_next
+ {\csname\??ly:m:\ifcsname\??ly:m:\layoutparameter\c!method\endcsname
+ \layoutparameter\c!method
\else
- \doifoddpageelse\checkcurrentoddlayout\checkcurrentevenlayout
- \fi\fi\fi}
+ \v!normal
+ \fi\endcsname}
+
+\let\checkcurrentlayout\page_layouts_check_next % public and used in naw, so this synonym will stay
% inheritance
%
@@ -660,311 +768,166 @@
% \dorecurse{20} {\input knuth \endgraf \input tufte \endgraf}
% \stoptext
-%appendtoks \checkcurrentlayout \to \everyaftershipout % no
-\appendtoks \checkcurrentlayout \to \everystarttext
+% Because we want to keep the set parameters as they are we use some
+% helpers to communicate between the several page building related
+% mechanism.
-\appendtoks
- \dochecknextlayout
-\to \everyaftershipout
-
-% \def\dochecknextlayout
-% {\ifx\currentlayout\v!current
-% % prevent redundant calculations
-% \else
-% \globallet\currentlayout\empty
-% \global\letbeundefined{\??ly\v!current\c!state}%
-% \checkcurrentlayout
-% \fi}
-%
-% this breaks after a standardmakeup
-
-\def\dochecknextlayout{\checkcurrentlayout}
+\appendtoks \page_layouts_check_next \to \everystarttext
+\appendtoks \page_layouts_check_next \to \everyaftershipout
\newconditional\c_page_layouts_location_is_set
\def\page_layouts_location_reset
{\setfalse\c_page_layouts_location_is_set
- \let\v_page_layouts_location_left_fill \relax
- \let\v_page_layouts_location_right_fill \relax
- \let\v_page_layouts_location_top_fill \relax
- \let\v_page_layouts_location_bottom_fill\relax}
-
-\page_layouts_location_reset
+ \let\v_page_target_left_fill \relax
+ \let\v_page_target_right_fill \relax
+ \let\v_page_target_top_fill \relax
+ \let\v_page_target_bottom_fill\relax}
\setvalue{\??ly:\c!location:\v!right }{\settrue\c_page_layouts_location_is_set
- \let\v_page_layouts_location_left_fill \hss}
+ \let\v_page_target_left_fill \hss}
\setvalue{\??ly:\c!location:\v!left }{\settrue\c_page_layouts_location_is_set
- \let\v_page_layouts_location_right_fill \hss}
+ \let\v_page_target_right_fill \hss}
\setvalue{\??ly:\c!location:\v!bottom }{\settrue\c_page_layouts_location_is_set
- \let\v_page_layouts_location_top_fill \vss}
+ \let\v_page_target_top_fill \vss}
\setvalue{\??ly:\c!location:\v!top }{\settrue\c_page_layouts_location_is_set
- \let\v_page_layouts_location_bottom_fill\vss}
+ \let\v_page_target_bottom_fill\vss}
\setvalue{\??ly:\c!location:\v!middle }{\settrue\c_page_layouts_location_is_set
- \let\v_page_layouts_location_left_fill \hss
- \let\v_page_layouts_location_right_fill \hss
- \let\v_page_layouts_location_top_fill \vss
- \let\v_page_layouts_location_bottom_fill\vss}
+ \let\v_page_target_left_fill \hss
+ \let\v_page_target_right_fill \hss
+ \let\v_page_target_top_fill \vss
+ \let\v_page_target_bottom_fill\vss}
\setvalue{\??ly:\c!location:\empty }{\setfalse\c_page_layouts_location_is_set % default also signal to scrn_
- \let\v_page_layouts_location_right_fill \hss
- \let\v_page_layouts_location_bottom_fill\hss}
-\setvalue{\??ly:\c!location:\v!doublesided}{\settrue\printdoublesided}
-\setvalue{\??ly:\c!location:\v!singlesided}{\setfalse\printdoublesided}
+ \let\v_page_target_right_fill \hss
+ \let\v_page_target_bottom_fill\hss}
+\setvalue{\??ly:\c!location:\v!doublesided}{\settrue \c_page_target_print_doublesided}
+\setvalue{\??ly:\c!location:\v!singlesided}{\setfalse\c_page_target_print_doublesided}
-\def\dopresetcenterpagebox#1%
+\def\page_target_check_centering_indeed#1%
{\ifcsname\??ly:\c!location:#1\endcsname\csname\??ly:\c!location:#1\endcsname\fi}
-\def\presetcenterpagebox
- {\setfalse\printdoublesided
+\unexpanded\def\page_target_check_centering
+ {\setfalse\c_page_target_print_doublesided
\page_layouts_location_reset
- \processcommacommand[\layoutparameter\c!location]\dopresetcenterpagebox}
+ \processcommacommand[\layoutparameter\c!location]\page_target_check_centering_indeed}
% installers
-\def\installlayoutmethod#1#2%
- {\setgvalue{\??ly:\c!method:#1}{#2}}
-
-\installlayoutmethod\v!default
- {\checkcurrentlayout}
-
-\installlayoutmethod\v!normal
- {\checkcurrentlayout}
-
-\def\dochecknextlayout
- {\executeifdefined
- {\??ly:\c!method:\layoutparameter\c!method}
- {\getvalue{\??ly:\c!method:\v!normal}}}
-
\def\installlayoutalternative#1#2%
- {\setgvalue{\??ly:\c!alternative:#1}{#2}}
+ {\setgvalue{\??ly:a:#1}{#2}}
-\def\constructnormalpagecontent#1#2% redefined
+\def\page_boxes_construct_content_default#1#2% #1 and #2 will become variables
{\setbox\pagebox\vbox
{\offinterlineskip
- \begingroup
- \dosetlayoutattributes\c!style\c!color
+ \begingroup % needed ?
+ \uselayoutstyleandcolor\c!style\c!color
\offinterlineskip
\gettextboxes
\endgroup
- \getmainbox#1#2}% including footnotes
- \addmainbackground\pagebox
- \buildpagebox\pagebox
- \addstatusinfo\pagebox}
-
-\installlayoutalternative\v!normal
- {\constructnormalpagecontent}
-
-\def\constructpagecontent % overload
- {\executeifdefined
- {\??ly:\c!alternative:\layoutparameter\c!alternative}%
- {\getvalue{\??ly:\c!alternative:\v!normal}}}
-
-\let\@@zaheight\!!zeropoint
-
-\def\dopushpagedimensions
- {\xdef\oldtextheight {\the\textheight }%
- \xdef\oldfooterheight{\the\footerheight}%
- \global\let\@@zaheight\@@zaheight}
-
-\def\dopoppagedimensions
- {\global\textheight \oldtextheight
- \global\footerheight\oldfooterheight
- \recalculatelayout
- \global\let\pushpagedimensions\dopushpagedimensions
- \global\let\poppagedimensions\relax}
-
-\let\poppagedimensions \relax
-\let\pushpagedimensions\dopushpagedimensions
-
-% Elke \csname ... \endcsname wordt ook aangemaakt, dus ook
-% in een test met \doifdefined. Bij veel bladzijden kan dit
-% te veel macro's kosten. Vandaar de set \adaptedpages. Het
-% kost tijd, maar scheelt macro's.
-
-\let\adaptedpages\empty
-
-\def\adaptpagedimensions
- {\ifx\adaptedpages\empty\else
- \adaptpagedimensionsindeed
- \fi}
+ \getmainbox#1#2}}% including footnotes
-\def\adaptpagedimensionsindeed
- {\rawdoifinset\realfolio\adaptedpages
- {\removefromcommalist\realfolio\adaptedpages
- \getvalue{\??za\realfolio}%
- \letbeundefined{\??za\realfolio}}}
+\installlayoutalternative\v!default{\page_boxes_construct_content_default}
+\installlayoutalternative\v!normal {\page_boxes_construct_content_default}
-\def\checkpagedimensions
- {\poppagedimensions
- \adaptpagedimensions}
+\def\page_boxes_construct_content
+ {\csname\??ly:a:\ifcsname\??ly:a:\layoutparameter\c!alternative\endcsname
+ \layoutparameter\c!alternative
+ \else
+ \v!normal
+ \fi\endcsname}
-\def\reportpagedimensions
- {\ifx\poppagedimensions\relax \else
- \space\the\dimexpr\@@zaheight\relax\space-\space
- \fi
- \realfolio}
+%D \macros
+%D {adaptlayout}
-\def\dodoadaptlayout[#1]%
- {\getparameters[\??za][\c!height=,\c!lines=0,#1]%
- \pushpagedimensions
- \ifcase\@@zalines\relax
- \showmessage\m!layouts1{\@@zaheight,\realfolio}%
+\newdimen\page_adepts_pushed_text_height
+\newdimen\page_adepts_pushed_footer_height
+\newdimen\page_adepts_height
+
+\unexpanded\def\adaptlayout
+ {\dodoubleempty\page_adapts_layout}
+
+\def\page_adapts_layout[#1][#2]%
+ {\ifsecondargument
+ \processcommalist[#1]{\page_adapts_layout_register{#2}}%
+ \page_adapts_check
\else
- \showmessage\m!layouts1{\@@zalines\space\v!lines,\realfolio}%
- \def\@@zaheight{\@@zalines\openlineheight}%
- \fi
+ \page_adapts_layout_indeed{#1}%
+ \fi}
+
+\def\page_adapts_layout_register#1#2%
+ {\setgvalue{\??za:#2}{\page_adapts_layout_indeed{#1}}}
+
+\def\page_adapts_layout_indeed#1%
+ {\getparameters[\??za][\c!height=\zeropoint,\c!lines=0,#1]%
+ \page_adepts_push
\doifelse\@@zaheight\v!max
- {\balancedimensions\textheight\footerheight\footerheight}
- {\balancedimensions\textheight\footerheight\@@zaheight}%
- \ifdim\footerheight<\zeropoint
- \global\advance\textheight \footerheight
- \global\footerheight\zeropoint
- \global\xdef\@@zaheight{\layoutparameter\c!footer\space(\v!max)}%
- \fi
+ {\global\page_adepts_height\footerheight}
+ {\global\page_adepts_height\dimexpr
+ \ifnum\@@zalines=\zerocount
+ \@@zaheight
+ \else
+ \@@zalines\openlineheight
+ \fi
+ \relax
+ \ifdim\page_adepts_height>\footerheight
+ \global\page_adepts_height\footerheight
+ \fi}
+ \global\advance\textheight \page_adepts_height
+ \global\advance\footerheight-\page_adepts_height
+ \showmessage\m!layouts1{\the\page_adepts_height,\the\realpageno}%
+ % this will become a better one (do we need insert correction?)
\setvsize
- \global\pagegoal\vsize % nog corrigeren voor insertions ?
+ \global\pagegoal\vsize
+ %
\recalculatebackgrounds
- \global\let\pushpagedimensions\relax
- \global\let\poppagedimensions\dopoppagedimensions}
+ \global\let\page_adepts_push\relax
+ \global\let\page_adepts_pop\page_adepts_pop_indeed}
-\def\doadaptlayout[#1][#2]%
- {\doifelsenothing{#2}
- {\dodoadaptlayout[#1]}
- {\def\docommand##1%
- {\addtocommalist{##1}\adaptedpages
- \setgvalue{\??za##1}{\dodoadaptlayout[#2]}}%
- \processcommalist[#1]\docommand
- \adaptpagedimensions}}
-
-\def\adaptlayout
- {\dodoubleempty\doadaptlayout}
-
-\unexpanded\def\startlayout[#1]%
- {\page
- \pushmacro\currentlayout
- \doiflayoutdefinedelse{#1}{\setuplayout[#1]}\donothing} % {\setuplayout[\currentlayout]}}
-
-\unexpanded\def\stoplayout
- {\page
- \popmacro\currentlayout
- \setuplayout[\currentlayout]}
-
-
-% describe interface
-
-%D Centering the paper area on the print area is determined
-%D by the \type {top}, \type {bottom}, \type {left} and \type
-%D {right} parameters.
-
-\def\centerpagebox#1% we could test for a difference (saves packing)
- {\printpaperwidth \paperscale\printpaperwidth
- \printpaperheight\paperscale\printpaperheight
- \ifdim\printpaperheight>\ht#1\relax
- \donetrue
- \else\ifdim\printpaperwidth>\wd#1\relax
- \donetrue
- \else
- \donefalse
- \fi\fi
- \ifdone
- \setbox#1\vbox to \printpaperheight
- {\@@pptop
- \v_page_layouts_location_top_fill
- \hbox to \printpaperwidth
- {\ifconditional\printdoublesided
- \doifbothsides
- {\@@ppleft \v_page_layouts_location_left_fill \box#1\v_page_layouts_location_right_fill\@@ppright}%
- {\@@ppleft \v_page_layouts_location_left_fill \box#1\v_page_layouts_location_right_fill\@@ppright}%
- {\@@ppright\v_page_layouts_location_right_fill\box#1\v_page_layouts_location_left_fill \@@ppleft }%
- \else
- \@@ppleft \v_page_layouts_location_left_fill \box#1\v_page_layouts_location_right_fill\@@ppright
- \fi}%
- \par
- \v_page_layouts_location_bottom_fill
- \@@ppbottom}%
+\def\page_adapts_check
+ {\ifcsname\??za:\the\realpageno\endcsname
+ \page_adapts_check_indeed
\fi}
-\def\offsetprintbox#1%
- {\ifdim\topoffset=\zeropoint % \relax
- \ifdim\backoffset=\zeropoint
- \donefalse
- \else
- \donetrue
- \fi
- \else
- \donetrue
- \fi
- \ifdone
- \edef\next{\wd#1\the\wd#1\ht#1\the\ht#1\dp#1\the\dp#1}%
- \setbox#1\vbox
- {\offinterlineskip
- \vskip\topoffset
- \hskip\doifbothsides\backoffset\backoffset{-\backoffset}%
- \box#1}%
- \next
- \fi}
+\def\page_adapts_check_indeed
+ {\getvalue{\??za:\the\realpageno}%
+ \letvalue{\??za:\the\realpageno}\relax}
-\def\replicatepagebox#1%
- {\ifnum\layoutparameter\c!nx>\plusone
- \donetrue
- \else\ifnum\layoutparameter\c!ny>\plusone
- \donetrue
- \else
- \donefalse
- \fi\fi
- \ifdone
- \setbox#1\vbox
- {\offinterlineskip
- \dorecurse{\layoutparameter\c!ny}
- {\hbox{\dorecurse{\layoutparameter\c!nx}{\copy#1\hskip\layoutparameter\c!dx}\unskip}%
- \vskip\layoutparameter\c!dy}
- \unskip}%
- \fi}
+\def\page_adepts_push_indeed
+ {\global\page_adepts_pushed_text_height \textheight
+ \global\page_adepts_pushed_footer_height\footerheight}
-\def\orientpagebodybox#1#2#3%
- {\ifnum\number#1\number#2>\zerocount
- \setbox#3\vbox
- {\edef\somerotation{\number\ifdoublesided\ifodd\realpageno#1\else#2\fi\else#1\fi}%
- \dorotatebox\somerotation\hbox{\box#3}}%
- \fi}
+\def\page_adepts_pop_indeed
+ {\global\textheight \page_adepts_pushed_text_height
+ \global\footerheight\page_adepts_pushed_footer_height
+ \pages_layouts_synchronize
+ \global\let\page_adepts_push\page_adepts_push_indeed
+ \global\let\page_adepts_pop\relax}
-\def\orientpaperbox{\orientpagebodybox\paperorientation\paperreverse}
-\def\orientprintbox{\orientpagebodybox\printorientation\printreverse}
+\let\page_adepts_pop \relax
+\let\page_adepts_push\page_adepts_push_indeed
-\def\mirrorpagebodybox#1#2%
- {\ifconditional#1\relax
- \setbox#2\vbox{\domirrorbox\vbox{\box#2}}%
- \fi}
+\unexpanded\def\page_adapts_synchronize % used elsewhere
+ {\page_adepts_pop
+ \page_adapts_check}
-\def\mirrorpaperbox{\mirrorpagebodybox\papermirror}
-\def\mirrorprintbox{\mirrorpagebodybox\printmirror}
-
-\def\scalepagebox#1%
- {\edef\tmp_currentlayout_scale{\layoutparameter\c!scale}%
- \ifdim\tmp_currentlayout_scale\points=\onepoint
- \edef\tmp_currentlayout_sx{\layoutparameter\c!sx}%
- \edef\tmp_currentlayout_sy{\layoutparameter\c!sy}%
- \ifdim\tmp_currentlayout_sx\points=\onepoint
- \ifdim\layoutparameter\c!sy\points=\onepoint
- % no scaling done (and no copying either)
- \else
- \doscalepagebox{#1}\tmp_currentlayout_sx\tmp_currentlayout_sy
- \fi
- \else
- \doscalepagebox{#1}\tmp_currentlayout_sx\tmp_currentlayout_sy
- \fi
- \else
- \doscalepagebox{#1}\tmp_currentlayout_scale\tmp_currentlayout_scale
- \fi}
+\def\page_adapts_status_info % used elsewhere
+ {\ifx\page_adepts_pop\relax \else
+ \space(adept: \the\page_adepts_height)\space
+ \fi
+ \the\realpageno}
+
+%D \macros
+%D {startlayout,stoplayout}
-\def\doscalepagebox#1#2#3%
- {\setbox#1\vbox{\scale[\c!sx=#2,\c!sy=#3]{\box#1}}%
- \paperwidth #2\paperwidth
- \paperheight#3\paperheight}
+\unexpanded\def\startlayout[#1]%
+ {\page
+ \pushmacro\currentlayout
+ \doiflayoutdefinedelse{#1}{\setuplayout[#1]}\donothing} % {\setuplayout[\currentlayout]}}
-\def\negateprintbox#1%
- {\ifconditional\printnegatecolors
- \negatecolorbox{#1}%
- \fi}
+\unexpanded\def\stoplayout
+ {\page
+ \popmacro\currentlayout
+ \setuplayout[\currentlayout]}
% NOG EENS NAGAAN WANNEER NU GLOBAL EN WANNEER NIET
@@ -977,25 +940,10 @@
\def\globalcompensatevsizeheader{\global\advance\textheight-\dimexpr\headerheight+\headerdistance\relax}
\def\globalcompensatevsizefooter{\global\advance\textheight-\dimexpr\footerheight+\footerdistance\relax}
-\def\compensatevsizeheaderzero{\headerheight\zeropoint\setlayoutdistances}
-\def\compensatevsizefooterzero{\footerheight\zeropoint\setlayoutdistances}
+\def\compensatevsizeheaderzero{\headerheight\zeropoint\page_layouts_set_distances}
+\def\compensatevsizefooterzero{\footerheight\zeropoint\page_layouts_set_distances}
-\def\calculatevsizes
- {\textheight\makeupheight
- \doifelselayoutsomeline\v!header\compensatevsizeheader\donothing
- \doifelselayoutsomeline\v!footer\compensatevsizefooter\donothing
- \setvsizemodes
- \resetglobal
- \setvsize}
-
-\def\calculateglobalvsizes
- {\global\textheight\makeupheight
- \doifelselayoutsomeline\v!header\globalcompensatevsizeheader\donothing
- \doifelselayoutsomeline\v!footer\globalcompensatevsizefooter\donothing
- \setvsizemodes
- \setvsize}
-
-\def\setvsizemodes
+\def\page_layouts_set_modes
{\ifzeropt\headerheight
\resetsystemmode\v!header
\else
@@ -1007,7 +955,22 @@
\setsystemmode\v!footer
\fi}
-\def\calculatereducedvsizes
+\def\calculatevsizes % name will change
+ {\textheight\makeupheight
+ \doifelselayoutsomeline\v!header\compensatevsizeheader\donothing
+ \doifelselayoutsomeline\v!footer\compensatevsizefooter\donothing
+ \page_layouts_set_modes
+ \resetglobal
+ \setvsize}
+
+\def\calculateglobalvsizes % name will change
+ {\global\textheight\makeupheight
+ \doifelselayoutsomeline\v!header\globalcompensatevsizeheader\donothing
+ \doifelselayoutsomeline\v!footer\globalcompensatevsizefooter\donothing
+ \page_layouts_set_modes
+ \setvsize}
+
+\def\calculatereducedvsizes % name will change
{\textheight\makeupheight
\doifelselayoutsomeline\v!header\compensatevsizeheader\compensatevsizeheaderzero
\doifelselayoutsomeline\v!footer\compensatevsizefooter\compensatevsizefooterzero}
@@ -1020,25 +983,28 @@
\def\compensatedinnermakeupmargin
{\dimexpr\ifconditional\innermakeupcompensation+\innermakeupmargin\else\zeropoint\fi\relax}
-\def\freezetextwidth % \makeupwidth may be set to \textwidth
- {\textwidth\makeupwidth % which is a tricky but valid value
- \doifsomething{\layoutparameter\c!textwidth}
- {\textwidth\layoutparameter\c!textwidth}% % local
+\def\freezetextwidth % name will change % \makeupwidth may be set to \textwidth
+ {\textwidth\makeupwidth % which is a tricky but valid value
+ \edef\tmp_currentlayout_text_width {\layoutparameter\c!textwidth }%
+ \edef\tmp_currentlayout_text_margin{\layoutparameter\c!textmargin}%
+ \ifx\tmp_currentlayout_text_width\empty \else
+ \textwidth\tmp_currentlayout_text_width % local
+ \fi
\global\innermakeupwidth\textwidth
- \doifelsenothing{\layoutparameter\c!textmargin}
- {\global\innermakeupmargin\zeropoint}
- {\global\innermakeupmargin\layoutparameter\c!textmargin}%
- \global\advance\innermakeupwidth-\dimexpr\innermakeupmargin+\innermakeupmargin\relax
- \advance\textwidth-\dimexpr\innermakeupmargin+\innermakeupmargin\relax} % local
+ \ifx\tmp_currentlayout_text_margin\empty
+ \global\innermakeupmargin\zeropoint
+ \else
+ \global\innermakeupmargin\tmp_currentlayout_text_margin\relax
+ \fi
+ \scratchdimen\dimexpr\innermakeupmargin+\innermakeupmargin\relax
+ \global\advance\innermakeupwidth-\scratchdimen
+ \advance\textwidth-\scratchdimen} % local
-\def\calculatehsizes
+\def\calculatehsizes % name will change
{\freezetextwidth
\sethsize}
-
-% De onderstaande macro voert commando's uit, afhankelijk van
-% het karakter van het paginanummer.
-%
-% \doifoddpageelse{then-commando}{else-commando}
+
+% The next few are better off in page-ini.mkiv
%D When we start at an even page, we need to swap the layout
%D differently. We cannot adapt the real page number, since
@@ -1048,6 +1014,8 @@
% We could use nested if here plus some \@EAEAEA's but but the
% next variant has less expansion which is nicer in tracing.
+% #single #left #right
+
\def\doifoddpageelse {\ifodd\pagenoshift\expandafter\doifoddpageelseyes \else\expandafter\doifoddpageelsenop \fi}
\def\doifoddpageelseyes{\ifodd\realpageno \expandafter\secondoftwoarguments\else\expandafter\firstoftwoarguments \fi}
\def\doifoddpageelsenop{\ifodd\realpageno \expandafter\firstoftwoarguments \else\expandafter\secondoftwoarguments\fi}
@@ -1079,7 +1047,7 @@
\newdimen\texthoffset
-\def\settexthoffset
+\def\settexthoffset % name will change
{\texthoffset\doifbothsides\backspace\backspace{\dimexpr\paperwidth-\backspace-\makeupwidth\relax}}
% The next hack is too tricky as we may shipout more pages:
@@ -1106,16 +1074,16 @@
% \freezepagestatechecks
% \to \everybeforeshipout
-\def\goleftonpage
+\def\goleftonpage % name will change
{\hskip-\dimexpr\leftmargindistance+\leftmarginwidth+\leftedgedistance+\leftedgewidth\relax}
\def\doifmarginswapelse#1#2%
{\doifbothsides{#1}{#1}{#2}}
-\def\swapmargins
+\def\swapmargins % name will change
{\doifmarginswapelse\relax\doswapmargins}
-\def\doswapmargins
+\def\doswapmargins % name will change
{\let\swapmargins \relax % to prevent local swapping
\let\doswapmargins\relax % to prevent local swapping
\the\everyswapmargins}
@@ -1178,15 +1146,15 @@
%D versions.
\unexpanded\def\startlocallayout
- {\globalpushmacro\restorepapersize
+ {\globalpushmacro\page_paper_restore
\globalpushmacro\currentlayout}
\unexpanded\def\stoplocallayout
{\globalpopmacro\currentlayout
- \globalpopmacro\restorepapersize
- \restorepapersize
- \setuplayout}
-
+ \globalpopmacro\page_paper_restore
+ \page_paper_restore
+ \setuplayout\relax}
+
%D \macros
%D {showprint, showframe, showlayout, showsetups}
%D
@@ -1218,26 +1186,6 @@
%D since they could change while going to a new page,
%D depending on the current font setting.
-\setuppaper % (size) % only used in XY imposition
- [\c!width=\zeropoint,
- \c!height=\zeropoint,
- \c!topspace=\zeropoint,
- \c!backspace=\zeropoint,
- \c!dx=\zeropoint,
- \c!dy=\zeropoint,
- \c!nx=1,
- \c!ny=1,
- \c!alternative=\v!normal,
- \c!method=\v!normal]
-
-\setuppapersize
- [\c!option=\v!max,
- \c!top=,
- \c!bottom=,
- \c!left=,
- \c!right=,
- \c!location=]
-
\setuplayout
[ \c!topspace=.08417508418\paperheight, % 2.5cm
\c!top=\zeropoint,