summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/page-lay.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/page-lay.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/page-lay.mkiv1572
1 files changed, 791 insertions, 781 deletions
diff --git a/Master/texmf-dist/tex/context/base/page-lay.mkiv b/Master/texmf-dist/tex/context/base/page-lay.mkiv
index 812f3a3aca8..78839ea705a 100644
--- a/Master/texmf-dist/tex/context/base/page-lay.mkiv
+++ b/Master/texmf-dist/tex/context/base/page-lay.mkiv
@@ -5,7 +5,7 @@
%D subtitle=Layout Specification,
%D author=Hans Hagen,
%D date=\currentdate,
-%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%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
@@ -24,18 +24,12 @@
\unprotect
-%D First we get rid of the funny \TEX\ offset defaults of one
-%D inch by setting them to zero.
-
-\voffset = 0pt % setting this to -1in let's go metapost crazy
-\hoffset = 0pt % setting this to -1in let's go metapost crazy
-
%D The dimensions related to layout areas are represented by
%D real dimensions.
\newdimen\paperheight \paperheight = 297mm
\newdimen\paperwidth \paperwidth = 210mm
-\newdimen\paperoffset \paperoffset = 0mm
+\newdimen\paperoffset \paperoffset = \zeropoint
\newdimen\printpaperheight \printpaperheight = \paperheight
\newdimen\printpaperwidth \printpaperwidth = \paperwidth
@@ -48,13 +42,13 @@
\newdimen\topspace \topspace = 2cm
\newdimen\backspace \backspace = \topspace
-\newdimen\cutspace \cutspace = 0pt
-\newdimen\bottomspace \bottomspace = 0pt
+\newdimen\cutspace \cutspace = \zeropoint
+\newdimen\bottomspace \bottomspace = \zeropoint
\newdimen\headerheight \headerheight = 2cm
\newdimen\footerheight \footerheight = \headerheight
-\newdimen\topoffset \topoffset = 0pt
+\newdimen\topoffset \topoffset = \zeropoint
\newdimen\backoffset \backoffset = \topoffset
\newdimen\leftmarginwidth \leftmarginwidth = 3cm
@@ -63,46 +57,23 @@
\newdimen\leftedgewidth \leftedgewidth = 3cm
\newdimen\rightedgewidth \rightedgewidth = \leftedgewidth
-\newdimen\topheight \topheight = 0cm
+\newdimen\topheight \topheight = \zeropoint
\newdimen\bottomheight \bottomheight = \topheight
-\newcount\layoutlines \layoutlines = 0
-\newcount\layoutcolumns \layoutcolumns = 0
-\newdimen\layoutcolumndistance \layoutcolumndistance = 0pt
-\newdimen\layoutcolumnwidth \layoutcolumnwidth = 0pt
-
-%D We can save some tokens and fuzzy parameters by using a
-%D symbolic name for the current set of layout parameters.
-
-\let\currentlayout\empty
-
-\def\layoutparameter#1%
- {\csname\??ly\ifcsname
- \??ly\currentlayout#1\endcsname\currentlayout
- \fi#1\endcsname}
+\newcount\layoutlines \layoutlines = \zerocount
+\newcount\layoutcolumns \layoutcolumns = \zerocount
+\newdimen\layoutcolumndistance \layoutcolumndistance = \zeropoint
+\newdimen\layoutcolumnwidth \layoutcolumnwidth = \zeropoint
-\def\namedlayoutparameter#1#2%
- {\csname\??ly\ifcsname\??ly #1#2\endcsname#1\else
- \ifcsname\??ly\currentlayout#2\endcsname\currentlayout
- \fi\fi#2\endcsname}
-
-%D Beause normal \TEX\ has at most 256 dimensions (of which a
-%D substantial part is already in use), we provide a way to
-%D generate a format with macro based alternatives. For a long
-%D time, this used to be the default case. Beware: only fixed
-%D dimensions can be used in calculations! By the way, the
-%D gain in speed can hardly be called impressive and is roughly
-%D 1 second on a 35 second run of 850 empty pages with a
-%D couple of backgrounds only (which is far less than one
-%D percent on a normal document).
+\newdimen\totaltextwidth
%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
@@ -110,17 +81,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:
@@ -137,9 +108,62 @@
\newdimen\naturalfooterdistance
\newdimen\naturalbottomdistance
+%D Now we've come to the setup and definition commands.
+
+\installcorenamespace{layout}
+\installcorenamespace{layoutlocation}
+\installcorenamespace{layoutalternative}
+\installcorenamespace{layoutcolumn}
+\installcorenamespace{layoutmethod}
+
+\installswitchcommandhandler \??layout {layout} \??layout
+
+\appendtoks
+ \doifnothing{\strictlayoutparameter\c!state}{\letlayoutparameter\c!state\v!start}%
+\to \everydefinelayout
+
+\appendtoks
+ \ifcase\layoutsetupmode
+ % can't happen
+ \or % \setuplayout[name][key=value]
+ \ifx\previouslayout\currentlayout
+ \letlayoutparameter\c!state\v!normal % global ? still needed ?
+ \let\currentlayout\currentlayout
+ \page_layouts_synchronize
+ \page_layouts_check_next
+ \fi
+ \or % \setuplayout[key=value]
+ % we can inherit so we always synchronize
+ \letlayoutparameter\c!state\v!normal % global ? still needed ?
+ \let\currentlayout\previouslayout
+ \page_layouts_synchronize
+ \page_layouts_check_next
+ \or % \setuplayout[name]
+ \ifx\currentlayout\v!reset
+ \let\currentlayout\empty
+ \fi
+ \letlayoutparameter\c!state\v!normal % global ? still needed ?
+ \global\let\currentlayout\currentlayout % global
+ \page_layouts_synchronize
+ \page_layouts_check_next
+ \or % \setuplayout (reverts to main layout)
+ \letlayoutparameter\c!state\v!normal % global ? still needed ?
+ \global\let\currentlayout\empty % global
+ \page_layouts_synchronize
+ \page_layouts_check_next
+ \fi
+\to \everysetuplayout
+
+\def\doiflayoutdefinedelse#1%
+ {\ifcsname\namedlayouthash{#1}\c!state\endcsname % maybe a helper
+ \expandafter\firstoftwoarguments
+ \else
+ \expandafter\secondoftwoarguments
+ \fi}
+
\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
@@ -153,22 +177,22 @@
\global\naturalfooterdistance \layoutparameter\c!footerdistance
\global\naturalbottomdistance \layoutparameter\c!bottomdistance
%
- \global\marginwidth \naturalmarginwidth
- \global\edgewidth \naturaledgewidth
- \global\margindistance \naturalmargindistance
- \global\edgedistance \naturaledgedistance
+ \global\marginwidth \naturalmarginwidth
+ \global\edgewidth \naturaledgewidth
+ \global\margindistance \naturalmargindistance
+ \global\edgedistance \naturaledgedistance
%
- \global\leftedgedistance \layoutdistance\leftedgewidth \naturalleftedgedistance
- \global\rightedgedistance \layoutdistance\rightedgewidth \naturalrightedgedistance
- \global\leftmargindistance \layoutdistance\leftmarginwidth \naturalleftmargindistance
- \global\rightmargindistance \layoutdistance\rightmarginwidth\naturalrightmargindistance
- \global\topdistance \layoutdistance\topheight \naturaltopdistance
- \global\headerdistance \layoutdistance\headerheight \naturalheaderdistance
- \global\footerdistance \layoutdistance\footerheight \naturalfooterdistance
- \global\bottomdistance \layoutdistance\bottomheight \naturalbottomdistance
- }
-
-\def\setlayoutdistances % local in \setreducedvsize
+ \global\leftedgedistance \layoutdistance\leftedgewidth \naturalleftedgedistance
+ \global\rightedgedistance \layoutdistance\rightedgewidth \naturalrightedgedistance
+ \global\leftmargindistance \layoutdistance\leftmarginwidth \naturalleftmargindistance
+ \global\rightmargindistance \layoutdistance\rightmarginwidth\naturalrightmargindistance
+ \global\topdistance \layoutdistance\topheight \naturaltopdistance
+ \global\headerdistance \layoutdistance\headerheight \naturalheaderdistance
+ \global\footerdistance \layoutdistance\footerheight \naturalfooterdistance
+ \global\bottomdistance \layoutdistance\bottomheight \naturalbottomdistance
+ }
+
+\def\page_layouts_set_distances % local in \setreducedvsize
{\headerdistance\layoutdistance\headerheight\naturalheaderdistance
\footerdistance\layoutdistance\footerheight\naturalfooterdistance}
@@ -187,31 +211,31 @@
\def\outerspacewidth {\rightorleftpageaction\cutspace\backspace}
\def\innerspacewidth {\rightorleftpageaction\backspace\cutspace}
-\newtoks\extralayoutcalculations \def\calculatelayoutextras{\the\extralayoutcalculations}
+\newtoks\extralayoutcalculations
-% \appendtoks
-% non etex calculations used to go here
-% \to \extralayoutcalculations
+\def\page_layouts_calculate_extras
+ {\the\extralayoutcalculations}
\newtoks\everyswapmargins % watch the order !
\appendtoks
- \swapdimens\leftmargindistance\rightmargindistance
- \swapdimens\leftedgedistance \rightedgedistance
- \swapdimens\leftmarginwidth \rightmarginwidth
- \swapdimens\leftedgewidth \rightedgewidth
+ \swapdimens\leftmargindistance\rightmargindistance
+ \swapdimens\leftedgedistance \rightedgedistance
+ \swapdimens\leftmarginwidth \rightmarginwidth
+ \swapdimens\leftedgewidth \rightedgewidth
+ %
+ \swapmacros\leftmargintotal \rightmargintotal
+ \swapmacros\leftedgetotal \rightedgetotal
+ \swapmacros\leftsidetotal \rightsidetotal
+ \swapmacros\leftcombitotal \rightcombitotal
+ \swapmacros\innermargintotal \outermargintotal
+ \swapmacros\inneredgetotal \outeredgetotal
+ \swapmacros\innercombitotal \outercombitotal
+ \swapmacros\innersidetotal \outersidetotal
\to \everyswapmargins
-\appendtoks
- \swapmacros\leftmargintotal \rightmargintotal
- \swapmacros\leftedgetotal \rightedgetotal
- \swapmacros\leftsidetotal \rightsidetotal
- \swapmacros\leftcombitotal \rightcombitotal
- \swapmacros\innermargintotal\outermargintotal
- \swapmacros\inneredgetotal \outeredgetotal
- \swapmacros\innercombitotal \outercombitotal
- \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}
@@ -222,39 +246,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
@@ -275,7 +267,7 @@
%D Page 6. \page
%D \stoptext
%D \stoptyping
-
+%D
%D \macros
%D {setuppaper,setuppapersize}
%D
@@ -287,121 +279,288 @@
%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
+\installcorenamespace{layouttarget}
+\installcorenamespace{layoutpaper}
+\installcorenamespace{layoutprint}
+\installcorenamespace{layoutcurrent}
+
+\installcommandhandler \??layouttarget {layouttarget} \??layouttarget % 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_topspace {\dimexpr\rootlayouttargetparameter \c!topspace \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 the future 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]
+
+\unexpanded\def\definepapersize
+ {\dotripleempty\page_paper_define_size}
+
+\def\page_paper_define_size[#1][#2][#3]%
+ {\edef\currentlayouttarget{#1}%
+ \ifx\currentlayouttarget\empty
+ % invalid target
+ \else
+ \doifassignmentelse{#2}
+ {\definelayouttarget[#1][#2]}
+ {\setevalue{\??layoutpaper#1}{#2}%
+ \setevalue{\??layoutprint#1}{#3}}%
+ \fi}
-\let\papersize\empty \let\printpapersize\empty
+\appendtoks
+ \letvalue{\??layoutcurrent\currentlayouttarget}\relax
+\to \everydefinelayouttarget
+
+\def\page_paper_the_paper_size#1{\ifcsname\??layoutpaper#1\endcsname\csname\??layoutpaper#1\endcsname\else#1\fi}
+\def\page_paper_the_print_size#1{\ifcsname\??layoutprint#1\endcsname\csname\??layoutprint#1\endcsname\else#1\fi}
-\def\paperscale{1} \newif\ifnegateprintbox
+% \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
-\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]}}}
+\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}{\v!default}]}}
- [\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\page_paper_setup_size}
+
+\unexpanded\def\page_paper_setup_size[#1][#2]%
+ {\iffirstargument
+ \doifassignmentelse{#1}
+ {\page_paper_setup_size_settings[#1]}
+ {\doifassignmentelse{#2}
+ {\page_paper_setup_size_settings_by_name[#1][#2]}
+ {\page_paper_setup_size_change_size[#1][#2]}}%
+ \else
+ \page_paper_restore
+ \fi}
+
+\unexpanded\def\page_paper_setup_size_settings[#1]% sometimes used to set paper/print size
+ {\let\currentlayouttarget\empty
+ \edef\m_layouttarget_paper_saved{\page_paper_the_paper_size{\layouttargetparameter\c!page }}%
+ \edef\m_layouttarget_print_saved{\page_paper_the_print_size{\layouttargetparameter\c!paper}}%
+ \setupcurrentlayouttarget[#1]%
+ \edef\m_layouttarget_paper{\page_paper_the_paper_size{\layouttargetparameter\c!page }}%
+ \edef\m_layouttarget_print{\page_paper_the_print_size{\layouttargetparameter\c!paper}}%
+ \ifx\m_layouttarget_paper_saved\m_layouttarget_paper
+ \ifx\m_layouttarget_print_saved\m_layouttarget_print
+ % we didn't change the size, maybe only sx or sy or so
+ \else
+ \page_paper_setup_size_settings_recalibrate
+ \fi
+ \else
+ \page_paper_setup_size_settings_recalibrate
+ \fi}
+
+\def\page_paper_setup_size_settings_recalibrate
+ {\ifx\m_layouttarget_paper\empty
+ % forget about it
+ \else
+ \ifx\m_layouttarget_print\empty
+ \let\m_layouttarget_print\m_layouttarget_paper
+ \fi
+ \page_paper_set_current[\m_layouttarget_paper][\m_layouttarget_print]%
+ \fi
+ \letlayouttargetparameter\c!page \papersize
+ \letlayouttargetparameter\c!paper\printpapersize}
+
+\unexpanded\def\page_paper_setup_size_settings_by_name[#1][#2]%
+ {\def\currentlayouttarget{\page_paper_the_paper_size{#1}}%
+ \setuplayouttarget[#2]}
+
+\unexpanded\def\page_paper_setup_size_change_size[#1][#2]%
+ {\doifelsenothing{#2}
+ {\page_paper_set_current[#1][#1]}
+ {\page_paper_set_current[#1][#2]}}
+
+\let\setuppaper\page_paper_setup_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{\page_paper_set_current_indeed[#1][#2]}}
+
+\unexpanded\def\page_paper_set_current[#1][#2]%
+ {\normalexpanded{\page_paper_set_current_indeed
+ [\page_paper_the_paper_size{#1}]%
+ [\page_paper_the_print_size{#2}]}}
+
+\setvalue{\??layoutpaper\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{\??layoutpaper\v!landscape }{\global\settrue\c_page_target_paper_landscape}
+\setvalue{\??layoutpaper\v!mirrored }{\global\settrue\c_page_target_paper_mirror}
+\setvalue{\??layoutpaper\v!negative }{\global\settrue\c_page_target_paper_negate}
+\setvalue{\??layoutpaper\v!rotated }{\global\c_page_target_paper_orientation\rightrotationangle
+ \global\c_page_target_paper_reverse \leftrotationangle}
+\setvalue{\??layoutpaper\number\rightrotationangle}{\global\c_page_target_paper_orientation\rightrotationangle
+ \global\c_page_target_paper_reverse \leftrotationangle}
+\setvalue{\??layoutpaper\number\downrotationangle }{\global\c_page_target_paper_orientation\downrotationangle
+ \global\c_page_target_paper_reverse \zerocount}
+\setvalue{\??layoutpaper\number\leftrotationangle }{\global\c_page_target_paper_orientation\leftrotationangle
+ \global\c_page_target_paper_reverse \rightrotationangle}
+
+\setvalue{\??layoutprint\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{\??layoutprint\v!landscape }{\global\settrue\c_page_target_print_landscape}
+\setvalue{\??layoutprint\v!mirrored }{\global\settrue\c_page_target_print_mirror}
+\setvalue{\??layoutprint\v!negative }{\global\settrue\c_page_target_print_negate}
+\setvalue{\??layoutprint\v!rotated }{\global\c_page_target_print_orientation\rightrotationangle
+ \global\c_page_target_print_reverse \leftrotationangle}
+\setvalue{\??layoutprint\number\rightrotationangle}{\global\c_page_target_print_orientation\rightrotationangle
+ \global\c_page_target_print_reverse \leftrotationangle}
+\setvalue{\??layoutprint\number\downrotationangle }{\global\c_page_target_print_orientation\downrotationangle
+ \global\c_page_target_print_reverse \zerocount}
+\setvalue{\??layoutprint\number\leftrotationangle }{\global\c_page_target_print_orientation\leftrotationangle
+ \global\c_page_target_print_reverse \rightrotationangle}
+
+\def\page_paper_handle_page_option #1{\ifcsname\??layoutpaper#1\endcsname\csname\??layoutpaper#1\endcsname\fi}
+\def\page_paper_handle_print_option#1{\ifcsname\??layoutprint#1\endcsname\csname\??layoutprint#1\endcsname\fi}
+
+\unexpanded\def\page_paper_identify_target#1%
+ {\ifcsname\??layoutcurrent#1\endcsname
+ \edef\currentlayouttarget{#1}%
+ \fi}
+
+\unexpanded\def\page_paper_set_current_indeed[#1][#2]%
+ {\edef\m_page_asked_paper{\v!reset,#1}% can be the restores
+ \edef\m_page_asked_print{\v!reset,#2}%
+ %
+ \page_paper_set_restore\m_page_asked_paper\m_page_asked_print
+ %
+ % locate page target
+ \let\currentlayouttarget\empty
+ \processcommacommand[\m_page_asked_paper]\page_paper_identify_target
+ \ifx\currentlayouttarget\empty
+ \let\currentlayouttarget\currentpage
+ \fi
+ \global\let\papersize\currentlayouttarget
+ \processcommacommand[\m_page_asked_paper]\page_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
+ %
+ \page_paper_set_offsets
+ % locate paper target
+ \processcommacommand[\m_page_asked_print]\page_paper_identify_target
+ \global\let\printpapersize\currentlayouttarget
+ \processcommacommand[\m_page_asked_print]\page_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\m_page_asked_option{\rootlayouttargetparameter\c!option}%
+ \ifx\m_page_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=\rightrotationangle
\swapdimens\paperwidth\paperheight
- \else\ifnum\paperorientation=\leftrotatioangle
+ \else\ifnum\c_page_target_paper_orientation=\leftrotationangle
\swapdimens\paperwidth\paperheight
\fi\fi
- \ifnum\printorientation=\rightrotatioangle
+ \ifnum\c_page_target_print_orientation=\rightrotationangle
\swapdimens\printpaperwidth\printpaperheight
- \else\ifnum\printorientation=\leftrotatioangle
+ \else\ifnum\c_page_target_print_orientation=\leftrotationangle
\swapdimens\printpaperwidth\printpaperheight
\fi\fi
\ifdim\paperheight>\printpaperheight
@@ -412,63 +571,28 @@
\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\negateprintboxfalse
- \processallactionsinset
- [#1]
- [ \v!landscape=>\global\settrue#2,
- \v!mirrored=>\global\settrue#5,
- \v!rotated=>\global#3\rightrotatioangle
- \global#4\leftrotatioangle,
- \v!negative=>\global\negateprintboxtrue,
- 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)}%
+ \page_layouts_synchronize}
-% \def\docheckforems#1%
-% {\beforesplitstring#1\at em\to\asciia
-% \doifnot\asciia{#1}
-% {\aftersplitstring\asciia\at=\to\asciia
-% \doifsomething\asciia{\showmessage\m!system{10}{#1}}}}
-%
-% \def\checkforems[#1]%
-% {\processcommalist[#1]\docheckforems}
+\ifx\page_paper_set_offsets\undefined
-\ifx\setups\undefined \unexpanded\def\setups[#1]{\setdefaultpenalties} \fi
+ \def\page_paper_set_offsets % will move
+ {\global\paperoffset\v_page_target_offset
+ \global\advance\paperwidth -2\paperoffset
+ \global\advance\paperheight-2\paperoffset}
-% \newtoks \everybeforelayout \relax
-% \newtoks \everyafterlayout \relax
+\fi
-\def\recalculatelayout
- {\doifsomething{\layoutparameter\c!page\layoutparameter\c!paper}
- {\expanded{\dododosetuppapersize[\layoutparameter\c!page][\layoutparameter\c!paper]}}%
- \dorecalculatelayout}
+\ifdefined\setups \else \unexpanded\def\setups[#1]{\setdefaultpenalties} \fi % still needed?
+\ifdefined\synchronizegridsnapping \else \let\synchronizegridsnapping\relax \fi
-\ifdefined\docheckgridsnapping \else \let\docheckgridsnapping\relax \fi
+\let\p_page_layouts_width \empty
+\let\p_page_layouts_height\empty
-\def\dorecalculatelayout
- {%\the\everybeforelayout
- \setups[\layoutparameter\c!preset]%
+\def\page_layouts_synchronize
+ {\setups[\layoutparameter\c!preset]%
\global\leftmarginwidth \layoutparameter\c!leftmargin
\global\rightmarginwidth\layoutparameter\c!rightmargin
\global\leftedgewidth \layoutparameter\c!leftedge
@@ -479,43 +603,45 @@
\global\topheight \layoutparameter\c!top
\global\backspace \layoutparameter\c!backspace
\global\topspace \layoutparameter\c!topspace
- \setlayoutdimensions % the rest of the `dimensions'
- \docheckgridsnapping
+ \page_layouts_set_dimensions
+ \synchronizegridsnapping
\doprocesslocalsetups{\layoutparameter\c!setups}% depends on gridsnapping !
- \simplesetupwhitespace
- \simplesetupblank
+ \synchronizewhitespace
+ \synchronizeblank
\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\p_page_layouts_width{\layoutparameter\c!width}%
+ \ifx\p_page_layouts_width\v!middle
+ \ifdim\cutspace=\zeropoint
+ \global\cutspace\backspace
+ \fi
+ \global\makeupwidth\dimexpr\paperwidth-\backspace-\cutspace\relax
+ \else\ifx\p_page_layouts_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\p_page_layouts_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
@@ -523,27 +649,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\p_page_layouts_height{\layoutparameter\c!height}%
+ \ifx\p_page_layouts_height\v!middle
+ \ifdim\bottomspace=\zeropoint
+ \global\bottomspace\topspace
+ \fi
+ \global\makeupheight\dimexpr\paperheight-\topspace-\bottomspace\relax
+ \else\ifx\p_page_layouts_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
@@ -553,38 +682,56 @@
\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
+ % handy in page builder
+ \global\totaltextwidth\dimexpr
+ \leftedgetotal
+ +\leftmargintotal
+ +\makeupwidth
+ +\rightmargintotal
+ +\rightedgetotal
+ \relax
+ % \page_layouts_check_next % here ?
+ \page_layouts_calculate_extras
+ \page_target_check_centering
\calculatehsizes
\calculatevsizes
- \calculatepseudocolumns
- \recalculatebackgrounds}
+ \page_layouts_check_pseudo_columns
+ \page_backgrounds_recalculate}
-\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}
+
+\def\page_layouts_check_pseudo_column
+ {\setxvalue{\??layoutcolumn\recurselevel}%
+ {\the\numexpr\recurselevel-\plusone\relax\dimexpr\layoutcolumnwidth+\layoutcolumndistance\relax}}
-%\dorecurse\layoutcolumns
-% {\setxvalue{\??ly:c:\recurselevel}{\the\dimexpr
-% (\numexpr(\recurselevel-1)\dimexpr(\layoutcolumnwidth+\layoutcolumndistance))}}
+\letvalue{\??layoutcolumn0}\zeropoint
\def\layoutcolumnoffset#1%
- {\executeifdefined{\??ly:c:#1}\zeropoint}
+ {\csname\??layoutcolumn\ifcsname\??layoutcolumn#1\endcsname#1\else0\fi\endcsname}
-\def\checklayout
- {\ifdim\makeupheight=\layoutlines\lineheight \else \recalculatelayout \fi}
+\def\page_layouts_synchronize_at_start
+ {\ifdim\makeupheight=\layoutlines\lineheight \else % weird check
+ \page_layouts_synchronize
+ \fi}
-\appendtoks \checklayout \to \everystarttext
+\appendtoks
+ \page_layouts_synchronize_at_start % still needed?
+\to \everystarttext
% document:
%
@@ -592,46 +739,100 @@
%
% \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}
+ \xdef\currentlayout{#1}%
+ \page_layouts_synchronize}
-\def\checkcurrentoddlayout
- {\ifcsname\??ly\v!odd\c!state\endcsname
- \doifvalue{\??ly\v!odd\c!state}\v!start{\changetolayout\v!odd}%
- \fi}
+\let\changetolayout\page_layouts_change % also public
-\def\checkcurrentevenlayout
- {\ifcsname\??ly\v!even\c!state\endcsname
- \doifvalue{\??ly\v!even\c!state}\v!start{\changetolayout\v!even}%
+\def\v_real_page_normal {\the\realpageno}
+\def\v_real_page_reverse{-\the\numexpr\lastpage-\realpageno\relax}
+
+\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}
+ \__unknown__
+ \fi\fi}
+
+\let\v_page_layouts_pre_check\relax
+
+\def\page_layouts_check_default_indeed#1%
+ {\edef\m_page_check{#1}
+ \edef\m_page_state{\namedlayoutparameter\m_page_check\c!state}%
+ \ifx\m_page_state\v!start
+ \global\let\v_page_layouts_pre_check\currentlayout
+ \global\let\currentlayout\m_page_check
+ \page_layouts_synchronize
+ \else\ifx\m_page_state\v!repeat
+ \global\let\v_page_layouts_pre_check\relax
+ \global\let\currentlayout\m_page_check
+ \page_layouts_synchronize
+ \fi\fi}
+
+\def\page_layouts_check_revert
+ {\global\let\currentlayout\v_page_layouts_pre_check
+ \global\let\v_page_layouts_pre_check\relax
+ \page_layouts_synchronize}
+
+\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_reverse
+ \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
+ \else\ifx\v_page_layouts_pre_check\relax
+ % okay
+ \else
+ \page_layouts_check_revert
+ \fi\fi\fi\fi\fi\fi}
+
+\def\installlayoutmethod#1#2%
+ {\setgvalue{\??layoutmethod#1}{#2}}
+
+\installlayoutmethod\v!default{\page_layouts_check_default}
+\installlayoutmethod\v!normal {\page_layouts_check_default}
-\def\checkcurrentlayout % public and used in naw, so keep this name
- {\ifcsname\??ly\realfolio\c!state\endcsname
- \doifvalue{\??ly\realfolio\c!state}\v!start{\changetolayout\realfolio}%
- \else\ifcsname\??ly\reverserealfolio\c!state\endcsname
- \doifvalue{\??ly\reverserealfolio\c!state}\v!start{\changetolayout\reverserealfolio}%
- \else\ifcsname\??ly\v!current\c!state\endcsname
- \changetolayout\v!current % no start test ?
+\def\page_layouts_check_next
+ {\csname\??layoutmethod\ifcsname\??layoutmethod\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
+%
+% \definelayout
+% [test]
+% [width=12cm,
+% height=10cm]
+%
+% \definelayout
+% [more]
+% [test]
+% [height=12cm]
+%
% testcase
%
% \setuppagenumbering[alternative=doublesided]
@@ -650,354 +851,173 @@
% \dorecurse{20} {\input knuth \endgraf \input tufte \endgraf}
% \stoptext
-%appendtoks \checkcurrentlayout \to \everyaftershipout % no
-\appendtoks \checkcurrentlayout \to \everystarttext
-
-\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}
-
-\newif\ifdoublesidedprint
-
-\newconditional\page_location_is_set
-
-\def\page_location_reset
- {\setfalse\page_location_is_set
- \let\page_location_left_fill \relax
- \let\page_location_right_fill \relax
- \let\page_location_top_fill \relax
- \let\page_location_bottom_fill\relax}
-
-\page_location_reset
-
-\setvalue{\??ly:\c!location:\v!right }{\settrue\page_location_is_set
- \let\page_location_left_fill \hss}
-\setvalue{\??ly:\c!location:\v!left }{\settrue\page_location_is_set
- \let\page_location_right_fill \hss}
-\setvalue{\??ly:\c!location:\v!bottom }{\settrue\page_location_is_set
- \let\page_location_top_fill \vss}
-\setvalue{\??ly:\c!location:\v!top }{\settrue\page_location_is_set
- \let\page_location_bottom_fill\vss}
-\setvalue{\??ly:\c!location:\v!middle }{\settrue\page_location_is_set
- \let\page_location_left_fill \hss
- \let\page_location_right_fill \hss
- \let\page_location_top_fill \vss
- \let\page_location_bottom_fill\vss}
-\setvalue{\??ly:\c!location:\empty }{\setfalse\page_location_is_set % default also signal to scrn_
- \let\page_location_right_fill \hss
- \let\page_location_bottom_fill\hss}
-\setvalue{\??ly:\c!location:\v!doublesided}{\doublesidedprinttrue}
-\setvalue{\??ly:\c!location:\v!singlesided}{\doublesidedprintfalse}
-
-\def\dopresetcenterpagebox#1%
- {\ifcsname\??ly:\c!location:#1\endcsname\csname\??ly:\c!location:#1\endcsname\fi}
-
-\def\presetcenterpagebox
- {\doublesidedprintfalse
- \page_location_reset
- \processcommacommand[\@@lylocation]\dopresetcenterpagebox}
-
-\unexpanded\def\definelayout
- {\dodoubleargument\dodefinelayout}
-
-\def\dodefinelayout[#1][#2]%
- {\getparameters[\??ly#1][\c!state=\v!start,#2]}
-
-\def\dodosetuplayout[#1][#2]%
- {\doifnot{#2}\v!reset{\getparameters[\??ly#1][#2]}}
-
-% global needed for non-doublesided standardmakeup
-
-\unexpanded\def\setuplayout
- {\dodoubleempty\dosetuplayout}
-
-\def\dosetuplayout[#1][#2]%
- {\globallet\currentlayout\empty
- \ifsecondargument
- \dodosetuplayout[#1][#2]%
- \else\iffirstargument
- \doifassignmentelse{#1}
- {\dodosetuplayout[][#1]}
- {\doifelse{#1}\v!reset
- {\let\@@lymethod\v!normal}% hardcodes, assumes a definition
- {\xdef\currentlayout{#1}}}%
- \fi\fi
- \recalculatelayout
- %\checkcurrentlayout % here?
- \dochecknextlayout % here?
- \presetcenterpagebox}
-
-\def\installlayouthandler#1#2%
- {\setgvalue{\??ly:\c!method:#1}{#2}}
-
-\installlayouthandler\v!default
- {\checkcurrentlayout}
-
-\installlayouthandler\v!normal
- {\checkcurrentlayout}
-
-\def\dochecknextlayout
- {\executeifdefined{\??ly:\c!method:\@@lymethod}\checkcurrentlayout}
-
-\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}
-
-\def\adaptpagedimensionsindeed
- {\rawdoifinset\realfolio\adaptedpages
- {\removefromcommalist\realfolio\adaptedpages
- \getvalue{\??za\realfolio}%
- \letbeundefined{\??za\realfolio}}}
-
-\def\checkpagedimensions
- {\poppagedimensions
- \adaptpagedimensions}
-
-\def\reportpagedimensions
- {\ifx\poppagedimensions\relax \else
- \space\the\dimexpr\@@zaheight\relax\space-\space
- \fi
- \realfolio}
-
-\def\dodoadaptlayout[#1]%
- {\getparameters[\??za][\c!height=,\c!lines=0,#1]%
- \pushpagedimensions
- \ifcase\@@zalines\relax
- \showmessage\m!layouts1{\@@zaheight,\realfolio}%
+% 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 \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 % we start in the left top and mirror right pages
+ {\setfalse\c_page_layouts_location_is_set
+ \let\v_page_target_left_fill \relax
+ \let\v_page_target_right_fill \hss % ? \relax
+ \let\v_page_target_top_fill \relax
+ \let\v_page_target_bottom_fill\vss} % \relax}
+
+\setvalue{\??layoutlocation\v!right }{\settrue\c_page_layouts_location_is_set
+ \let\v_page_target_left_fill \hss
+ \let\v_page_target_right_fill \relax}
+\setvalue{\??layoutlocation\v!left }{\settrue\c_page_layouts_location_is_set
+ \let\v_page_target_left_fill \relax
+ \let\v_page_target_right_fill \hss}
+\setvalue{\??layoutlocation\v!bottom }{\settrue\c_page_layouts_location_is_set
+ \let\v_page_target_top_fill \vss
+ \let\v_page_target_bottom_fill\relax}
+\setvalue{\??layoutlocation\v!top }{\settrue\c_page_layouts_location_is_set
+ \let\v_page_target_top_fill \relax
+ \let\v_page_target_bottom_fill\vss}
+\setvalue{\??layoutlocation\v!middle }{\settrue\c_page_layouts_location_is_set
+ \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{\??layoutlocation\empty }{\setfalse\c_page_layouts_location_is_set % default also signal to scrn_
+ \let\v_page_target_right_fill \hss
+ \let\v_page_target_bottom_fill\hss}
+\setvalue{\??layoutlocation\v!doublesided}{\settrue \c_page_target_print_doublesided}
+\setvalue{\??layoutlocation\v!singlesided}{\setfalse\c_page_target_print_doublesided}
+
+\def\page_target_check_centering_indeed#1%
+ {\ifcsname\??layoutlocation#1\endcsname\csname\??layoutlocation#1\endcsname\fi}
+
+\unexpanded\def\page_target_check_centering
+ {\setfalse\c_page_target_print_doublesided
+ \page_layouts_location_reset
+ \processcommacommand[\layoutparameter\c!location]\page_target_check_centering_indeed}
+
+% installers
+
+\def\installlayoutalternative#1#2%
+ {\setgvalue{\??layoutalternative#1}{#2}}
+
+\def\page_boxes_construct_content_default#1#2#3% targetbox flusher box
+ {\setbox#1\vbox
+ {\offinterlineskip
+ \begingroup % needed ?
+ \uselayoutstyleandcolor\c!style\c!color
+ \offinterlineskip
+ \page_layouts_insert_elements % zero size
+ \endgroup
+ \page_insert_body#2#3}}% including footnotes
+
+\installlayoutalternative\v!default{\page_boxes_construct_content_default}
+\installlayoutalternative\v!normal {\page_boxes_construct_content_default}
+
+\def\page_boxes_construct_content % targetbox flusher box
+ {\csname\??layoutalternative\ifcsname\??layoutalternative\layoutparameter\c!alternative\endcsname
+ \layoutparameter\c!alternative
\else
- \showmessage\m!layouts1{\@@zalines\space\v!lines,\realfolio}%
- \def\@@zaheight{\@@zalines\openlineheight}%
- \fi
- \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
- \setvsize
- \global\pagegoal\vsize % nog corrigeren voor insertions ?
- \recalculatebackgrounds
- \global\let\pushpagedimensions\relax
- \global\let\poppagedimensions\dopoppagedimensions}
-
-\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}
-
-% 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
- \page_location_top_fill
- \hbox to \printpaperwidth
- {\ifdoublesidedprint
- \doifbothsides
- {\@@ppleft \page_location_left_fill \box#1\page_location_right_fill\@@ppright}%
- {\@@ppleft \page_location_left_fill \box#1\page_location_right_fill\@@ppright}%
- {\@@ppright\page_location_right_fill\box#1\page_location_left_fill \@@ppleft }%
- \else
- \@@ppleft \page_location_left_fill \box#1\page_location_right_fill\@@ppright
- \fi}%
- \par
- \page_location_bottom_fill
- \@@ppbottom}%
- \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\replicatepagebox#1%
- {\ifnum\@@lynx>\plusone
- \donetrue
- \else\ifnum\@@lyny>\plusone
- \donetrue
- \else
- \donefalse
- \fi\fi
- \ifdone
- \setbox#1\vbox
- {\offinterlineskip
- \dorecurse\@@lyny
- {\hbox{\dorecurse\@@lynx{\copy#1\hskip\@@lydx}\unskip}%
- \vskip\@@lydy}
- \unskip}%
- \fi}
+ \v!normal
+ \fi\endcsname}
-\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}
+%D \macros
+%D {adaptlayout}
-\def\orientpaperbox{\orientpagebodybox\paperorientation\paperreverse}
-\def\orientprintbox{\orientpagebodybox\printorientation\printreverse}
+\installcorenamespace{pageadaptations}
-\def\mirrorpagebodybox#1#2%
- {\ifconditional#1\relax
- \setbox#2\vbox{\domirrorbox\vbox{\box#2}}%
- \fi}
+\newdimen\d_page_adepts_pushed_text_height
+\newdimen\d_page_adepts_pushed_footer_height
+\newdimen\d_page_adepts_height
-\def\mirrorpaperbox{\mirrorpagebodybox\papermirror}
-\def\mirrorprintbox{\mirrorpagebodybox\printmirror}
+\unexpanded\def\adaptlayout
+ {\dodoubleempty\page_adapts_layout}
-\def\scalepagebox#1%
- {\ifdim\@@lyscale\points=\onepoint
- \ifdim\@@lysx\points=\onepoint
- \ifdim\@@lysy\points=\onepoint
- \else
- \doscalepagebox{#1}\@@lysx\@@lysy
- \fi
- \else
- \doscalepagebox{#1}\@@lysx\@@lysy
- \fi
+\def\page_adapts_layout[#1][#2]%
+ {\ifsecondargument
+ \processcommalist[#1]{\page_adapts_layout_register{#2}}%
+ \page_adapts_check
\else
- \doscalepagebox{#1}\@@lyscale\@@lyscale
- \fi}
-
-\def\doscalepagebox#1#2#3%
- {\setbox#1\vbox{\scale[\c!sx=#2,\c!sy=#3]{\box#1}}%
- \paperwidth #2\paperwidth
- \paperheight#3\paperheight}
-
-\def\negateprintbox#1%
- {\ifnegateprintbox
- \negatecolorbox{#1}%
+ \page_adapts_layout_indeed{#1}%
\fi}
-\def\pagecutmarksymbol {\the\realpageno}
-\def\pagecutmarklength {.5cm}
-\let\pagecutmarktoptext \empty
-\let\pagecutmarkbottomtext \empty
+\def\page_adapts_layout_register#1#2%
+ {\setgvalue{\??pageadaptations#2}{\page_adapts_layout_indeed{#1}}}
-\def\extrapagecutmarkbottomtext
- {\rlap{\jobname}\hfill\currentdate\space-\space\currenttime\hfill\llap{\realfolio}}
+\def\page_adapts_layout_indeed#1%
+ {\getparameters[\??za][\c!height=\zeropoint,\c!lines=0,#1]%
+ \page_adepts_push
+ \doifelse\@@zaheight\v!max
+ {\global\d_page_adepts_height\footerheight}
+ {\global\d_page_adepts_height\dimexpr
+ \ifnum\@@zalines=\zerocount
+ \@@zaheight
+ \else
+ \@@zalines\openlineheight
+ \fi
+ \relax
+ \ifdim\d_page_adepts_height>\footerheight
+ \global\d_page_adepts_height\footerheight
+ \fi}
+ \global\advance\textheight \d_page_adepts_height
+ \global\advance\footerheight-\d_page_adepts_height
+ \showmessage\m!layouts1{\the\d_page_adepts_height,\the\realpageno}%
+ % this will become a better one (do we need insert correction?)
+ \page_otr_command_set_vsize
+ \global\pagegoal\vsize
+ %
+ \page_backgrounds_recalculate
+ \global\let\page_adepts_push\relax
+ \global\let\page_adepts_pop\page_adepts_pop_indeed}
-\def\makepagecutbox % #1
- {\let\cutmarksymbol \pagecutmarksymbol
- \let\cutmarklength \pagecutmarklength
- \let\cutmarktoptext \pagecutmarktoptext
- \let\cutmarkbottomtext\pagecutmarkbottomtext
- \makecutbox}
+\def\page_adapts_check
+ {\ifcsname\??pageadaptations\the\realpageno\endcsname
+ \page_adapts_check_indeed
+ \fi}
-\setvalue{\??ly:n:\c!marking:\v!on}%
- {\makepagecutbox}
+\def\page_adapts_check_indeed
+ {\getvalue{\??pageadaptations\the\realpageno}%
+ \letvalue{\??pageadaptations\the\realpageno}\relax}
-\setvalue{\??ly:n:\c!marking:\v!page}% only at outer when nx/ny > 0
- {\makepagecutbox}
+\def\page_adepts_push_indeed
+ {\global\d_page_adepts_pushed_text_height \textheight
+ \global\d_page_adepts_pushed_footer_height\footerheight}
-\setvalue{\??ly:n:\c!marking:\v!empty}%
- {\let\pagecutmarksymbol\empty
- \let\pagecutmarktoptext\empty
- \let\pagecutmarkbottomtext\empty
- \makepagecutbox}
+\def\page_adepts_pop_indeed
+ {\global\textheight \d_page_adepts_pushed_text_height
+ \global\footerheight\d_page_adepts_pushed_footer_height
+ \page_layouts_synchronize
+ \global\let\page_adepts_push\page_adepts_push_indeed
+ \global\let\page_adepts_pop\relax}
-\setvalue{\??ly:n:\c!marking:\v!text}%
- {\let\pagecutmarksymbol\empty
- \let\pagecutmarkbottomtext\extrapagecutmarkbottomtext
- \makepagecutbox}
+\let\page_adepts_pop \relax
+\let\page_adepts_push\page_adepts_push_indeed
-\setvalue{\??ly:c:\c!marking:\v!color}%
- {\doaddpagecolormarks\colormarkbox}
+\unexpanded\def\page_adapts_synchronize % used elsewhere
+ {\page_adepts_pop
+ \page_adapts_check}
-\setvalue{\??ly:c:\c!marking:\v!screen}%
- {\doaddpagecolormarks\rastermarkbox}
+\def\page_adapts_status_info % used elsewhere
+ {\ifx\page_adepts_pop\relax \else
+ \space(adept: \the\d_page_adepts_height)\space
+ \fi
+ \the\realpageno}
-\letvalue{\??ly:c:\c!marking:\v!unknown}\gobbleoneargument
-\letvalue{\??ly:n:\c!marking:\v!unknown}\gobbleoneargument
+%D \macros
+%D {startlayout,stoplayout}
-% \def\addpagecutmarks {\executeifdefined{\??ly:n:\c!marking:\@@lymarking}\gobbleoneargument}
-% \def\addpagecolormarks{\executeifdefined{\??ly:c:\c!marking:\@@lymarking}\gobbleoneargument}
+\unexpanded\def\startlayout[#1]%
+ {\page
+ \pushmacro\currentlayout
+ \doiflayoutdefinedelse{#1}{\setuplayout[#1]}\donothing} % {\setuplayout[\currentlayout]}}
-\def\addpagecutmarks {\expandcheckedcsname{\??ly:n:\c!marking:}\@@lymarking\s!unknown}
-\def\addpagecolormarks{\expandcheckedcsname{\??ly:c:\c!marking:}\@@lymarking\s!unknown}
+\unexpanded\def\stoplayout
+ {\page
+ \popmacro\currentlayout
+ \setuplayout[\currentlayout]}
-\def\doaddpagecolormarks#1#2%
- {\makepagecutbox{#2}%
- \ifnum\horizontalcutmarks>\plustwo \def\colormarkoffset{\plusfour}\fi
- \ifnum\verticalcutmarks >\plustwo \def\colormarkoffset{\plusfour}\fi
- #1{#2}}
-
% NOG EENS NAGAAN WANNEER NU GLOBAL EN WANNEER NIET
\ifx\doifelselayoutsomeline\undefined % defined in page-txt
@@ -1009,25 +1029,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\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\compensatevsizeheaderzero{\headerheight\zeropoint\page_layouts_set_distances}
+\def\compensatevsizefooterzero{\footerheight\zeropoint\page_layouts_set_distances}
-\def\setvsizemodes
+\def\page_layouts_set_modes
{\ifzeropt\headerheight
\resetsystemmode\v!header
\else
@@ -1039,7 +1044,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
+ \page_otr_command_set_vsize}
+
+\def\calculateglobalvsizes % name will change
+ {\global\textheight\makeupheight
+ \doifelselayoutsomeline\v!header\globalcompensatevsizeheader\donothing
+ \doifelselayoutsomeline\v!footer\globalcompensatevsizefooter\donothing
+ \page_layouts_set_modes
+ \page_otr_command_set_vsize}
+
+\def\calculatereducedvsizes % name will change
{\textheight\makeupheight
\doifelselayoutsomeline\v!header\compensatevsizeheader\compensatevsizeheaderzero
\doifelselayoutsomeline\v!footer\compensatevsizefooter\compensatevsizefooterzero}
@@ -1052,25 +1072,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\m_currentlayout_text_width {\layoutparameter\c!textwidth }%
+ \edef\m_currentlayout_text_margin{\layoutparameter\c!textmargin}%
+ \ifx\m_currentlayout_text_width\empty \else
+ \textwidth\m_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\m_currentlayout_text_margin\empty
+ \global\innermakeupmargin\zeropoint
+ \else
+ \global\innermakeupmargin\m_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}
+ \page_otr_command_set_hsize}
+
+% 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
@@ -1080,6 +1103,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}
@@ -1111,7 +1136,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:
@@ -1137,21 +1162,21 @@
% \prependtoks
% \freezepagestatechecks
% \to \everybeforeshipout
-
-\def\goleftonpage
+
+\def\goleftonpage % name will change (we could cache)
{\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}
-
+
\def\rightorleftpageaction
{\ifdoublesided
\expandafter\rightorleftpageactionindeed
@@ -1210,15 +1235,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
@@ -1250,25 +1275,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!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,
@@ -1305,6 +1311,7 @@
\c!color=,
\c!marking=\v!off,
\c!location=,% \v!singlesided, but unset is signal (no other default, spoils arrange)
+ \c!state=\v!start,
\c!scale=1,
\c!sx=1,
\c!sy=1,
@@ -1319,7 +1326,7 @@
\c!lines=0,
\c!paper=, % for foxet
\c!page=, % for foxet
- \c!columns=1,
+ \c!columns=\plusone,
\c!columndistance=\zeropoint]
%D First we define a whole range of (DIN) papersizes,
@@ -1374,13 +1381,15 @@
%D a bunch of sizes with $4:3$ ratios. The \type {S6} size is
%D nearly as wide as a sheet of \type {A4} paper.
-\definepapersize [S3] [\c!width=300pt,\c!height=225pt]
-\definepapersize [S4] [\c!width=400pt,\c!height=300pt]
-\definepapersize [S5] [\c!width=500pt,\c!height=375pt]
-\definepapersize [S6] [\c!width=600pt,\c!height=450pt]
-\definepapersize [S8] [\c!width=800pt,\c!height=600pt]
-\definepapersize [SW] [\c!width=800pt,\c!height=450pt]
-\definepapersize [SM] [\c!width=720pt,\c!height=450pt]
+\definepapersize [S3] [\c!width=300pt,\c!height=225pt]
+\definepapersize [S4] [\c!width=400pt,\c!height=300pt]
+\definepapersize [S5] [\c!width=500pt,\c!height=375pt]
+\definepapersize [S6] [\c!width=600pt,\c!height=450pt]
+\definepapersize [S8] [\c!width=800pt,\c!height=600pt]
+\definepapersize [SW] [\c!width=800pt,\c!height=450pt]
+\definepapersize [SM] [\c!width=720pt,\c!height=450pt]
+\definepapersize [HD] [\c!width=1920pt,\c!height=1080pt]
+\definepapersize [HD+] [\c!width=1920pt,\c!height=1200pt]
%D These are handy too:
@@ -1468,6 +1477,11 @@
\c!height=\dimexpr\paperheight+1.5cm\relax]
\definepapersize
+ [undersized]
+ [ \c!width=\dimexpr\paperwidth -1.5cm\relax,
+ \c!height=\dimexpr\paperheight-1.5cm\relax]
+
+\definepapersize
[doublesized]
[ \c!width=\dimexpr \paperwidth \relax,
\c!height=\dimexpr2\paperheight\relax]
@@ -1481,19 +1495,15 @@
% [A4][A4]
\setuppapersize
- [A4][samesized]
+ [A4] % [samesized]
%D A few goodies:
-%D For orthogonality:
-
-\definepapersize
- [undersized]
- [ \c!width=\dimexpr\paperwidth -1.5cm\relax,
- \c!height=\dimexpr\paperheight-1.5cm\relax]
-
\definelayout
[\v!page]
+
+\setuplayout
+ [\v!page]
[\c!backspace=\zeropoint,
\c!cutspace=\zeropoint,
\c!topspace=\zeropoint,