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\unprotect
50
51\installcorenamespace {background}
52
53\installframedcommandhandler \??background {background} \??background
54
55
56
57
58
59
60
61
62
63
64
65\setnewconstant\backgroundsplitmode\plusthree
66
67\appendtoks
68 \frozen\protected\instance\defcsname\e!start\currentbackground\endcsname{\pack_backgrounds_start [\currentbackground]}
69 \frozen\protected\instance\defcsname\e!stop \currentbackground\endcsname{\pack_backgrounds_stop }
70 \frozen\protected\instance\defcsname \currentbackground\endcsname{\pack_backgrounds_direct[\currentbackground]}
71\to \everydefinebackground
72
73\protected\def\pack_backgrounds_start[#tag]
74 {\endgraf
75 \begingroup
76 \cdef\currentbackground{#tag}
77 \ifcstok{\backgroundparameter\c!state}\v!start
78 \expandafter\pack_backgrounds_start_indeed
79 \else
80 \expandafter\pack_backgrounds_start_ignore
81 \fi}
82
83\tolerant\def\pack_backgrounds_start_indeed[#S#settings]
84 {\setupcurrentbackground[#settings,\c!state=\v!start,\c!offset=\v!overlay]
85 \let\pack_backgrounds_stop\pack_backgrounds_stop_indeed
86 \setbox\scratchboxone\vbox\bgroup
87 \strut
88 \vskip2\lineheight
89 \strut
90 \blank[\v!disable]
91 \leftskip \backgroundparameter\c!leftoffset
92 \rightskip\backgroundparameter\c!rightoffset}
93
94\tolerant\def\pack_backgrounds_start_ignore[#S#settings]
95 {\let\pack_backgrounds_stop\pack_backgrounds_stop_ignore}
96
97\let\pack_backgrounds_stop\relax
98
99\protected\def\pack_backgrounds_stop_indeed
100 {\endgraf
101 \removelastskip
102 \strut
103 \vskip2\lineheight
104 \strut
105
106 \ifdim\dimexpr\pagetotal2\lineheight\relax>\pagegoal
107 \page
108 \fi
109
110 \egroup
111 \scratchdistance\leftskip
112 \forgetall
113 \ifinsidefloat
114 \backgroundsplitmode\zerocount
115 \fi
116 \ifcase\backgroundsplitmode
117 \inheritedbackgroundframed{\box\scratchboxone}
118 \or
119 \hskip\scratchdistance
120 \inheritedbackgroundframed{\box\scratchboxone}
121 \else
122 \splitmaxdepth\boxmaxdepth
123 \splittopskip\topskip
124 \doloop
125 {\ifzeropt\pagetotal
126 \scratchdimen\textheight
127 \backgroundsplitmode\plusone
128 \else
129 \setbox\scratchdimentwo\vbox{\backgroundparameter\c!before}
130 \scratchdimen\dimexpr\pagegoal\ht\scratchdimentwo\pagetotal\relax
131 \backgroundsplitmode\plustwo
132 \fi
133 \ifdim\scratchdimen<\zeropoint
134 \scratchdimen\pagegoal
135 \fi
136 \advanceby\scratchdimen\dimexpr
137 \backgroundparameter\c!topoffset
138 \backgroundparameter\c!bottomoffset
139 \relax
140 \ifdim\scratchdimen>2\lineheight\relax
141 \ifdim\ht\scratchboxone>\scratchdimen
142 \setbox\scratchdimentwo\vsplit\scratchboxone to \scratchdimen
143 \else
144 \setbox\scratchdimentwo\box\scratchboxone
145 \backgroundsplitmode\zerocount
146 \fi
147 \setbox\scratchdimentwo\vbox \ifcase\backgroundsplitmode\or to \textheight \fi
148 {\vskip\backgroundparameter\c!topoffset
149 \unvcopy\scratchdimentwo
150 \prevdepth\dp\scratchdimentwo
151 \obeydepth
152 \vskip\backgroundparameter\c!bottomoffset
153 \vfill}
154 \backgroundparameter\c!before
155 \ifcase\backgroundsplitmode\or\or
156 \ifdim\pagegoal<\maxdimen
157 \pagegoal=1.2\pagegoal
158 \fi
159 \fi
160 \startlinecorrection
161 \ifnum\backgroundsplitmode=\plusthree
162 \hskip\scratchdistance
163 \fi
164 \inheritedbackgroundframed{\box\scratchdimentwo}
165 \stoplinecorrection
166 \ifcase\backgroundsplitmode
167 \backgroundparameter\c!after
168 \else
169 \page_otr_fill_and_eject_page
170 \fi
171 \else
172 \page
173 \fi
174 \ifdim\ht\scratchboxone>\zeropoint \else
175 \exitloop
176 \fi}
177 \fi
178 \endgroup
179 \endgraf}
180
181\protected\def\pack_backgrounds_stop_ignore
182 {\endgroup
183 \endgraf}
184
185\protected\def\pack_backgrounds_direct[#tag]
186 {\begingroup
187 \cdef\currentbackground{#tag}
188 \ifcstok{\backgroundparameter\c!state}\c!start
189 \expandafter\pack_backgrounds_direct_indeed
190 \else
191 \expandafter\pack_backgrounds_direct_ignore
192 \fi}
193
194\def\pack_backgrounds_direct_indeed
195 {\dowithnextboxcs\pack_backgrounds_direct_finish\vbox}
196
197\def\pack_backgrounds_direct_finish
198 {\setupcurrentbackground[\c!offset=\v!overlay]
199 \inheritedbackgroundframed{\flushnextbox}
200 \endgroup}
201
202\def\pack_backgrounds_direct_ignore
203 {\endgroup}
204
205\definebackground[\v!background]
206
207\ifdefined\startbackground \else
208 \permanent\expandafter\let\expandafter\startbackground\csname\e!start\v!background\endcsname
209 \permanent\expandafter\let\expandafter\stopbackground \csname\e!stop \v!background\endcsname
210 \permanent\expandafter\let\expandafter\background \csname \v!background\endcsname
211\fi
212
213\setupbackground
214 [\c!leftoffset=.5\bodyfontsize,
215 \c!rightoffset=\backgroundparameter\c!leftoffset,
216 \c!topoffset=\zeropoint,
217 \c!bottomoffset=\backgroundparameter\c!topoffset,
218 \c!state=\v!start,
219 \c!radius=.5\bodyfontsize,
220 \c!corner=\v!rectangular,
221 \c!frame=\v!off,
222 \c!depth=\zeropoint,
223
224 \c!background=\v!color,
225 \c!backgroundcolor=lightgray,
226 \c!before=,
227 \c!after=]
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249\protect \endinput
250 |