diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/page-bck.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/page-bck.mkiv | 687 |
1 files changed, 382 insertions, 305 deletions
diff --git a/Master/texmf-dist/tex/context/base/page-bck.mkiv b/Master/texmf-dist/tex/context/base/page-bck.mkiv index 81392f5af87..100c186ddce 100644 --- a/Master/texmf-dist/tex/context/base/page-bck.mkiv +++ b/Master/texmf-dist/tex/context/base/page-bck.mkiv @@ -5,35 +5,22 @@ %D subtitle=Backgrounds, %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 %C details. -\writestatus{loading}{ConTeXt Page Macros / Backgrounds} +% todo: ma:r:c +% +% Currently the text cells are fakes and no (foreground) frames which +% makes sense as order might matter e.g. is text sticks in other +% cells. The page, text etc ares do support foreground order change. -% todo \fastlocalframed -> \localbackgroundframed +\writestatus{loading}{ConTeXt Page Macros / Backgrounds} \unprotect -%D \macros -%D {recalculatebackgrounds} -%D -%D We use a couple of switches so that we can minimize the -%D amount of background calculations. The main switch is set -%D by the recalculate directive. -%D -%D \starttyping -%D \recalculatebackgrounds -%D \stoptyping -%D -%D Other modules may not directly set the switches -%D themselves. - -\newif\ifnewbackground -\newif\ifsomebackground - %D For special purposes, users can question the \type %D {*background} mode. This mode is only available when %D typesetting the pagebody. @@ -42,102 +29,103 @@ %D \startmode[*background] ... %D \stoptyping +\newconditional\c_page_backgrounds_new +\newconditional\c_page_backgrounds_new_right +\newconditional\c_page_backgrounds_new_left +\newconditional\c_page_backgrounds_some + \appendtoks - \ifsomebackground \ifnewbackground \setsystemmode\v!background \fi \fi + \ifconditional\c_page_backgrounds_some + \ifconditional\c_page_backgrounds_new + \setsystemmode\v!background + \fi + \fi \to \everybeforepagebody -%D \macros -%D {addmainbackground, addtextbackground, -%D addpagebackground, addprintbackground} -%D -%D Apart from the previously mentioned directive, the -%D interface between this module and the other modules -%D is made up by four macros that add background to parts of -%D the layout. -%D -%D \starttyping -%D \addmainbackground <box> -%D \addtextbackground <box> -%D \addpagebackground <box> -%D \addprintbackground <box> -%D \stoptyping +%D We keep calculations and checks to a minimum and also +%D try to minimize the amount of tracing due to expansion. -%D To minimize calculations, we keep track of the state of the -%D background of each area. A previous implementation did -%D check each call to the background calculation macro, but -%D using an intermediate usage flag instead of testing each -%D time saves about 3\% on a run with a couple of backgrounds. -%D (On the 824 pages maps bibliography runtime went down from -%D 309 to 299 seconds.) +\let\currentotrbackground\empty -% \let\currentotrbackground\empty -% -% \def\@@docheckbackground#1#2% -% {\ifcsname\currentotrbackground#1\endcsname -% \edef\!!stringa{\csname\currentotrbackground#1\endcsname}\ifx\!!stringa#2\!!doneatrue\fi -% \fi} -% -% \def\@@nocheckbackground#1#2% -% {\ifcsname\currentotrbackground#1\endcsname -% \edef\!!stringa{\csname\currentotrbackground#1\endcsname}\ifx\!!stringa#2\else\!!doneatrue\fi -% \fi} -% -% \def\checkbackground#1% -% {\edef\currentotrbackground{\??ma#1}% -% \begingroup -% \!!doneafalse -% \if!!donea\else\@@nocheckbackground\c!background \empty -% \if!!donea\else\@@docheckbackground\c!frame \v!on -% \if!!donea\else\@@nocheckbackground\c!foregroundcolor\empty -% \if!!donea\else\@@docheckbackground\c!leftframe \v!on -% \if!!donea\else\@@docheckbackground\c!rightframe \v!on -% \if!!donea\else\@@docheckbackground\c!topframe \v!on -% \if!!donea\else\@@docheckbackground\c!bottomframe \v!on \fi\fi\fi\fi\fi\fi\fi -% \if!!donea -% \endgroup\setusage \currentotrbackground -% \else -% \endgroup\resetusage\currentotrbackground -% \fi} -% -% \def\ifsomebackgroundfound#1% -% {\ifusage{\??ma#1}} -% -% \def\doifsomebackgroundelse#1% -% {\ifusage{\??ma#1}% -% \expandafter\firstoftwoarguments -% \else -% \expandafter\secondoftwoarguments -% \fi} +\def\page_backgrounds_set_yes{\expandafter\let\csname\currentotrbackground\endcsname\relax } +\def\page_backgrounds_set_nop{\expandafter\let\csname\currentotrbackground\endcsname\undefined} -\let\currentotrbackground\empty +\def\page_backgrounds_check_background + {\ifcsname\currentotrbackground\c!background\endcsname + \edef\page_background_temp{\csname\currentotrbackground\c!background\endcsname}% + \ifx\page_background_temp\empty + \expandafter\expandafter\expandafter\page_backgrounds_check_frame + \else + \page_backgrounds_set_yes + \fi + \else + \expandafter\page_backgrounds_check_frame + \fi} -\def\@@docheckbackground#1#2% - {\ifcsname\currentotrbackground#1\endcsname - \edef\!!stringa{\csname\currentotrbackground#1\endcsname}\ifx\!!stringa#2\!!doneatrue\fi +\def\page_backgrounds_check_frame + {\ifcsname\currentotrbackground\c!frame\endcsname + \edef\page_background_temp{\csname\currentotrbackground\c!frame\endcsname}% + \ifx\page_background_temp\v!on + \page_backgrounds_set_yes + \else + \expandafter\expandafter\expandafter\page_backgrounds_check_leftframe + \fi + \else + \expandafter\page_backgrounds_check_leftframe \fi} -\def\@@nocheckbackground#1#2% - {\ifcsname\currentotrbackground#1\endcsname - \edef\!!stringa{\csname\currentotrbackground#1\endcsname}\ifx\!!stringa#2\else\!!doneatrue\fi +\def\page_backgrounds_check_leftframe + {\ifcsname\currentotrbackground\c!leftframe\endcsname + \edef\page_background_temp{\csname\currentotrbackground\c!leftframe\endcsname}% + \ifx\page_background_temp\v!on + \page_backgrounds_set_yes + \else + \expandafter\expandafter\expandafter\page_backgrounds_check_rightframe + \fi + \else + \expandafter\page_backgrounds_check_rightframe \fi} -\def\checkbackground#1% here we need an \ifempty primitive - {\edef\currentotrbackground{\??ma#1}% - \begingroup - \!!doneafalse - \if!!donea\else\@@nocheckbackground\c!background \empty - \if!!donea\else\@@docheckbackground\c!frame \v!on - \if!!donea\else\@@nocheckbackground\c!foregroundcolor\empty - \if!!donea\else\@@docheckbackground\c!leftframe \v!on - \if!!donea\else\@@docheckbackground\c!rightframe \v!on - \if!!donea\else\@@docheckbackground\c!topframe \v!on - \if!!donea\else\@@docheckbackground\c!bottomframe \v!on \fi\fi\fi\fi\fi\fi\fi - \if!!donea - \endgroup\expandafter\let\csname\currentotrbackground\endcsname\relax +\def\page_backgrounds_check_rightframe + {\ifcsname\currentotrbackground\c!rightframe\endcsname + \edef\page_background_temp{\csname\currentotrbackground\c!rightframe\endcsname}% + \ifx\page_background_temp\v!on + \page_backgrounds_set_yes + \else + \expandafter\expandafter\expandafter\page_backgrounds_check_topframe + \fi + \else + \expandafter\page_backgrounds_check_topframe + \fi} + +\def\page_backgrounds_check_topframe + {\ifcsname\currentotrbackground\c!topframe\endcsname + \edef\page_background_temp{\csname\currentotrbackground\c!topframe\endcsname}% + \ifx\page_background_temp\v!on + \page_backgrounds_set_yes + \else + \expandafter\expandafter\expandafter\page_backgrounds_check_bottomframe + \fi \else - \endgroup\expandafter\let\csname\currentotrbackground\endcsname\undefined + \expandafter\page_backgrounds_check_bottomframe \fi} +\def\page_backgrounds_check_bottomframe + {\ifcsname\currentotrbackground\c!bottomframe\endcsname + \edef\page_background_temp{\csname\currentotrbackground\c!bottomframe\endcsname}% + \ifx\page_background_temp\v!on + \page_backgrounds_set_yes + \else + \page_backgrounds_set_nop + \fi + \else + \page_backgrounds_set_nop + \fi} + +\def\page_backgrounds_check#1% + {\edef\currentotrbackground{\??ma#1}% + \page_backgrounds_check_background} + \def\ifsomebackgroundfound#1% {\ifcsname\??ma#1\endcsname} @@ -159,42 +147,40 @@ %D macro. This means that all normal frame and overlay %D features can be used. -% \def\addsomebackground#1#2#3#4% area box width height / zero test added -% {\ifsomebackgroundfound#1\ifdim#3>\zeropoint\ifdim#4>\zeropoint -% \ifcsname\??ma#1\c!setups\endcsname % to be done -% \doprocesslocalsetups{\csname\??ma#1\c!setups\endcsname}% should not produce funny spaces ! -% \fi -% \setbox#2\vbox\fastlocalframed % maybe \superfastlocalframed{tag}{w}{h} -% [\??ma#1]% -% [\c!component=#1,\c!width=#3,\c!height=#4]% are width and height used? -% {\dp#2\zeropoint\box#2}% -% \fi\fi\fi} - -\def\addsomebackground#1#2#3#4% area box width height / zero test added - {\ifsomebackgroundfound#1\ifdim#3>\zeropoint\ifdim#4>\zeropoint - \ifcsname\??ma#1\c!setups\endcsname % to be done - \doprocesslocalsetups{\csname\??ma#1\c!setups\endcsname}% should not produce funny spaces ! - \fi - \localbackgroundframed{#1}{#2}{#3}{#4}% - \fi\fi\fi} +\def\page_backgrounds_add_to_box#1% area + {\ifcsname\??ma#1\endcsname + \expandafter\page_backgrounds_add_to_box_indeed + \else + \expandafter\gobblefourarguments + \fi#1} + +% we don't need the dimensions here as this is a real framed but the question is: do we indeed +% need a real framed or can we use a fake (i.e. no foreground, only for hidden) + +\def\page_backgrounds_add_to_box_indeed#1#2#3#4% area box width height / always non zero + {\ifcsname\??ma#1\c!setups\endcsname % to be done + \doprocesslocalsetups{\csname\??ma#1\c!setups\endcsname}% should not produce funny spaces ! + \fi + % #2 has the right dimensions already + \setbox#2\hbox{\localbackgroundframed{\??ma#1}#1#2}}% a real framed (including foreground) %D There are quite some backgrounds. At the bottom layer, %D there is the {\em paper} background. This one is only %D used for special purposes, like annotations to documents. -\def\addprintbackground#1% - {\addsomebackground\v!paper#1\printpaperwidth\printpaperheight} +\def\page_backgrounds_add_to_print#1% + {\page_backgrounds_add_to_box\v!paper#1\printpaperwidth\printpaperheight} %D The page backgrounds can be put behind the {\em left %D page}, the {\em right page} or {\em each page}. As with %D the paper background, these are calculated on each page. -\def\addpagebackground#1% +\def\page_backgrounds_add_to_paper#1% {\doifbothsidesoverruled - {\addsomebackground\v!rightpage#1\paperwidth\paperheight} - {\addsomebackground\v!rightpage#1\paperwidth\paperheight} - {\addsomebackground\v!leftpage #1\paperwidth\paperheight}% - \addsomebackground\v!page #1\paperwidth\paperheight} + {\page_backgrounds_add_to_box\v!rightpage#1\paperwidth\paperheight}% + {\page_backgrounds_add_to_box\v!rightpage#1\paperwidth\paperheight}% + {\page_backgrounds_add_to_box\v!leftpage #1\paperwidth\paperheight}% + \page_backgrounds_add_to_box\v!page#1\paperwidth\paperheight} %D Then there are the 25 areas that make up the layout: {\em %D top, header, text, footer, bottom} times {\em left edge, @@ -202,29 +188,20 @@ %D only recalculated when they change or when the \type %D {status} is set to \type {repeat}. -\newbox\leftbackground -\newbox\rightbackground - -\def\addmainbackground#1% todo: dimension spec - {\ifsomebackground - \ifnewbackground \setbackgroundboxes \fi - \setbox#1\vbox - {\offinterlineskip - \doifmarginswapelse{\copy\leftbackground}{\copy\rightbackground}% - \box#1}% - \fi} +\newbox\leftbackground % todo: rename +\newbox\rightbackground % todo: rename %D Finaly there is an aditional {\em text} background, again %D useful for special purposes only. This one is calculated %D each time. The hidden backgrounds are not meant for users! -\newconditional\hiddenbackgroundenabled +\newconditional\c_page_backgrounds_hidden_enabled -\def\addtextbackground#1% - {\ifconditional\hiddenbackgroundenabled - \addsomebackground\v!hidden#1\makeupwidth\textheight % mine ! +\def\page_backgrounds_add_to_text#1% + {\ifconditional\c_page_backgrounds_hidden_enabled + \page_backgrounds_add_to_box\v!hidden#1\makeupwidth\textheight % mine ! \fi - \addsomebackground\v!text#1\makeupwidth\textheight} + \page_backgrounds_add_to_box\v!text#1\makeupwidth\textheight} %D The next couple of macros implement the area backgrounds. %D As said, these are cached in dedicated boxes. The offsets @@ -233,63 +210,61 @@ \newdimen\pageoffset % bleed \newdimen\pagedepth -% \def\setbackgroundboxes -% {\showmessage\m!layouts8\empty -% \setbackgroundbox\leftbackground\relax -% \ifdoublesided -% \setbackgroundbox\rightbackground\doswapmargins -% \fi -% \doifnot\@@mastatus\v!herhaal{\global\newbackgroundfalse}} - %D We need a bit more clever mechanism in order to handle %D layers well. This means that we cannot calculate both %D background at the same time since something may have %D changed halfway a page. -\newconditional\newrightbackground -\newconditional\newleftbackground +%D Margin swapping has been simplified: see mkii code in case of +%D regression. Calculation is delayed till the page anyway so the +%D state is known. -\def\recalculatebackgrounds - {\global\newbackgroundtrue} +\def\page_backgrounds_recalculate + {\global\settrue\c_page_backgrounds_new} -\def\setbackgroundboxes - {\ifnewbackground - \dosetbackgroundboxesr +\def\page_backgrounds_set_boxes + {\ifconditional\c_page_backgrounds_new + \page_backgrounds_set_boxes_r \fi - \doifbothsides\dosetbackgroundboxesa\dosetbackgroundboxesb\dosetbackgroundboxesc - \ifx\@@mastate\v!repeat\else\global\newbackgroundfalse\fi} + \doifbothsides + \page_backgrounds_set_boxes_a + \page_backgrounds_set_boxes_b + \page_backgrounds_set_boxes_c + \ifx\@@mastate\v!repeat\else + \global\setfalse\c_page_backgrounds_new + \fi} -\def\dosetbackgroundboxesr - {\global\settrue\newrightbackground - \global\settrue\newleftbackground +\def\page_backgrounds_set_boxes_r + {\global\settrue\c_page_backgrounds_new_right + \global\settrue\c_page_backgrounds_new_left \global\setbox\leftbackground\emptybox \global\setbox\rightbackground\emptybox} -\def\dosetbackgroundboxesa - {\ifconditional\newleftbackground +\def\page_backgrounds_set_boxes_a + {\ifconditional\c_page_backgrounds_new_left % \showmessage\m!layouts8\empty - \setbackgroundbox\leftbackground\relax - \global\setfalse\newleftbackground - \global\setfalse\newrightbackground + \page_backgrounds_set_box\leftbackground % \conditionalfalse + \global\setfalse\c_page_backgrounds_new_left + \global\setfalse\c_page_backgrounds_new_right \fi} -\def\dosetbackgroundboxesb - {\ifconditional\newleftbackground +\def\page_backgrounds_set_boxes_b + {\ifconditional\c_page_backgrounds_new_left % \showmessage\m!layouts8\empty - \setbackgroundbox\leftbackground\relax - \global\setfalse\newleftbackground + \page_backgrounds_set_box\leftbackground % \conditionalfalse + \global\setfalse\c_page_backgrounds_new_left \fi} -\def\dosetbackgroundboxesc - {\ifconditional\newrightbackground +\def\page_backgrounds_set_boxes_c + {\ifconditional\c_page_backgrounds_new_right % \showmessage\m!layouts8\empty - \setbackgroundbox\rightbackground\doswapmargins - \global\setfalse\newrightbackground + \page_backgrounds_set_box\rightbackground % \conditionaltrue + \global\setfalse\c_page_backgrounds_new_right \fi} -\def\addmainbackground#1% todo: dimension spec - {\ifsomebackground - \setbackgroundboxes +\def\page_backgrounds_add_to_main#1% todo: dimension spec + {\ifconditional\c_page_backgrounds_some + \page_backgrounds_set_boxes \setbox#1\vbox {\offinterlineskip \doifmarginswapelse{\copy\leftbackground}{\copy\rightbackground}% @@ -299,34 +274,61 @@ \newdimen\pagebackgroundhoffset % THESE WILL BECOME OBSOLETE \newdimen\pagebackgroundvoffset \newdimen\pagebackgrounddepth -\newdimen\pagebackgroundoffset - -\def\setbackgroundoffsets % used in menus (we can use ifcsname's here) - {\ifsomebackground \ifnewbackground - \global\pagebackgroundhoffset\zeropoint - \global\pagebackgroundvoffset\zeropoint - \global\pagebackgrounddepth \zeropoint - \doifsomebackgroundelse{\v!text\v!text}\donetrue\donefalse - \ifdone\else\doifsomebackgroundelse\v!text\donetrue\donothing\fi - \ifdone - \begingroup - \scratchdimen\csname\??ma\v!page\c!offset\endcsname - \doifsomebackgroundelse{\v!top\v!text}\donothing - {\doifsomebackgroundelse{\v!bottom\v!text}\donothing - {\global\pagebackgroundhoffset\scratchdimen}}% - \doifsomebackgroundelse{\v!text\v!rightedge}\donothing - {\doifsomebackgroundelse{\v!text\v!leftedge}\donothing - {\global\pagebackgroundvoffset\scratchdimen - \global\pagebackgrounddepth\csname\??ma\v!page\c!depth\endcsname}}% - \endgroup - \fi +\newdimen\pagebackgroundcompensation + +\newdimen\pagebackgroundoffset % used elsewhere + +\def\page_backgrounds_set_offsets % used in menus (we can use ifcsname's here) + {\ifconditional\c_page_backgrounds_some \ifconditional\c_page_backgrounds_new + \page_backgrounds_set_offsets_indeed % indirect, less tracing \fi \fi} -\appendtoks \setbackgroundoffsets \to \everybeforepagebody +\def\page_backgrounds_set_offsets_indeed + {\ifcsname\??ma\v!text\v!text\endcsname + \page_backgrounds_set_offsets_yes + \else\ifcsname\??ma\v!text\endcsname + \page_backgrounds_set_offsets_yes + \else + \page_backgrounds_set_offsets_nop + \fi\fi} + +\def\page_backgrounds_set_offsets_nop + {\global\pagebackgroundhoffset \zeropoint + \global\pagebackgroundvoffset \zeropoint + \global\pagebackgrounddepth \zeropoint + \global\pagebackgroundcompensation\zeropoint} + +\def\page_backgrounds_set_offsets_yes + {\global\pagebackgroundcompensation\csname\??ma\v!page\c!offset\endcsname\relax + \ifzeropt\pagebackgroundcompensation + \page_backgrounds_set_offsets_nop + \else + \ifcsname\??ma\v!top\v!text\endcsname + \global\pagebackgroundhoffset\zeropoint + \else\ifcsname\??ma\v!bottom\v!text\endcsname + \global\pagebackgroundhoffset\zeropoint + \else + \global\pagebackgroundhoffset\pagebackgroundcompensation + \fi\fi + \ifcsname\??ma\v!text\v!rightedge\endcsname + \global\pagebackgroundvoffset\zeropoint + \global\pagebackgrounddepth \zeropoint + \else\ifcsname\??ma\v!text\v!leftedge\endcsname + \global\pagebackgroundvoffset\zeropoint + \global\pagebackgrounddepth \zeropoint + \else + \global\pagebackgroundvoffset\pagebackgroundcompensation + \global\pagebackgrounddepth \csname\??ma\v!page\c!depth\endcsname\relax + \fi\fi + \fi} + +\appendtoks + \page_backgrounds_set_offsets +\to \everybeforepagebody \newconditional\swapbackgroundmargins \settrue\swapbackgroundmargins -\def\setbackgroundbox#1#2% +\def\page_backgrounds_set_box#1% #2% {\global\setbox#1\vbox {\dontcomplain \swapmargins @@ -337,60 +339,101 @@ \fi \calculatereducedvsizes \offinterlineskip - #2\relax - \vskip\dimexpr-\topheight-\topdistance\relax - \dodopagebodybackground\v!top\topheight - \vskip\topdistance - \dodopagebodybackground\v!header\headerheight - \vskip\headerdistance - \dodopagebodybackground\v!text\textheight - \vskip\footerdistance - \dodopagebodybackground\v!footer\footerheight - \vskip\bottomdistance - \dodopagebodybackground\v!bottom\bottomheight + % \ifconditional#2\relax + % \doswapmargins % hm, this one gets nilled in \swapmargins anyway + % \fi + \ifdim\topheight>\zeropoint + \kern\dimexpr-\topheight-\topdistance\relax + \page_backgrounds_set_box_row\v!top\topheight + \kern\topdistance + \fi + \ifdim\headerheight>\zeropoint + \page_backgrounds_set_box_row\v!header\headerheight + \kern\headerdistance + \fi + \ifdim\textheight>\zeropoint + \page_backgrounds_set_box_row\v!text\textheight + \fi + \ifdim\footerheight>\zeropoint + \kern\footerdistance + \page_backgrounds_set_box_row\v!footer\footerheight + \fi + \ifdim\bottomheight>\zeropoint + \kern\bottomdistance + \page_backgrounds_set_box_row\v!bottom\bottomheight + \fi \vfilll}% - \smashbox#1} - -\def\dodopagebodybackground#1#2% maybe helper - {\ifdim#2>\zeropoint % added, faster - \setbox\scratchbox\vbox to #2 - \bgroup\hbox\bgroup - % \swapmargins - \goleftonpage - \dododopagebodybackground\leftedgewidth #2#1\v!leftedge - \hskip\leftedgedistance - \dododopagebodybackground\leftmarginwidth #2#1\v!leftmargin - \hskip\leftmargindistance - \dododopagebodybackground\makeupwidth #2#1\v!text - \hskip\rightmargindistance - \dododopagebodybackground\rightmarginwidth#2#1\v!rightmargin - \hskip\rightedgedistance - \dododopagebodybackground\rightedgewidth #2#1\v!rightedge - \egroup\egroup - \wd\scratchbox\zeropoint - \box\scratchbox\relax - \fi} - -\def\dododopagebodybackground#1#2#3#4% width height pos pos % maybe helper - {\ifsomebackgroundfound{#3#4}% - \ifdim#2>\zeropoint\relax - \ifdim#1>\zeropoint\relax - \ifcsname\??ma#3#4\c!setups\endcsname % to be done - \doprocesslocalsetups{\csname\??ma#3#4\c!setups\endcsname}% should not produce funny spaces ! + \smashbox#1} + +\def\page_backgrounds_set_box_row#1#2% maybe helper + {\setbox\scratchbox\vbox to #2 + \bgroup\hbox\bgroup + \goleftonpage + \ifdim\leftedgewidth>\zeropoint + \ifcsname\??ma#1\v!leftedge\endcsname + \page_backgrounds_set_box_cell#1\v!leftedge\leftedgewidth#2% + \else + \kern\leftedgewidth \fi - \fastlocalframed - [\??ma#3#4]% - [\c!component=#3-#4]% - {\vbox to #2{\vss\hbox to#1{\hss\csname\??ma#3#4\c!command\endcsname\hss}\vss}}% + \kern\leftedgedistance + \fi + \ifdim\leftmarginwidth>\zeropoint + \ifcsname\??ma#1\v!leftmargin\endcsname + \page_backgrounds_set_box_cell#1\v!leftmargin\leftmarginwidth#2% + \else + \kern\leftmarginwidth + \fi + \kern\leftmargindistance + \fi + \ifcsname\??ma#1\v!text\endcsname + \page_backgrounds_set_box_cell#1\v!text\makeupwidth#2% \else - \hskip#1% + \kern\makeupwidth \fi - \else - \hskip#1% - \fi + \ifdim\rightmarginwidth>\zeropoint + \kern\rightmargindistance + \ifcsname\??ma#1\v!rightmargin\endcsname + \page_backgrounds_set_box_cell#1\v!rightmargin\rightmarginwidth#2% + \else + \kern\rightmarginwidth + \fi + \fi + \ifdim\rightedgewidth>\zeropoint + \kern\rightedgedistance + \ifcsname\??ma#1\v!rightedge\endcsname + \page_backgrounds_set_box_cell#1\v!rightedge\rightedgewidth#2% + \else + \kern\rightedgewidth + \fi + \fi + \egroup\egroup + \wd\scratchbox\zeropoint + \box\scratchbox\relax} + +% these are fake framed .. maybe it's nicer to honor foreground here as well +% but it's probably a slow downer + +\def\page_backgrounds_set_box_cell#1#2#3#4% pos pos width height + {\begingroup + \ifcsname\??ma#1#2\c!setups\endcsname + \doprocesslocalsetups{\csname\??ma#1#2\c!setups\endcsname}% should not produce funny spaces ! + \fi + \ifcsname\??ma#1#2\c!command\endcsname + \expandafter\page_backgrounds_set_box_cell_nop \else - \hskip#1% - \fi} + \expandafter\page_backgrounds_set_box_cell_yes + \fi#1#2#3#4% + \localbackgroundframed{\??ma#1#2}{#1:#2}\scratchbox + \endgroup} + +\def\page_backgrounds_set_box_cell_nop#1#2#3#4% + {\setbox\scratchbox\emptyvbox + \wd\scratchbox#3% + \ht\scratchbox#4} + +\def\page_backgrounds_set_box_cell_yes#1#2#3#4% + {\setbox\scratchbox\vbox to #4{\vss\hbox to#3{\hss\csname\??ma#1#2\c!command\endcsname\hss}\vss}% + \dp\scratchbox\zeropoint} %D The background mechanism is quite demanding in terms or %D resources. We used to delay these definitions till runtime @@ -408,30 +451,22 @@ %D Because the number of arguments runs from one to three, %D we need to check for it. +\newtoks\everybackgroundssetup + \unexpanded\def\setupbackgrounds - {\dotripleempty\dosetupbackgrounds} + {\dotripleempty\page_backgrounds_setup} -\def\dosetupbackgrounds[#1][#2][#3]% +\def\page_backgrounds_setup[#1][#2][#3]% {\ifthirdargument - \global\somebackgroundtrue - \def\docommand##1% - {\doifinsetelse{##1}{\v!paper,\v!page,\v!leftpage,\v!rightpage} - {\getparameters[\??ma##1][#3]\checkbackground{##1}} - {\def\dodocommand####1{\getparameters[\??ma##1####1][#3]\checkbackground{##1####1}}% - \processcommalist[#2]\dodocommand}}% - \processcommalist[#1]\docommand + \page_backgrounds_setup_double{#1}{#2}{#3}% \else\ifsecondargument - \global\somebackgroundtrue - \doifcommonelse{#1}{\v!text,\v!hidden,\v!paper,\v!page,\v!leftpage,\v!rightpage} - {\def\docommand##1{\getparameters[\??ma##1][#2]\checkbackground{##1}}% - \processcommalist[#1]\docommand}% - {\setupbackgrounds - [#1]% - [\v!leftedge,\v!leftmargin,\v!text,\v!rightmargin,\v!rightedge]% - [#2]}% + \page_backgrounds_setup_single{#1}{#2}% \else\iffirstargument - \getparameters[\??ma][#1]% + \page_backgrounds_setup_basics{#1}% \fi\fi\fi + \the\everybackgroundssetup} + +\appendtoks \doifelsevalue{\??ma\v!page\c!offset}\v!overlay {\global\pageoffset\zeropoint} {\global\pageoffset\csname\??ma\v!page\c!offset\endcsname}% @@ -439,13 +474,44 @@ \global\pagebackgroundoffset\pageoffset \global\pagebackgrounddepth\pagedepth \doifelse\@@mastate\v!stop - {\global\newbackgroundfalse} - {\global\newbackgroundtrue }} + {\global\setfalse\c_page_backgrounds_new} + {\global\settrue \c_page_backgrounds_new}% +\to \everybackgroundssetup + +\def\v_page_backgrounds_double_set{\v!paper,\v!page,\v!leftpage,\v!rightpage} +\def\v_page_backgrounds_single_set{\v!text,\v!hidden,\v!paper,\v!page,\v!leftpage,\v!rightpage} +\def\v_page_backgrounds_common_set{\v!leftedge,\v!leftmargin,\v!text,\v!rightmargin,\v!rightedge} + +\def\page_backgrounds_setup_double#1#2#3% + {\global\settrue\c_page_backgrounds_some + \def\docommand##1% + {\doifinsetelse{##1}\v_page_backgrounds_double_set + {\page_backgrounds_setup_and_check{##1}{#3}} + {\def\dodocommand####1{\page_backgrounds_setup_and_check{##1####1}{#3}}% + \processcommalist[#2]\dodocommand}}% + \processcommalist[#1]\docommand} + +\def\page_backgrounds_setup_single#1#2% + {\global\settrue\c_page_backgrounds_some + \doifcommonelse{#1}\v_page_backgrounds_single_set + {\def\docommand##1{\page_backgrounds_setup_and_check{##1}{#2}}% + \processcommalist[#1]\docommand}% + {\page_backgrounds_setup_double{#1}\v_page_backgrounds_common_set{#2}}} + +\def\page_backgrounds_setup_basics#1% + {\getparameters[\??ma][#1]} + +\def\page_backgrounds_setup_and_check#1#2% tag settings + {\edef\currentotrbackground{\??ma#1}% + \getparameters[\currentotrbackground][#2]% + \page_backgrounds_check_background} %D Each areas (currently there are $1+3+25+1=30$ of them) %D has its own low level framed object associated. -\def\installsomebackground#1#2{\inheritlocalframed[\??ma#1#2][\??od]} +% hm, we can delay them + +\unexpanded\def\installsomebackground#1#2{\inheritlocalframed[\??ma#1#2][\??od]} \installsomebackground \v!paper \empty \installsomebackground \v!page \empty @@ -502,49 +568,60 @@ % spread-2 .. spread+2 achter spread -> spread (repeat 2 times) \def\enablehiddenbackground - {\global\settrue\hiddenbackgroundenabled - \global\somebackgroundtrue - \recalculatebackgrounds} + {\global\settrue\c_page_backgrounds_hidden_enabled + \global\settrue\c_page_backgrounds_some + \page_backgrounds_recalculate} \def\disablehiddenbackground - {\global\setfalse\hiddenbackgroundenabled} + {\global\setfalse\c_page_backgrounds_hidden_enabled} -\def\hiddenbackground +\def\hiddenbackgroundlist {\v!text-2,\v!text-1,\v!foreground,\v!text+1,\v!text+2} +% \defineoverlay[\v!text-2][\positionoverlay{\v!text-2}] +% \defineoverlay[\v!text-1][\positionoverlay{\v!text-1}] +% \defineoverlay[\v!text+1][\positionoverlay{\v!text+1}] +% \defineoverlay[\v!text+2][\positionoverlay{\v!text+2}] + +\defineoverlay[\v!text-2][\positionregionoverlay\textanchor{\v!text-2}] % no new anchor, we share text +\defineoverlay[\v!text-1][\positionregionoverlay\textanchor{\v!text-1}] +\defineoverlay[\v!text+1][\positionregionoverlay\textanchor{\v!text+1}] +\defineoverlay[\v!text+2][\positionregionoverlay\textanchor{\v!text+2}] + \setupbackgrounds [\v!hidden] - [\c!background=\hiddenbackground] + [\c!background=\hiddenbackgroundlist] % The next series is used in local (for instance floating) % backgrounds. -\installsomebackground \v!local \empty % not really a background, invisible for users - -\getparameters - [\??ma\v!local] - [\c!component=local, - \c!background=\localbackground] - -\def\localbackground - {\v!local-2,\v!local-1,\v!foreground,\v!local+1,\v!local+2} - -\defineoverlay[\v!local-2][\positionoverlay{\v!local-2}] -\defineoverlay[\v!local-1][\positionoverlay{\v!local-1}] -\defineoverlay[\v!local+1][\positionoverlay{\v!local+1}] -\defineoverlay[\v!local+2][\positionoverlay{\v!local+2}] - -\def\addlocalbackgroundtobox - {\ifconditional\hiddenbackgroundenabled - \expandafter\doaddlocalbackground - \else - \resetglobal \expandafter\gobbleoneargument - \fi} - -\def\doaddlocalbackground#1% - {\dodoglobal\setbox#1\hbox{\fastlocalframed[\??ma\v!local][]{\registerMPlocaltextarea{\box#1}}}% - \resetglobal % redundant - \doglobal\increment\localpositionnumber\relax} % afterwards ! +% \installsomebackground \v!local \empty % not really a background, invisible for users +% +% \getparameters +% [\??ma\v!local] +% [\c!component=local, +% \c!background=\localbackgroundlist] +% +% \def\localbackgroundlist +% {\v!local-2,\v!local-1,\v!foreground,\v!local+1,\v!local+2} +% +% \defineoverlay[\v!local-2][\positionoverlay{\v!local-2}] % todo share +% \defineoverlay[\v!local-1][\positionoverlay{\v!local-1}] +% \defineoverlay[\v!local+1][\positionoverlay{\v!local+1}] +% \defineoverlay[\v!local+2][\positionoverlay{\v!local+2}] +% +% \def\page_backgrounds_add_local_to_box +% {\ifconditional\c_page_backgrounds_hidden_enabled +% \expandafter\page_backgrounds_add_local_to_box_indeed +% \else +% \expandafter\gobbleoneargument +% \fi} +% +% \def\page_backgrounds_add_local_to_box_indeed#1% +% {\setbox#1\hbox{\localbackgroundframed{\??ma\v!local}\v!local#1}% +% \global\advance\localpositionnumber\plusone} % afterwards ! +% +% \let\page_backgrounds_add_local_to_box\gobbleoneargument % Test how previous macro behaves with depth: % @@ -559,6 +636,6 @@ %D Because we haven't really set up backgrounds yet, we set %D the main efficiency switch to false. -\somebackgroundfalse +\setfalse\c_page_backgrounds_some \protect \endinput |