1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Packaging Macros Simple Backgrounds}
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53\unprotect
54
55\installcorenamespace {background}
56
57\installframedcommandhandler \??background {background} \??background
58
59
60
61
62
63
64
65
66
67
68
69
70\setnewconstant\backgroundsplitmode\plusthree
71
72\appendtoks
73 \setuevalue{\e!start\currentbackground}{\pack_backgrounds_start [\currentbackground]}
74 \setuevalue{\e!stop \currentbackground}{\pack_backgrounds_stop }
75 \setuevalue {\currentbackground}{\pack_backgrounds_direct[\currentbackground]}
76\to \everydefinebackground
77
78\unexpanded\def\pack_backgrounds_start[#tag]
79 {\endgraf
80 \begingroup
81 \def\currentbackground{#tag}
82 \doifelse{\backgroundparameter\c!state}\v!start
83 {\dosingleempty\pack_backgrounds_start_indeed}
84 {\dosingleempty\pack_backgrounds_start_ignore}}
85
86\def\pack_backgrounds_start_indeed[#settings]
87 {\setupcurrentbackground[#settings,\c!state=\v!start,\c!offset=\v!overlay]
88 \let\pack_backgrounds_stop\pack_backgrounds_stop_indeed
89 \setbox0\vbox\bgroup
90 \strut
91 \vskip2\lineheight
92 \strut
93 \blank[\v!disable]
94 \leftskip \backgroundparameter\c!leftoffset
95 \rightskip\backgroundparameter\c!rightoffset}
96
97\def\pack_backgrounds_start_ignore[#settings]
98 {\let\pack_backgrounds_stop\pack_backgrounds_stop_ignore}
99
100\let\pack_backgrounds_stop\relax
101
102\unexpanded\def\pack_backgrounds_stop_indeed
103 {\endgraf
104 \removelastskip
105 \strut
106 \vskip2\lineheight
107 \strut
108
109 \ifdim\dimexpr\pagetotal2\lineheight\relax>\pagegoal
110 \page
111 \fi
112
113 \egroup
114 \dimen2\leftskip
115 \forgetall
116 \ifinsidefloat
117 \backgroundsplitmode\zerocount
118 \fi
119 \ifcase\backgroundsplitmode
120 \inheritedbackgroundframed{\box0}
121 \or
122 \hskip\dimen2
123 \inheritedbackgroundframed{\box0}
124 \else
125 \splitmaxdepth\boxmaxdepth
126 \splittopskip\topskip
127 \doloop
128 {\ifzeropt\pagetotal
129 \scratchdimen\textheight
130 \backgroundsplitmode\plusone
131 \else
132 \setbox2\vbox{\backgroundparameter\c!before}
133 \scratchdimen\dimexpr\pagegoal\ht2\pagetotal\relax
134 \backgroundsplitmode\plustwo
135 \fi
136 \ifdim\scratchdimen<\zeropoint
137 \scratchdimen\pagegoal
138 \fi
139 \advance\scratchdimen\dimexpr
140 \backgroundparameter\c!topoffset
141 \backgroundparameter\c!bottomoffset
142 \relax
143 \ifdim\scratchdimen>2\lineheight\relax
144 \ifdim\ht0>\scratchdimen
145 \setbox2\vsplit0 to \scratchdimen
146 \else
147 \setbox2\box0
148 \backgroundsplitmode\zerocount
149 \fi
150 \setbox2\vbox \ifcase\backgroundsplitmode\or to \textheight \fi
151 {\vskip\backgroundparameter\c!topoffset
152 \unvcopy2
153 \prevdepth\dp2
154 \obeydepth
155 \vskip\backgroundparameter\c!bottomoffset
156 \vfill}
157 \backgroundparameter\c!before
158 \ifcase\backgroundsplitmode\or\or
159 \ifdim\pagegoal<\maxdimen
160 \pagegoal=1.2\pagegoal
161 \fi
162 \fi
163 \startlinecorrection
164 \ifnum\backgroundsplitmode=\plusthree
165 \hskip\dimen2
166 \fi
167 \inheritedbackgroundframed{\box2}
168 \stoplinecorrection
169 \ifcase\backgroundsplitmode
170 \backgroundparameter\c!after
171 \else
172 \page_otr_fill_and_eject_page
173 \fi
174 \else
175 \page
176 \fi
177 \ifdim\ht0>\zeropoint \else
178 \exitloop
179 \fi}
180 \fi
181 \endgroup
182 \endgraf}
183
184\unexpanded\def\pack_backgrounds_stop_ignore
185 {\endgroup
186 \endgraf}
187
188\unexpanded\def\pack_backgrounds_direct[#tag]
189 {\begingroup
190 \def\currentbackground{#tag}
191 \doifelse{\backgroundparameter\c!state}\c!start
192 \pack_backgrounds_direct_indeed
193 \pack_backgrounds_direct_ignore}
194
195\def\pack_backgrounds_direct_indeed
196 {\dowithnextboxcs\pack_backgrounds_direct_finish\vbox}
197
198\def\pack_backgrounds_direct_finish
199 {\setupcurrentbackground[\c!offset=\v!overlay]
200 \inheritedbackgroundframed{\flushnextbox}
201 \endgroup}
202
203\def\pack_backgrounds_direct_ignore
204 {\endgroup}
205
206\definebackground[\v!background]
207
208\ifdefined\startbackground \else
209 \expandafter\let\expandafter\startbackground\csname\e!start\v!background\endcsname
210 \expandafter\let\expandafter\stopbackground \csname\e!stop \v!background\endcsname
211 \expandafter\let\expandafter\background \csname \v!background\endcsname
212\fi
213
214\setupbackground
215 [\c!leftoffset=.5\bodyfontsize,
216 \c!rightoffset=\backgroundparameter\c!leftoffset,
217 \c!topoffset=\zeropoint,
218 \c!bottomoffset=\backgroundparameter\c!topoffset,
219 \c!state=\v!start,
220 \c!radius=.5\bodyfontsize,
221 \c!corner=\v!rectangular,
222 \c!frame=\v!off,
223 \c!depth=\zeropoint,
224
225 \c!background=\v!color,
226 \c!backgroundcolor=lightgray,
227 \c!before=,
228 \c!after=]
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291\protect \endinput
292 |