page-bck.mkiv /size: 25 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=page-bck, % copied from main-001
3
%D version=1997.03.31,
4
%D title=\CONTEXT\ Page Macros,
5
%D subtitle=Backgrounds,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
% Currently the text cells are fakes and no (foreground) frames which makes sense
15
% as order might matter e.g. is text sticks in other cells. The page, text etc
16
% areas do support foreground order change.
17 18
\writestatus
{
loading
}{
ConTeXt
Page
Macros
/
Backgrounds
}
19 20
\unprotect
21 22
% maybe use \currentframedhash here
23 24
%D For special purposes, users can question the \type {*background} mode. This mode
25
%D is only available when typesetting the pagebody.
26
%D
27
%D \starttyping
28
%D \startmode[*background] ...
29
%D \stoptyping
30 31
\newconditional
\c_page_backgrounds_new
32
\newconditional
\c_page_backgrounds_new_right
33
\newconditional
\c_page_backgrounds_new_left
34
\newconditional
\c_page_backgrounds_some
35 36
\appendtoks
37
\ifconditional
\c_page_backgrounds_some
38
\ifconditional
\c_page_backgrounds_new
39
\setsystemmode
\v!background
40
\fi
41
\fi
42
\to
\everybeforepagebody
43 44
\unexpanded
\def
\initializepagebackgrounds
45
{
\setfalse
\c_page_backgrounds_new
46
\setfalse
\c_page_backgrounds_new_right
47
\setfalse
\c_page_backgrounds_new_left
48
\setfalse
\c_page_backgrounds_some
}
49 50
%D We keep calculations and checks to a minimum and also try to minimize
51
%D the amount of tracing due to expansion.
52 53
\let
\currentotrbackground
\empty
54 55
%D This is the only spot where we have a low level dependency on the way
56
%D parent chains are defined but we want the speed.
57 58
\unexpanded
\def
\page_backgrounds_check_background
59
{
\ifcsname
\??framed
\currentotrbackground
:
\c!background
\endcsname
60
%\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!background\endcsname}%
61
\edef
\page_background_temp
{
\lastnamedcs
}
%
62
\ifx
\page_background_temp
\empty
63
\expandafter\expandafter\expandafter
\page_backgrounds_check_frame
64
\else
65
\page_backgrounds_set_yes
66
\fi
67
\else
68
\expandafter
\page_backgrounds_check_frame
69
\fi
}
70 71
\def
\page_backgrounds_check_frame
72
{
\ifcsname
\??framed
\currentotrbackground
:
\c!frame
\endcsname
73
%\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!frame\endcsname}%
74
\edef
\page_background_temp
{
\lastnamedcs
}
%
75
\ifx
\page_background_temp
\v!on
76
\page_backgrounds_set_yes
77
\else
78
\expandafter\expandafter\expandafter
\page_backgrounds_check_leftframe
79
\fi
80
\else
81
\expandafter
\page_backgrounds_check_leftframe
82
\fi
}
83 84
\def
\page_backgrounds_check_leftframe
85
{
\ifcsname
\??framed
\currentotrbackground
:
\c!leftframe
\endcsname
86
%\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!leftframe\endcsname}%
87
\edef
\page_background_temp
{
\lastnamedcs
}
%
88
\ifx
\page_background_temp
\v!on
89
\page_backgrounds_set_yes
90
\else
91
\expandafter\expandafter\expandafter
\page_backgrounds_check_rightframe
92
\fi
93
\else
94
\expandafter
\page_backgrounds_check_rightframe
95
\fi
}
96 97
\def
\page_backgrounds_check_rightframe
98
{
\ifcsname
\??framed
\currentotrbackground
:
\c!rightframe
\endcsname
99
%\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!rightframe\endcsname}%
100
\edef
\page_background_temp
{
\lastnamedcs
}
%
101
\ifx
\page_background_temp
\v!on
102
\page_backgrounds_set_yes
103
\else
104
\expandafter\expandafter\expandafter
\page_backgrounds_check_topframe
105
\fi
106
\else
107
\expandafter
\page_backgrounds_check_topframe
108
\fi
}
109 110
\def
\page_backgrounds_check_topframe
111
{
\ifcsname
\??framed
\currentotrbackground
:
\c!topframe
\endcsname
112
%\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!topframe\endcsname}%
113
\edef
\page_background_temp
{
\lastnamedcs
}
%
114
\ifx
\page_background_temp
\v!on
115
\page_backgrounds_set_yes
116
\else
117
\expandafter\expandafter\expandafter
\page_backgrounds_check_bottomframe
118
\fi
119
\else
120
\expandafter
\page_backgrounds_check_bottomframe
121
\fi
}
122 123
\def
\page_backgrounds_check_bottomframe
124
{
\ifcsname
\??framed
\currentotrbackground
:
\c!bottomframe
\endcsname
125
%\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!bottomframe\endcsname}%
126
\edef
\page_background_temp
{
\lastnamedcs
}
%
127
\ifx
\page_background_temp
\v!on
128
\page_backgrounds_set_yes
129
\else
130
\page_backgrounds_set_nop
131
\fi
132
\else
133
\page_backgrounds_set_nop
134
\fi
}
135 136
%D We don't use the commandhandler code as we want these multitude of backgrounds to be
137
%D as fast as possible.
138 139
\installcorenamespace
{
layoutbackgrounds
}
140
\installcorenamespace
{
layoutbackgroundcheck
}
% we need another hash as \??layoutbackgrounds<...> gets defined
141 142
\def
\page_backgrounds_set_yes
{
\expandafter\let\csname
\currentotrbackground
\endcsname\relax
}
143
\def
\page_backgrounds_set_nop
{
\expandafter\let\csname
\currentotrbackground
\endcsname
\undefined
}
144 145
\unexpanded
\def
\page_backgrounds_check
#
1
%
146
{
\edef
\currentotrbackground
{
\??layoutbackgrounds
#
1
}
%
147
\page_backgrounds_check_background
}
148 149
\def
\doifelsesomebackground
#
1
%
150
{
\ifcsname
\??layoutbackgrounds
#
1
\endcsname
151
\expandafter
\firstoftwoarguments
152
\else
153
\expandafter
\secondoftwoarguments
154
\fi
}
155 156
\let
\doifsomebackgroundelse\doifelsesomebackground
157 158
\def
\doifsomebackground
#
1
%
159
{
\ifcsname
\??layoutbackgrounds
#
1
\endcsname
160
\expandafter
\firstofoneargument
161
\else
162
\expandafter
\gobbleoneargument
163
\fi
}
164 165
%D The background mechanism falls back on the \type {\framed} macro. This means
166
%D that all normal frame and overlay features can be used.
167 168
\def
\page_backgrounds_add_to_box
#
1
% area
169
{
\ifcsname
\??layoutbackgrounds
#
1
\endcsname
170
\expandafter
\page_backgrounds_add_to_box_indeed
171
\else
172
\expandafter
\gobblefourarguments
173
\fi
#
1
}
174 175
%D We don't need the dimensions here as this is a real framed but the question is:
176
%D do we indeed need a real framed or can we use a fake (i.e. no foreground, only
177
%D for hidden).
178 179
\def
\page_backgrounds_add_to_box_indeed
#
1
#
2
#
3
#
4
% area box width height / always non zero
180
{
\edef
\p_page_backgrounds_setups
{
\namedframedparameter
{
\??layoutbackgrounds
#
1
}
\c!setups
}
%
181
\ifx
\p_page_backgrounds_setups
\empty
\else
182
\doprocesslocalsetups
\p_page_backgrounds_setups
% should not produce funny spaces !
183
\fi
184
% #2 has the right dimensions already
185
\setbox
#
2
\hpack
{
\localbackgroundframed
{
\??layoutbackgrounds
#
1
}
#
1
#
2
}}
% a real framed (including foreground)
186 187 188
%D There are quite some backgrounds. At the bottom layer, there is the {\em
189
%D paper} background. This one is only used for special purposes, like
190
%D annotations to documents.
191 192
\def
\page_backgrounds_add_to_print
#
1
%
193
{
\page_backgrounds_add_to_box
\v!paper
#
1
\printpaperwidth
\printpaperheight
}
194 195
%D The page backgrounds can be put behind the {\em left page}, the {\em
196
%D right page} or {\em each page}. As with the paper background, these are
197
%D calculated on each page.
198 199
\def
\page_backgrounds_add_to_paper
#
1
%
200
{
\doifbothsidesoverruled
201
{
\page_backgrounds_add_to_box
\v!rightpage
#
1
\paperwidth
\paperheight
}
%
202
{
\page_backgrounds_add_to_box
\v!rightpage
#
1
\paperwidth
\paperheight
}
%
203
{
\page_backgrounds_add_to_box
\v!leftpage
#
1
\paperwidth
\paperheight
}
%
204
\page_backgrounds_add_to_box
\v!page
#
1
\paperwidth
\paperheight
}
205 206
%D Then there are the 25 areas that make up the layout: {\em top, header, text,
207
%D footer, bottom} times {\em left edge, left margin, text, right margin, right
208
%D edge}. These are only recalculated when they change or when the \type {status}
209
%D is set to \type {repeat}.
210 211
\newbox
\leftbackground
% todo: rename
212
\newbox
\rightbackground
% todo: rename
213 214
%D Finaly there is an aditional {\em text} background, again useful for
215
%D special purposes only. This one is calculated each time. The hidden
216
%D backgrounds are not meant for users!
217 218
\newconditional
\c_page_backgrounds_hidden_enabled
219 220
\def
\page_backgrounds_add_to_text
#
1
%
221
{
\ifconditional
\c_page_backgrounds_hidden_enabled
222
\page_backgrounds_add_to_box
\v!hidden
#
1
\makeupwidth
\textheight
% mine !
223
\fi
224
\page_backgrounds_add_to_box
\v!text
#
1
\makeupwidth
\textheight
}
225 226
%D The next couple of macros implement the area backgrounds. As said, these
227
%D are cached in dedicated boxes. The offsets and depth of the page are used
228
%D for alignment purposes.
229 230
%newdimen\pageoffset % bleed
231
%newdimen\pagedepth % built-in
232 233
%D We need a bit more clever mechanism in order to handle layers well.
234
%D This means that we cannot calculate both background at the same time
235
%D since something may have changed halfway a page.
236 237
%D Margin swapping has been simplified: see mkii code in case of regression.
238
%D Calculation is delayed till the page anyway so the state is known.
239 240
\def
\page_backgrounds_recalculate
241
{
\global
\settrue
\c_page_backgrounds_new
}
242 243
\def
\page_backgrounds_set_boxes
244
{
\ifconditional
\c_page_backgrounds_new
245
\page_backgrounds_set_boxes_r
246
\fi
247
\doifbothsides
248
\page_backgrounds_set_boxes_a
249
\page_backgrounds_set_boxes_b
250
\page_backgrounds_set_boxes_c
251
\ifx
\p_page_backgrounds_state
\v!repeat
\else
252
\global
\setfalse
\c_page_backgrounds_new
253
\fi
}
254 255
\def
\page_backgrounds_set_boxes_r
256
{
\global
\settrue
\c_page_backgrounds_new_right
257
\global
\settrue
\c_page_backgrounds_new_left
258
\global\setbox
\leftbackground
\emptybox
259
\global\setbox
\rightbackground
\emptybox
}
260 261
\def
\page_backgrounds_set_boxes_a
262
{
\ifconditional
\c_page_backgrounds_new_left
263
% \showmessage\m!layouts8\empty
264
\page_backgrounds_set_box
\leftbackground
% \conditionalfalse
265
\global
\setfalse
\c_page_backgrounds_new_left
266
\global
\setfalse
\c_page_backgrounds_new_right
267
\fi
}
268 269
\def
\page_backgrounds_set_boxes_b
270
{
\ifconditional
\c_page_backgrounds_new_left
271
% \showmessage\m!layouts8\empty
272
\page_backgrounds_set_box
\leftbackground
273
\global
\setfalse
\c_page_backgrounds_new_left
274
\fi
}
275 276
\def
\page_backgrounds_set_boxes_c
277
{
\ifconditional
\c_page_backgrounds_new_right
278
% \showmessage\m!layouts8\empty
279
\page_backgrounds_set_box
\rightbackground
280
\global
\setfalse
\c_page_backgrounds_new_right
281
\fi
}
282 283
\def
\page_backgrounds_add_to_main
#
1
% todo: dimension spec
284
{
\ifconditional
\c_page_backgrounds_some
285
\page_backgrounds_set_boxes
286
\setbox
#
1
\vpack
287
{
\offinterlineskip
288
\doifelsemarginswap
{
\copy
\leftbackground
}{
\copy
\rightbackground
}
%
289
\box
#
1
}
%
290
\fi
}
291 292
\newdimen
\pagebackgroundhoffset
% THESE WILL BECOME OBSOLETE
293
\newdimen
\pagebackgroundvoffset
294
\newdimen
\pagebackgroundoffset
% used elsewhere
295
\newdimen
\pagebackgrounddepth
296
\newdimen
\pagebackgroundcompensation
297 298
\def
\page_backgrounds_set_offsets
% used in menus (we can use ifcsname's here)
299
{
\ifconditional
\c_page_backgrounds_some
\ifconditional
\c_page_backgrounds_new
300
\page_backgrounds_set_offsets_indeed
% indirect, less tracing
301
\fi
\fi
}
302 303
\def
\page_backgrounds_set_offsets_indeed
304
{
\ifcsname
\??layoutbackgrounds\v!text\v!text
\endcsname
305
\page_backgrounds_set_offsets_yes
306
\else\ifcsname
\??layoutbackgrounds\v!text
\endcsname
307
\page_backgrounds_set_offsets_yes
308
\else
309
\page_backgrounds_set_offsets_nop
310
\fi\fi
}
311 312
\def
\page_backgrounds_set_offsets_nop
313
{
\global
\pagebackgroundhoffset
\zeropoint
314
\global
\pagebackgroundvoffset
\zeropoint
315
\global
\pagebackgrounddepth
\zeropoint
316
\global
\pagebackgroundcompensation
\zeropoint
}
317 318
\def
\page_backgrounds_set_offsets_yes
319
{
\global
\pagebackgroundoffset
\d_page_backgrounds_depth
320
\global
\pagebackgroundcompensation
\d_page_backgrounds_offset
\relax
321
\ifzeropt
\pagebackgroundcompensation
322
\page_backgrounds_set_offsets_nop
323
\else
324
\ifcsname
\??layoutbackgrounds\v!top\v!text
\endcsname
325
\global
\pagebackgroundhoffset
\zeropoint
326
\else\ifcsname
\??layoutbackgrounds\v!bottom\v!text
\endcsname
327
\global
\pagebackgroundhoffset
\zeropoint
328
\else
329
\global
\pagebackgroundhoffset
\pagebackgroundcompensation
330
\fi\fi
331
\ifcsname
\??layoutbackgrounds\v!text\v!rightedge
\endcsname
332
\global
\pagebackgroundvoffset
\zeropoint
333
\global
\pagebackgrounddepth
\zeropoint
334
\else\ifcsname
\??layoutbackgrounds\v!text\v!leftedge
\endcsname
335
\global
\pagebackgroundvoffset
\zeropoint
336
\global
\pagebackgrounddepth
\zeropoint
337
\else
338
\global
\pagebackgroundvoffset
\pagebackgroundcompensation
339
\global
\pagebackgrounddepth
\d_page_backgrounds_depth
340
\fi\fi
341
\fi
}
342 343
\appendtoks
344
\page_backgrounds_set_offsets
345
\to
\everybeforepagebody
346 347
\newconditional
\swapbackgroundmargins
\settrue
\swapbackgroundmargins
348 349
\def
\page_backgrounds_set_box
#
1
% #2%
350
{
\global\setbox
#
1
\vpack
351
{
\dontcomplain
352
\swapmargins
353
\ifconditional
\swapbackgroundmargins
354
\doifelsemarginswap
\donothing
355
{
\swapmacros
\v!rightmargin\v!leftmargin
356
\swapmacros
\v!rightedge
\v!leftedge
}
%
357
\fi
358
\calculatereducedvsizes
359
\offinterlineskip
360
% \ifconditional#2\relax
361
% \doswapmargins % hm, this one gets nilled in \swapmargins anyway
362
% \fi
363
\ifdim
\topheight
>
\zeropoint
364
\kern\dimexpr
-
\topheight
-
\topdistance
\relax
365
\page_backgrounds_set_box_row
\v!top
\topheight
366
\kern
\topdistance
367
\fi
368
\ifdim
\headerheight
>
\zeropoint
369
\page_backgrounds_set_box_row
\v!header
\headerheight
370
\kern
\headerdistance
371
\fi
372
\ifdim
\textheight
>
\zeropoint
373
\page_backgrounds_set_box_row
\v!text
\textheight
374
\fi
375
\ifdim
\footerheight
>
\zeropoint
376
\kern
\footerdistance
377
\page_backgrounds_set_box_row
\v!footer
\footerheight
378
\fi
379
\ifdim
\bottomheight
>
\zeropoint
380
\kern
\bottomdistance
381
\page_backgrounds_set_box_row
\v!bottom
\bottomheight
382
\fi
383
\vfilll
}
%
384
\smashbox
#
1
}
385 386
\def
\page_backgrounds_set_box_row
#
1
#
2
% maybe helper
387
{
\setbox
\scratchbox
\vpack
to
#
2
388
\bgroup
\hpack
\bgroup
389
\goleftonpage
390
\ifdim
\leftedgewidth
>
\zeropoint
391
\ifcsname
\??layoutbackgrounds
#
1
\v!leftedge
\endcsname
392
\page_backgrounds_set_box_cell
#
1
\v!leftedge
\leftedgewidth
#
2
%
393
\else
394
\kern
\leftedgewidth
395
\fi
396
\kern
\leftedgedistance
397
\fi
398
\ifdim
\leftmarginwidth
>
\zeropoint
399
\ifcsname
\??layoutbackgrounds
#
1
\v!leftmargin
\endcsname
400
\page_backgrounds_set_box_cell
#
1
\v!leftmargin
\leftmarginwidth
#
2
%
401
\else
402
\kern
\leftmarginwidth
403
\fi
404
\kern
\leftmargindistance
405
\fi
406
\ifcsname
\??layoutbackgrounds
#
1
\v!text
\endcsname
407
\page_backgrounds_set_box_cell
#
1
\v!text
\makeupwidth
#
2
%
408
\else
409
\kern
\makeupwidth
410
\fi
411
\ifdim
\rightmarginwidth
>
\zeropoint
412
\kern
\rightmargindistance
413
\ifcsname
\??layoutbackgrounds
#
1
\v!rightmargin
\endcsname
414
\page_backgrounds_set_box_cell
#
1
\v!rightmargin
\rightmarginwidth
#
2
%
415
\else
416
\kern
\rightmarginwidth
417
\fi
418
\fi
419
\ifdim
\rightedgewidth
>
\zeropoint
420
\kern
\rightedgedistance
421
\ifcsname
\??layoutbackgrounds
#
1
\v!rightedge
\endcsname
422
\page_backgrounds_set_box_cell
#
1
\v!rightedge
\rightedgewidth
#
2
%
423
\else
424
\kern
\rightedgewidth
425
\fi
426
\fi
427
\egroup\egroup
428
\wd
\scratchbox
\zeropoint
429
\box
\scratchbox
\relax
}
430 431
% these are fake framed .. maybe it's nicer to honor foreground here as well
432
% but it's probably a slow downer
433 434
\def
\page_backgrounds_set_box_cell
#
1
#
2
#
3
#
4
% pos pos width height
435
{
\begingroup
436
\edef
\p_page_backgrounds_setups
{
\namedframedparameter
{
\??layoutbackgrounds
#
1
#
2
}
\c!setups
}
%
437
\ifx
\p_page_backgrounds_setups
\empty
\else
438
\doprocesslocalsetups
\p_page_backgrounds_setups
% should not produce funny spaces !
439
\fi
440
\edef
\p_page_backgrounds_command
{
\namedframedparameter
{
\??layoutbackgrounds
#
1
#
2
}
\c!command
}
%
441
\ifx
\p_page_backgrounds_command
\empty
442
\expandafter
\page_backgrounds_set_box_cell_nop
443
\else
444
\expandafter
\page_backgrounds_set_box_cell_yes
445
\fi
#
3
#
4
%
446
\localbackgroundframed
{
\??layoutbackgrounds
#
1
#
2
}{
#
1
:
#
2
}
\scratchbox
447
\endgroup
}
448 449
\def
\page_backgrounds_set_box_cell_nop
#
1
#
2
%
450
{
\setbox
\scratchbox
\emptyvbox
451
\wd
\scratchbox
#
1
%
452
\ht
\scratchbox
#
2
}
453 454
\def
\page_backgrounds_set_box_cell_yes
#
1
#
2
%
455
{
\setbox
\scratchbox
\vpack
to
#
2
{
\vss\hpack
to
#
1
{
\hss
\p_page_backgrounds_command
\hss
}
\vss
}
%
456
\dp
\scratchbox
\zeropoint
}
457 458
%D The background mechanism is quite demanding in terms or resources. We used to
459
%D delay these definitions till runtime usage, but since today's \TEX's are large,
460
%D we now do the work on forehand.
461
%D
462
%D \starttyping
463
%D \setupbackgrounds [settings]
464
%D \setupbackgrounds [paper,page,text,..] [settings]
465
%D \setupbackgrounds [top,...] [leftedge,...] [settings]
466
%D \stoptyping
467
%D
468
%D \showsetup{setupbackgrounds}
469
%D
470
%D Because the number of arguments runs from one to three, we need to check
471
%D for it.
472 473
\newtoks
\everybackgroundssetup
474 475
\unexpanded
\def
\setupbackgrounds
476
{
\dotripleempty
\page_backgrounds_setup
}
477 478
\def
\page_backgrounds_setup
479
{
\ifthirdargument
480
\expandafter
\page_backgrounds_setup_double
481
\else
\ifsecondargument
482
\doubleexpandafter
\page_backgrounds_setup_single
483
\else
\iffirstargument
484
\tripleexpandafter
\page_backgrounds_setup_basics
485
\fi\fi\fi
}
486 487
\newdimen
\d_page_backgrounds_offset
488
\newdimen
\d_page_backgrounds_depth
489 490
\appendtoks
491
\edef
\p_page_backgrounds_offset
{
\namedframedparameter
{
\??layoutbackgrounds\v!page
}
\c!offset
}
%
492
\edef
\p_page_backgrounds_depth
{
\namedframedparameter
{
\??layoutbackgrounds\v!page
}
\c!depth
}
%
493
\edef
\p_page_backgrounds_state
{
\namedframedparameter
{
\??layoutbackgrounds
}
\c!state
}
%
494
\global
\d_page_backgrounds_offset
\ifx
\p_offset
\empty\zeropoint
\else
\p_page_backgrounds_offset
\fi
495
\global
\d_page_backgrounds_depth
\ifx
\p_depth
\empty\zeropoint
\else
\p_page_backgrounds_depth
\fi
496
\global
\pagebackgroundoffset
\d_page_backgrounds_offset
\relax
497
\global
\pagebackgrounddepth
\d_page_backgrounds_depth
\relax
498
\ifx
\p_page_backgrounds_state
\v!stop
499
\global
\setfalse
\c_page_backgrounds_new
500
\else
501
\global
\settrue
\c_page_backgrounds_new
502
\fi
503
\to
\everybackgroundssetup
504 505
\def
\v_page_backgrounds_double_set
{
\v!paper
,
\v!page
,
\v!leftpage
,
\v!rightpage
}
506
\def
\v_page_backgrounds_single_set
{
\v!text
,
\v!hidden
,
\v!paper
,
\v!page
,
\v!leftpage
,
\v!rightpage
}
507
\def
\v_page_backgrounds_common_set
{
\v!leftedge
,
\v!leftmargin
,
\v!text
,
\v!rightmargin
,
\v!rightedge
}
508 509
\unexpanded
\def
\page_backgrounds_setup_double
[#
1
][#
2
][#
3
]
% if needed we can speed this up
510
{
\global
\settrue
\c_page_backgrounds_some
511
\def
\page_backgrounds_setup_step
##
1
%
512
{
\doifelseinset
{
##
1
}
\v_page_backgrounds_double_set
513
{
\page_backgrounds_setup_and_check
{
##
1
}{
#
3
}}
514
{
\def
\page_backgrounds_setup_step_nested
####
1
{
\page_backgrounds_setup_and_check
{
##
1
####
1
}{
#
3
}}
%
515
\processcommacommand
[#
2
]
\page_backgrounds_setup_step_nested
}}
%
516
\processcommacommand
[#
1
]
\page_backgrounds_setup_step
517
\the
\everybackgroundssetup
}
518 519
\unexpanded
\def
\page_backgrounds_setup_single
[#
1
][#
2
][#
3
]
%
520
{
\global
\settrue
\c_page_backgrounds_some
521
\doifelsecommon
{
#
1
}
\v_page_backgrounds_single_set
522
{
\def
\page_backgrounds_setup_step
##
1
{
\page_backgrounds_setup_and_check
{
##
1
}{
#
2
}}
%
523
\processcommacommand
[#
1
]
\page_backgrounds_setup_step
524
\the
\everybackgroundssetup
}
%
525
{
\page_backgrounds_setup_double
[#
1
][
\v_page_backgrounds_common_set
][#
2
]
}}
526 527
\unexpanded
\def
\page_backgrounds_setup_basics
[#
1
][#
2
][#
3
]
%
528
{
\setupframed
[
\??layoutbackgrounds
][#
1
]
%
529
\the
\everybackgroundssetup
}
530 531
\unexpanded
\def
\page_backgrounds_setup_and_check
#
1
#
2
% tag settings
532
{
\edef
\currentotrbackground
{
\??layoutbackgrounds
#
1
}
%
533
\setupframed
[
\currentotrbackground
][#
2
]
%
534
\page_backgrounds_check_background
}
535 536
%D Each areas (currently there are $1+3+25+1=30$ of them) has its own low level
537
%D framed object associated.
538 539
\definesimplifiedframed
[
\??layoutbackgrounds\v!paper
]
540
\definesimplifiedframed
[
\??layoutbackgrounds\v!page
]
541
\definesimplifiedframed
[
\??layoutbackgrounds\v!leftpage
]
542
\definesimplifiedframed
[
\??layoutbackgrounds\v!rightpage
]
543 544
\definesimplifiedframed
[
\??layoutbackgrounds\v!text
]
545
\definesimplifiedframed
[
\??layoutbackgrounds\v!hidden
]
546 547
\definesimplifiedframed
[
\??layoutbackgrounds\v!top\v!leftedge
]
548
\definesimplifiedframed
[
\??layoutbackgrounds\v!top\v!leftmargin
]
549
\definesimplifiedframed
[
\??layoutbackgrounds\v!top\v!text
]
550
\definesimplifiedframed
[
\??layoutbackgrounds\v!top\v!rightmargin
]
551
\definesimplifiedframed
[
\??layoutbackgrounds\v!top\v!rightedge
]
552 553
\definesimplifiedframed
[
\??layoutbackgrounds\v!header\v!leftedge
]
554
\definesimplifiedframed
[
\??layoutbackgrounds\v!header\v!leftmargin
]
555
\definesimplifiedframed
[
\??layoutbackgrounds\v!header\v!text
]
556
\definesimplifiedframed
[
\??layoutbackgrounds\v!header\v!rightmargin
]
557
\definesimplifiedframed
[
\??layoutbackgrounds\v!header\v!rightedge
]
558 559
\definesimplifiedframed
[
\??layoutbackgrounds\v!text\v!leftedge
]
560
\definesimplifiedframed
[
\??layoutbackgrounds\v!text\v!leftmargin
]
561
\definesimplifiedframed
[
\??layoutbackgrounds\v!text\v!text
]
562
\definesimplifiedframed
[
\??layoutbackgrounds\v!text\v!rightmargin
]
563
\definesimplifiedframed
[
\??layoutbackgrounds\v!text\v!rightedge
]
564 565
\definesimplifiedframed
[
\??layoutbackgrounds\v!footer\v!leftedge
]
566
\definesimplifiedframed
[
\??layoutbackgrounds\v!footer\v!leftmargin
]
567
\definesimplifiedframed
[
\??layoutbackgrounds\v!footer\v!text
]
568
\definesimplifiedframed
[
\??layoutbackgrounds\v!footer\v!rightmargin
]
569
\definesimplifiedframed
[
\??layoutbackgrounds\v!footer\v!rightedge
]
570 571
\definesimplifiedframed
[
\??layoutbackgrounds\v!bottom\v!leftedge
]
572
\definesimplifiedframed
[
\??layoutbackgrounds\v!bottom\v!leftmargin
]
573
\definesimplifiedframed
[
\??layoutbackgrounds\v!bottom\v!text
]
574
\definesimplifiedframed
[
\??layoutbackgrounds\v!bottom\v!rightmargin
]
575
\definesimplifiedframed
[
\??layoutbackgrounds\v!bottom\v!rightedge
]
576 577
\setupbackgrounds
578
[
\v!page
]
579
[
\c!offset
=
\zeropoint
,
% hm, so we need to force overlay elsewhere
580
\c!depth
=
\zeropoint
]
581 582
%D General setup:
583 584
\setupbackgrounds
585
[
\c!state
=
\c!start
]
586 587
%D The hidden layer can be populated by extending the following comma separated
588
%D list. This only happens in core modules.
589 590
% todo page-2 .. page+2 achter pagina -> bleed
591
% spread-2 .. spread+2 achter spread -> spread (repeat 2 times)
592 593
\unexpanded
\def
\enablehiddenbackground
594
{
\global
\settrue
\c_page_backgrounds_hidden_enabled
595
\global
\settrue
\c_page_backgrounds_some
596
\page_backgrounds_recalculate
}
597 598
\unexpanded
\def
\disablehiddenbackground
599
{
\global
\setfalse
\c_page_backgrounds_hidden_enabled
}
600 601
\def
\hiddenbackgroundlist
602
{
\v!text
-
2
,
\v!text
-
1
,
\v!foreground
,
\v!text
+
1
,
\v!text
+
2
}
603 604
\defineoverlay
[
\v!text
-
2
][
\positionregionoverlay
\textanchor
{
\v!text
-
2
}
]
% no new anchor, we share text
605
\defineoverlay
[
\v!text
-
1
][
\positionregionoverlay
\textanchor
{
\v!text
-
1
}
]
606
\defineoverlay
[
\v!text
+
1
][
\positionregionoverlay
\textanchor
{
\v!text
+
1
}
]
607
\defineoverlay
[
\v!text
+
2
][
\positionregionoverlay
\textanchor
{
\v!text
+
2
}
]
608 609
\setupbackgrounds
610
[
\v!hidden
]
611
[
\c!background
=
\hiddenbackgroundlist
]
612 613
%D Because we haven't really set up backgrounds yet, we set the main efficiency
614
%D switch to false.
615 616
\setfalse
\c_page_backgrounds_some
617 618
%D Sometimes you have a document wide (page) background but need to overload it
619
%D locally. In such case (at least in my experience) the only values that get set
620
%D are the background and backgroundcolor (if set at all). A full inheritance chain
621
%D would complicate things because then we need to use named backgrounds which in
622
%D turn will make this mechanism slower. I considered independent local backgrounds
623
%D but that also complicates the code (not that much) but isolation means that we
624
%D need to set more parameters each time. The following simple approach proabbly
625
%D suits most usage.
626
%D
627
%D \starttyping
628
%D \starttext
629
%D \setupbackgrounds[page][background=color,backgroundcolor=red]
630
%D \input tufte \page
631
%D \setupbackgrounds[page][background=,backgroundcolor=]
632
%D \input tufte \page
633
%D \setupbackgrounds[page][background=color,backgroundcolor=red]
634
%D \input tufte \page
635
%D \pushbackground[page]
636
%D \setupbackgrounds[page][background=color,backgroundcolor=green]
637
%D \input tufte \page
638
%D \popbackground
639
%D \input tufte \page
640
%D \stoptext
641
%D \stoptyping
642 643
\unexpanded
\def
\pushbackground
[#
1
]
%
644
{
\pushmacro
\popbackground
645
\edef
\currentotrbackground
{
\??layoutbackgrounds
#
1
}
%
646
\unexpanded
\edef
\popbackground
647
{
\setupframed
648
[
\currentotrbackground
]
649
[
\c!background
=
\namedframedparameter
{
\currentotrbackground
}
\c!background
,
650
\c!backgroundcolor
=
\namedframedparameter
{
\currentotrbackground
}
\c!backgroundcolor
]
%
651
\page_backgrounds_check_background
652
\popmacro
\popbackground
}
%
653
\setupframed
654
[
\currentotrbackground
]
655
[
\c!background
=
,
\c!backgroundcolor
=]
%
656
\page_backgrounds_check_background
}
657 658
\let
\popbackground
\relax
659 660
\protect
\endinput
661 662
% %D The next series is used in local (for instance floating) backgrounds.
663
%
664
% \installsimplifiedframed{\??layoutbackgrounds\v!local}
665
%
666
% \getparameters
667
% [\??layoutbackgrounds\v!local]
668
% [\c!component=local,
669
% \c!background=\localbackgroundlist]
670
%
671
% \def\localbackgroundlist
672
% {\v!local-2,\v!local-1,\v!foreground,\v!local+1,\v!local+2}
673
%
674
% \defineoverlay[\v!local-2][\positionoverlay{\v!local-2}] % todo share
675
% \defineoverlay[\v!local-1][\positionoverlay{\v!local-1}]
676
% \defineoverlay[\v!local+1][\positionoverlay{\v!local+1}]
677
% \defineoverlay[\v!local+2][\positionoverlay{\v!local+2}]
678
%
679
% \def\page_backgrounds_add_local_to_box
680
% {\ifconditional\c_page_backgrounds_hidden_enabled
681
% \expandafter\page_backgrounds_add_local_to_box_indeed
682
% \else
683
% \expandafter\gobbleoneargument
684
% \fi}
685
%
686
% \def\page_backgrounds_add_local_to_box_indeed#1%
687
% {\setbox#1\hbox{\localbackgroundframed{\??layoutbackgrounds\v!local}\v!local#1}%
688
% \global\advance\localpositionnumber\plusone} % afterwards !
689
%
690
% \let\page_backgrounds_add_local_to_box\gobbleoneargument
691 692
% Test how previous macro behaves with depth:
693
%
694
% \startcolumnset
695
% \input tufte
696
% \placefigure{none}{\framed[lines=5]{xxx}}
697
% \input tufte
698
% \placefigure{none}{\starttabulate\NC test\nc test\NC\NR\stoptabulate}
699
% \input tufte
700
% \stopcolumnset
701 702