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\edefcsname\e!start\currentbackground\endcsname{\pack_backgrounds_start [\currentbackground]}
69 \frozen\protected\instance\edefcsname\e!stop \currentbackground\endcsname{\pack_backgrounds_stop }
70 \frozen\protected\instance\edefcsname \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 \glueexpr\backgroundparameter\c!leftoffset\relax
92 \rightskip\glueexpr\backgroundparameter\c!rightoffset\relax}
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{\pagetotal2\lineheight}>\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{\pagegoal\ht\scratchdimentwo\pagetotal}
131 \backgroundsplitmode\plustwo
132 \fi
133 \ifdim\scratchdimen<\zeropoint
134 \scratchdimen\pagegoal
135 \fi
136 \advanceby\scratchdimen{\backgroundparameter\c!topoffset\backgroundparameter\c!bottomoffset}
137 \ifdim\scratchdimen>2\lineheight\relax
138 \ifdim\ht\scratchboxone>\scratchdimen
139 \setbox\scratchdimentwo\vsplit\scratchboxone to \scratchdimen
140 \else
141 \setbox\scratchdimentwo\box\scratchboxone
142 \backgroundsplitmode\zerocount
143 \fi
144 \setbox\scratchdimentwo\vbox \ifcase\backgroundsplitmode\or to \textheight \fi
145 {\vskip{\backgroundparameter\c!topoffset}
146 \unvcopy\scratchdimentwo
147 \prevdepth\dp\scratchdimentwo
148 \obeydepth
149 \vskip{\backgroundparameter\c!bottomoffset}
150 \vfill}
151 \backgroundparameter\c!before
152 \ifcase\backgroundsplitmode\or\or
153 \ifdim\pagegoal<\maxdimen
154 \pagegoal=1.2\pagegoal
155 \fi
156 \fi
157 \startlinecorrection
158 \ifnum\backgroundsplitmode=\plusthree
159 \hskip\scratchdistance
160 \fi
161 \inheritedbackgroundframed{\box\scratchdimentwo}
162 \stoplinecorrection
163 \ifcase\backgroundsplitmode
164 \backgroundparameter\c!after
165 \else
166 \page_otr_fill_and_eject_page
167 \fi
168 \else
169 \page
170 \fi
171 \ifdim\ht\scratchboxone>\zeropoint \else
172 \exitloop
173 \fi}
174 \fi
175 \endgroup
176 \endgraf}
177
178\protected\def\pack_backgrounds_stop_ignore
179 {\endgroup
180 \endgraf}
181
182\protected\def\pack_backgrounds_direct[#tag]
183 {\begingroup
184 \cdef\currentbackground{#tag}
185 \ifcstok{\backgroundparameter\c!state}\c!start
186 \expandafter\pack_backgrounds_direct_indeed
187 \else
188 \expandafter\pack_backgrounds_direct_ignore
189 \fi}
190
191\def\pack_backgrounds_direct_indeed
192 {\dowithnextboxcs\pack_backgrounds_direct_finish\vbox}
193
194\def\pack_backgrounds_direct_finish
195 {\setupcurrentbackground[\c!offset=\v!overlay]
196 \inheritedbackgroundframed{\flushnextbox}
197 \endgroup}
198
199\def\pack_backgrounds_direct_ignore
200 {\endgroup}
201
202\definebackground[\v!background]
203
204\ifdefined\startbackground \else
205 \permanent\expandafter\let\expandafter\startbackground\csname\e!start\v!background\endcsname
206 \permanent\expandafter\let\expandafter\stopbackground \csname\e!stop \v!background\endcsname
207 \permanent\expandafter\let\expandafter\background \csname \v!background\endcsname
208\fi
209
210\setupbackground
211 [\c!leftoffset=.5\bodyfontsize,
212 \c!rightoffset=\backgroundparameter\c!leftoffset,
213 \c!topoffset=\zeropoint,
214 \c!bottomoffset=\backgroundparameter\c!topoffset,
215 \c!state=\v!start,
216 \c!radius=.5\bodyfontsize,
217 \c!corner=\v!rectangular,
218 \c!frame=\v!off,
219 \c!depth=\zeropoint,
220
221 \c!background=\v!color,
222 \c!backgroundcolor=lightgray,
223 \c!before=,
224 \c!after=]
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246\protect \endinput
247 |