page-inj.mkvi /size: 8237 b    last modification: 2020-07-01 14:35
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
{
\scrn_canvas_synchronize_set
{
\pageinjectionparameter
\c!width
}{
\pageinjectionparameter
\c!height
}
%
37
\invokepagehandler
\v!normal
{
\inheritedpageinjectionframed
{
\texsetup
\p_page_injectionalternative_rederingsetup
}}
%
38
\scrn_canvas_synchronize_reset
}
39 40
\def
\page_injections_flush_saved
#
name
#
parameters
%
41
{
\begingroup
42
\edef
\currentpageinjection
{
#
name
}
%
43
\getdummyparameters
[#
parameters
]
%
44
\edef
\currentpageinjectionalternative
{
\pageinjectionparameter
\c!alternative
}
%
45
\edef
\p_page_injectionalternative_rederingsetup
{
\pageinjectionalternativeparameter
\c!renderingsetup
}
%
46
\page_injections_nextpage
47
\page_injections_flush_indeed
48
\endgroup
}
49 50
\unexpanded
\def
\pageinjection
51
{
\begingroup
52
\dodoubleempty
\page_injections_direct
}
53 54
\def
\page_injections_direct
[#
1
][#
2
]
% name parameters | settings parameters | name | parameters
55
{
\doifelseassignment
{
#
1
}
56
{
\doifelseassignment
{
#
2
}
57
{
\page_injections_direct_settings_parameters
{
#
1
}{
#
2
}}
58
{
\page_injections_direct_parameters
{
#
1
}}}
59
{
\doifelseassignment
{
#
2
}
60
{
\page_injections_direct_name_parameters
{
#
1
}{
#
2
}}
61
{
\page_injections_direct_name
{
#
1
}}}}
62 63
\def
\page_injections_direct_settings_parameters
#
settings
% #parameters%
64
{
\let
\currentpageinjection
\empty
65
\checkpageinjectionparent
66
\setupcurrentpageinjection
[#
settings
]
%
67
\page_injections_direct_indeed
}
68 69
\def
\page_injections_direct_parameters
% #parameters%
70
{
\let
\currentpageinjection
\empty
71
\checkpageinjectionparent
72
\page_injections_direct_indeed
}
73 74
\def
\page_injections_direct_name_parameters
#
name
% #parameters%
75
{
\edef
\currentpageinjection
{
#
name
}
%
76
\checkpageinjectionparent
77
\page_injections_direct_indeed
}
78 79
\def
\page_injections_direct_name
#
name
%
80
{
\edef
\currentpageinjection
{
#
name
}
%
81
\checkpageinjectionparent
82
\page_injections_direct_indeed
{}}
83 84
\def
\page_injections_direct_indeed
% #parameters%
85
{
\edef
\p_page_injections_state
{
\pageinjectionparameter
\c!state
}
%
86
\edef
\p_page_injections_delay
{
\pageinjectionparameter
\c!delay
}
%
87
\edef
\p_page_injections_page
{
\pageinjectionparameter
\c!page
}
%
88
\ifx
\p_page_injections_delay
\v!yes
89
\expandafter
\page_injections_direct_indeed_yes
90
\else
91
\expandafter
\page_injections_direct_indeed_nop
92
\fi
}
93 94
\def
\page_injections_direct_indeed_yes
#
parameters
%
95
{
\clf_savepageinjections
96
name
{
\currentpageinjection
}
%
97
state
{
\p_page_injections_state
}
%
98
userdata
{
\normalunexpanded
{
#
parameters
}}
%
99
\relax
100
\endgroup
}
101 102
\def
\page_injections_direct_indeed_nop
#
parameters
%
103
{
\ifx
\p_page_injections_page
\empty
104
\page
105
\else
106
\page
[
\p_page_injections_page
]
%
107
\fi
108
\getdummyparameters
[#
parameters
]
%
109
\page_injections_place
110
\endgroup
}
111 112
% \def\page_injections_place
113
% {\edef\currentpageinjectionalternative {\pageinjectionparameter \c!alternative }%
114
% \edef\p_page_injectionalternative_rederingsetup{\pageinjectionalternativeparameter\c!renderingsetup}%
115
% \page_injections_nextpage
116
% \ifx\currentpageinjectionalternative\v!none \else % increment counter but don’t generate output
117
% \invokepagehandler\v!normal{\inheritedpageinjectionframed{\texsetup\p_page_injectionalternative_rederingsetup}}%
118
% \fi}
119 120
\def
\page_injections_place
121
{
\edef
\currentpageinjectionalternative
{
\pageinjectionparameter
\c!alternative
}
%
122
\edef
\p_page_injectionalternative_rederingsetup
{
\pageinjectionalternativeparameter
\c!renderingsetup
}
%
123
\page_injections_nextpage
124
\ifx
\currentpageinjectionalternative
\v!none
\else
% increment counter but don’t generate output
125
\forgetparindent
126
\dontcomplain
127
\setconstant
\shipoutfinalizemethod
\zerocount
% this is messy
128
\page_injections_flush_indeed
129
\fi
}
130 131
\def
\page_injections_nextpage
132
{
\edef
\p_page_injections_pagestate
{
\pageinjectionparameter
\c!pagestate
}
%
133
\ifx
\p_page_injections_pagestate
\v!stop
\else
134
\edef
\p_page_injections_n
{
\pageinjectionparameter
\c!n
}
%
135
\ifx
\p_page_injections_n
\empty
136
\let
\p_page_injections_n
\plusone
137
\fi
138
\dorecurse
\p_page_injections_n
139
{
\incrementcounter
[
\s!realpage
]
%
140
\incrementcounter
[
\s!userpage
]
}
%
141
\fi
}
142 143
\definepageinjectionalternative
[
\v!figure
][
\c!renderingsetup
=
\??pageinjectionrenderings
:
\v!figure
]
144
\definepageinjectionalternative
[
\v!buffer
][
\c!renderingsetup
=
\??pageinjectionrenderings
:
\v!buffer
]
145
\definepageinjectionalternative
[
\v!setups
][
\c!renderingsetup
=
\??pageinjectionrenderings
:
\s!setup
]
146 147
\startsetups
[
\??pageinjectionrenderings
:
\v!figure
]
148
\dontleavehmode
\externalfigure
[
\dummyparameter
\c!name
][
\c!factor
=
\v!max
]
149
\stopsetups
150 151
\startsetups
[
\??pageinjectionrenderings
:
\s!setup
]
152
\setups
[
\dummyparameter
\c!setup
]
% kind of redundant but fits in
153
\stopsetups
154 155
\startsetups
[
\??pageinjectionrenderings
:
\v!buffer
]
156
\getbuffer
[
\dummyparameter
\c!name
]
%
157
\stopsetups
158 159
% \setuppaper
160
% [\c!method=\v!pageinjection]
161 162
\setuppageinjection
163
[
\c!width
=
\paperwidth
,
164
\c!height
=
\paperheight
,
165
\c!frame
=
\v!off
,
166
\c!offset
=
\v!overlay
,
167
\c!delay
=
\v!no
,
168
\c!state
=
\v!next
,
169
\c!alternative
=
\v!figure
]
170 171
\definepageinjection
[
\v!previouspage
][
\c!delay
=
\v!yes
,
\c!state
=
\v!previous
]
172
\definepageinjection
[
\v!nextpage
]
[
\c!delay
=
\v!yes
,
\c!state
=
\v!next
]
173
\definepageinjection
[
\v!here
]
% direct
174
\definepageinjection
[
\v!empty
]
[
\c!alternative
=
\v!none
]
175 176
%definepageinjection[\v!chapter] [\v!previouspage][\c!pagestate=\v!stop]
177 178
\protect
\endinput
179 180
% \enabletrackers[pagebuilder.injections]
181
%
182
% \setuppageinjection[offset=2em]
183
%
184
% \definepageinjection[chapter][previouspage][pagestate=stop]
185
% \definepageinjection[later] [delay=yes,state=+2]
186
%
187
% \useMPlibrary[dum]
188
%
189
% \starttext
190
%
191
% \startchapter[title={Insert pages before/after the current page}]
192
%
193
% \dorecurse{10}{one: \input ward\par}
194
%
195
% \pageinjection[previouspage][name=dummy-1]
196
%
197
% \dorecurse{20}{two: \input ward\par} \page
198
%
199
% \pageinjection[nextpage][name=dummy-2]
200
% \pageinjection[later] [name=dummy-4]
201
% \pageinjection[delay=yes,state=+2][name=dummy-5]
202
%
203
% \dorecurse{100}{three: \input ward\par}
204
%
205
% \stopchapter
206
%
207
% \startbuffer[whatever]
208
% \dorecurse{10}{whatever #1 }
209
% \stopbuffer
210
%
211
% \startchapter[title={Insert pages at the current location}]
212
%
213
% \dorecurse{10}{\input ward\par}
214
%
215
% \pageinjection[direct][name=dummy-3]
216
% \pageinjection[direct][alternative=buffer,name=whatever]
217
%
218
% \dorecurse{10}{\input ward\par}
219
%
220
% \stopchapter
221
%
222
% \setuphead
223
% [chapter]
224
% [beforesection={\pageinjection[empty]},
225
% insidesection={\pageinjection[chapter][name=\structureuservariable{image}]}]
226
%
227
% \startchapter[title={Combine both mechanism}][name=dummy-4]
228
%
229
% \dorecurse{10}{\input ward\par}
230
%
231
% \stopchapter
232
%
233
% \stoptext
234