page-inj.mkvi /size: 8327 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [     file=page-inj,
3%D      version=2013.02.10,
4%D        title=\CONTEXT\ Page Module,
5%D     subtitle=Injections,
6%D       author=Wolfgang Schuster \& Hans Hagen,
7%D         date=\currentdate,
8%D    copyright=Wolfgang Schuster \& Hans Hagen,
9%D      license=see context related readme files (gpl)]
10
11%D This module is based on an idea and prototype by Wolfgang but instead of
12%D injectioning into a page constructor we injection it into the regular shipout
13%D handler because that way we get page numbering. It's a sort of variation
14%D on postponing but the content does not end up in the regular page flow, so
15%D it's closer to page figures but without the usual page builder.
16%D
17%D This module is following the mkvi way of rendering setups and configuration
18%D and is somewhat experimental. Probably more alternatives will be added. This
19%D could become a delayed loaded module at some point (no real consequences).
20
21\unprotect
22
23\registerctxluafile{page-inj}{}
24
25\installcorenamespace {pageinjection}
26\installcorenamespace {pageinjectionalternative}
27\installcorenamespace {pageinjectionrenderings}
28
29\installframedcommandhandler \??pageinjection            {pageinjection}            \??pageinjection
30\installcommandhandler       \??pageinjectionalternative {pageinjectionalternative} \??pageinjectionalternative
31
32\let\page_boxes_flush_before\clf_flushpageinjectionsbefore
33\let\page_boxes_flush_after \clf_flushpageinjectionsafter
34
35\def\page_injections_flush_indeed
36  {\begingroup
37   \setbox\scratchbox\normalhpack
38     {\inheritedpageinjectionframed{\texsetup\p_page_injectionalternative_rederingsetup}}%
39   \printpaperwidth \wd\scratchbox
40   \printpaperheight\ht\scratchbox
41   \scrn_canvas_synchronize_only
42   \invokepagehandler\v!normal{\box\scratchbox}%
43   \endgroup
44   \scrn_canvas_synchronize_reset}
45
46\def\page_injections_flush_saved#name#parameters%
47  {\begingroup
48   \edef\currentpageinjection{#name}%
49   \getdummyparameters[#parameters]%
50   \edef\currentpageinjectionalternative          {\pageinjectionparameter           \c!alternative   }%
51   \edef\p_page_injectionalternative_rederingsetup{\pageinjectionalternativeparameter\c!renderingsetup}%
52   \page_injections_nextpage
53   \page_injections_flush_indeed
54   \endgroup}
55
56\unexpanded\def\pageinjection
57  {\begingroup
58   \dodoubleempty\page_injections_direct}
59
60\def\page_injections_direct[#1][#2]% name parameters | settings parameters | name | parameters
61  {\doifelseassignment{#1}
62     {\doifelseassignment{#2}
63        {\page_injections_direct_settings_parameters{#1}{#2}}
64        {\page_injections_direct_parameters         {#1}}}
65     {\doifelseassignment{#2}
66        {\page_injections_direct_name_parameters    {#1}{#2}}
67        {\page_injections_direct_name               {#1}}}}
68
69\def\page_injections_direct_settings_parameters#settings% #parameters%
70  {\let\currentpageinjection\empty
71   \checkpageinjectionparent
72   \setupcurrentpageinjection[#settings]%
73   \page_injections_direct_indeed}
74
75\def\page_injections_direct_parameters% #parameters%
76  {\let\currentpageinjection\empty
77   \checkpageinjectionparent
78   \page_injections_direct_indeed}
79
80\def\page_injections_direct_name_parameters#name% #parameters%
81  {\edef\currentpageinjection{#name}%
82   \checkpageinjectionparent
83   \page_injections_direct_indeed}
84
85\def\page_injections_direct_name#name%
86  {\edef\currentpageinjection{#name}%
87   \checkpageinjectionparent
88   \page_injections_direct_indeed{}}
89
90\def\page_injections_direct_indeed% #parameters%
91  {\edef\p_page_injections_state{\pageinjectionparameter\c!state}%
92   \edef\p_page_injections_delay{\pageinjectionparameter\c!delay}%
93   \edef\p_page_injections_page {\pageinjectionparameter\c!page }%
94   \ifx\p_page_injections_delay\v!yes
95     \expandafter\page_injections_direct_indeed_yes
96   \else
97     \expandafter\page_injections_direct_indeed_nop
98   \fi}
99
100\def\page_injections_direct_indeed_yes#parameters%
101  {\clf_savepageinjections
102         name {\currentpageinjection}%
103        state {\p_page_injections_state}%
104     userdata {\normalunexpanded{#parameters}}%
105   \relax
106   \endgroup}
107
108\def\page_injections_direct_indeed_nop#parameters%
109  {\ifx\p_page_injections_page\empty
110     \page
111   \else
112     \page[\p_page_injections_page]%
113   \fi
114   \getdummyparameters[#parameters]%
115   \page_injections_place
116   \endgroup}
117
118% \def\page_injections_place
119%   {\edef\currentpageinjectionalternative          {\pageinjectionparameter           \c!alternative   }%
120%    \edef\p_page_injectionalternative_rederingsetup{\pageinjectionalternativeparameter\c!renderingsetup}%
121%    \page_injections_nextpage
122%    \ifx\currentpageinjectionalternative\v!none \else % increment counter but don’t generate output
123%      \invokepagehandler\v!normal{\inheritedpageinjectionframed{\texsetup\p_page_injectionalternative_rederingsetup}}%
124%    \fi}
125
126\def\page_injections_place
127  {\edef\currentpageinjectionalternative          {\pageinjectionparameter           \c!alternative   }%
128   \edef\p_page_injectionalternative_rederingsetup{\pageinjectionalternativeparameter\c!renderingsetup}%
129   \page_injections_nextpage
130   \ifx\currentpageinjectionalternative\v!none \else % increment counter but don’t generate output
131     \forgetparindent
132     \dontcomplain
133     \setconstant\shipoutfinalizemethod\zerocount % this is messy
134     \page_injections_flush_indeed
135   \fi}
136
137\def\page_injections_nextpage
138  {\edef\p_page_injections_pagestate{\pageinjectionparameter\c!pagestate}%
139   \ifx\p_page_injections_pagestate\v!stop \else
140     \edef\p_page_injections_n{\pageinjectionparameter\c!n}%
141     \ifx\p_page_injections_n\empty
142        \let\p_page_injections_n\plusone
143     \fi
144     \dorecurse\p_page_injections_n
145       {\incrementcounter[\s!realpage]%
146        \incrementcounter[\s!userpage]}%
147   \fi}
148
149\definepageinjectionalternative[\v!figure][\c!renderingsetup=\??pageinjectionrenderings:\v!figure]
150\definepageinjectionalternative[\v!buffer][\c!renderingsetup=\??pageinjectionrenderings:\v!buffer]
151\definepageinjectionalternative[\v!setups][\c!renderingsetup=\??pageinjectionrenderings:\s!setup ]
152
153\startsetups[\??pageinjectionrenderings:\v!figure]
154    \dontleavehmode\externalfigure[\dummyparameter\c!name][\c!factor=\v!max]
155\stopsetups
156
157\startsetups[\??pageinjectionrenderings:\s!setup]
158    \setups[\dummyparameter\c!setups]% kind of redundant but fits in
159\stopsetups
160
161\startsetups[\??pageinjectionrenderings:\v!buffer]
162    \getbuffer[\dummyparameter\c!name]%
163\stopsetups
164
165% \setuppaper
166%   [\c!method=\v!pageinjection]
167
168\setuppageinjection
169  [      \c!width=\paperwidth,
170        \c!height=\paperheight,
171         \c!frame=\v!off,
172        \c!offset=\v!overlay,
173         \c!delay=\v!no,
174         \c!state=\v!next,
175   \c!alternative=\v!figure]
176
177\definepageinjection[\v!previouspage][\c!delay=\v!yes,\c!state=\v!previous]
178\definepageinjection[\v!nextpage]    [\c!delay=\v!yes,\c!state=\v!next]
179\definepageinjection[\v!here]        % direct
180\definepageinjection[\v!empty]       [\c!alternative=\v!none]
181
182%definepageinjection[\v!chapter]     [\v!previouspage][\c!pagestate=\v!stop]
183
184\protect \endinput
185
186% \enabletrackers[pagebuilder.injections]
187%
188% \setuppageinjection[offset=2em]
189%
190% \definepageinjection[chapter][previouspage][pagestate=stop]
191% \definepageinjection[later]  [delay=yes,state=+2]
192%
193% \useMPlibrary[dum]
194%
195% \starttext
196%
197% \startchapter[title={Insert pages before/after the current page}]
198%
199% 	\dorecurse{10}{one: \input ward\par}
200%
201% 	\pageinjection[previouspage][name=dummy-1]
202%
203% 	\dorecurse{20}{two: \input ward\par} \page
204%
205% 	\pageinjection[nextpage][name=dummy-2]
206%  	\pageinjection[later]   [name=dummy-4]
207%  	\pageinjection[delay=yes,state=+2][name=dummy-5]
208%
209% 	\dorecurse{100}{three: \input ward\par}
210%
211% \stopchapter
212%
213% \startbuffer[whatever]
214%     \dorecurse{10}{whatever #1 }
215% \stopbuffer
216%
217% \startchapter[title={Insert pages at the current location}]
218%
219% 	\dorecurse{10}{\input ward\par}
220%
221% 	\pageinjection[direct][name=dummy-3]
222% 	\pageinjection[direct][alternative=buffer,name=whatever]
223%
224% 	\dorecurse{10}{\input ward\par}
225%
226% \stopchapter
227%
228% \setuphead
229%   [chapter]
230%   [beforesection={\pageinjection[empty]},
231%    insidesection={\pageinjection[chapter][name=\structureuservariable{image}]}]
232%
233% \startchapter[title={Combine both mechanism}][name=dummy-4]
234%
235% 	\dorecurse{10}{\input ward\par}
236%
237% \stopchapter
238%
239% \stoptext
240