pack-lyr.mkxl /size: 28 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=pack-lyr,
3
%D version=2000.10.20,
4
%D title=\CONTEXT\ Packaging Macros,
5
%D subtitle=Layers,
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
\writestatus
{
loading
}{
ConTeXt
Packaging
Macros
/
Layers
}
15 16
% todo : first / last / next / +... => page key
17
% test on left/right box when no doublesided option given
18
% use \ifcsname instead of doifvalue
19 20
\unprotect
21 22
% When being backgrounds layers get the background offset displacement. Should be
23
% an option, on by default (compatibility).
24 25
%D The layering mechanism implemented here is independent of the output routine, but
26
%D future extensions may depend on a more close cooperation.
27
%D
28
%D First we overload a macro from \type {pack-rul}. From now on we accept a
29
%D (optional) argument: the specific layer it will go in. This means that we can
30
%D move an overlay from one background to the other using the dimensions of the
31
%D parent.
32 33
\ifdefined
\defineoverlay
\else
\message
{
loaded
to
early
}
\wait
\fi
34 35
\unexpanded
\def
\defineoverlay
36
{
\dotripleempty
\pack_framed_define_overlay
}
37 38
\def
\pack_framed_define_overlay
[#
1
][#
2
][#
3
]
% overlay [layer] content
39
{
\ifthirdargument
40
%\writestatus{BEWARE}{This (overlay definition) has changed!}% temp
41
\def
\pack_framed_define_overlay_indeed
##
1
{
\setvalue
{
\??overlay
##
1
}{
\setlayer
[#
2
]
{
\executedefinedoverlay
{
##
1
}{
#
3
}}}}
%
42
\else
43
\def
\pack_framed_define_overlay_indeed
##
1
{
\setvalue
{
\??overlay
##
1
}{
\executedefinedoverlay
{
##
1
}{
#
2
}}}
%
44
\fi
45
\processcommalist
[#
1
]
\pack_framed_define_overlay_indeed
}
46 47
%D We use the command handler code. The previous, more direct parameter handling was
48
%D 25\% faster when no parameters were passed when adding content to a layer.
49
%D However, when we pass for instance a preset, the new methos is some 10\% faster
50
%D and it happens that in most cases we do pass some parameters. It would be
51
%D interesting to see if we can push the preset in between the regular chain but it
52
%D could also lead to unwanted side effects when nesting layer placement.
53 54
\installcorenamespace
{
layer
}
55
\installcorenamespace
{
layerbox
}
56
\installcorenamespace
{
layerpreset
}
57
\installcorenamespace
{
layerposition
}
% brr, unreadable
58 59
%D \macros
60
%D {definelayer,setuplayer}
61
%D
62
%D Each layer gets its own (global) box. This also means that the data that goes
63
%D into a layer, is typeset immediately. Each layer automatically gets an associated
64
%D overlay, which can be used in any background assignment.
65
%D
66
%D After a layer is defined, you can change its characteristics.
67 68
\installcommandhandler
\??layer
{
layer
}
\??layer
69 70
\setuplayer
71
[
\c!state
=
\v!start
,
72
%\c!doublesided=,
73
%\c!preset=,
74
%\c!option=,
75
%\c!corner=,
76
%\c!page=,
77
%\c!rotation=, % geen 0 !
78
\c!direction
=
\v!normal
,
79
\c!position
=
\v!no
,
80
\c!method
=
\v!overlay
,
81
\c!x
=
\zeropoint
,
82
\c!y
=
\zeropoint
,
83
\c!line
=
0
,
84
\c!column
=
0
,
85
\c!width
=
\wd
\nextbox
,
% don't change this globally
86
\c!height
=
\ht
\nextbox
,
% don't change this globally
87
\c!offset
=
\zeropoint
,
88
\c!hoffset
=
\zeropoint
,
89
\c!voffset
=
\zeropoint
,
90
\c!dx
=
\zeropoint
,
91
\c!dy
=
\zeropoint
,
92
\c!location
=
rb
,
93
\c!sx
=
1
,
94
\c!sy
=
1
,
95
\c!region
=
\layeranchor
]
96 97
\def
\layeranchor
{
\currentlayer
:
\the
\realpageno
}
98 99
\let
\p_pack_layers_doublesided
\empty
100
\let
\p_pack_layers_state
\empty
101
\let
\p_pack_layers_option
\empty
102
\let
\p_pack_layers_method
\empty
103
\let
\p_pack_layers_preset
\empty
104
\let
\p_pack_layers_rotation
\empty
105
\let
\p_pack_layers_position
\empty
106
\let
\p_pack_layers_hoffset
\empty
107
\let
\p_pack_layers_voffset
\empty
108
\let
\p_pack_layers_offset
\empty
109
\let
\p_pack_layers_dx
\empty
110
\let
\p_pack_layers_dy
\empty
111
\let
\p_pack_layers_sx
\empty
112
\let
\p_pack_layers_sy
\empty
113
\let
\p_pack_layers_x
\empty
114
\let
\p_pack_layers_y
\empty
115
\let
\p_pack_layers_corner
\empty
116
\let
\p_pack_layers_location
\empty
117
\let
\p_pack_layers_line
\empty
118
\let
\p_pack_layers_column
\empty
119
\let
\p_pack_layers_width
\empty
120
\let
\p_pack_layers_height
\empty
121
\let
\p_pack_layers_direction
\empty
122
\let
\p_pack_layers_region
\empty
123 124
\let
\m_pack_layers_page
\empty
125
\let
\m_pack_layers_target
\empty
126
\let
\m_pack_layers_region
\empty
127
\let
\m_pack_layers_anchor
\empty
128 129
\newconditional
\c_pack_layers_repeated
130
\newconditional
\c_pack_layers_trace
131
\newcount
\c_pack_layers_current_data
132 133
\newbox
\b_layers
134 135
\newdimen
\d_pack_layers_x_size
136
\newdimen
\d_pack_layers_y_size
137
\newdimen
\d_pack_layers_x_offset
138
\newdimen
\d_pack_layers_y_offset
139
\newdimen
\d_pack_layers_x_position
140
\newdimen
\d_pack_layers_y_position
141 142
\newdimen
\layerwidth
143
\newdimen
\layerheight
144 145
\let
\lastlayerxpos
\!!zeropoint
146
\let
\lastlayerypos
\!!zeropoint
147
\let
\lastlayerwd
\!!zeropoint
148
\let
\lastlayerht
\!!zeropoint
149
\let
\lastlayerdp
\!!zeropoint
150 151
\appendtoks
152
\edef
\p_pack_layers_doublesided
{
\layerparameter
\c!doublesided
}
%
153
\ifx
\p_pack_layers_doublesided
\v!yes
154
\relateparameterhandlers
{
layer
}{
\v!left
\currentlayer
}{
layer
}
\currentlayer
% permits left*
155
\relateparameterhandlers
{
layer
}{
\v!right
\currentlayer
}{
layer
}
\currentlayer
% permits right*
156
\pack_layers_preset_box
{
\v!left
\currentlayer
}
%
157
\pack_layers_preset_box
{
\v!right
\currentlayer
}
%
158
\fi
159
\pack_layers_preset_box
\currentlayer
160
\normalexpanded
{
\defineoverlay
[
\currentlayer
][
\noexpand
\composedlayer
{
\currentlayer
}
]
}
%
161
\to
\everydefinelayer
162 163
\def
\pack_layers_preset_box
#
1
%
164
{
\ifcsname
\??layerbox
#
1
\endcsname
165
\resetlayer
[#
1
]
%
166
\else
167
\expandafter
\newbox
\csname
\??layerbox
#
1
\endcsname
168
\fi
}
169 170
%D \macros
171
%D {resetlayer}
172
%D
173
%D This macro hardly needs an explanation (but is seldom needed anyway).
174 175
\def
\pack_layers_reset_box
#
1
%
176
{
\ifcsname
\??layerbox
#
1
\endcsname
177
%\global\setbox\csname\??layerbox#1\endcsname\emptybox
178
\global\setbox\lastnamedcs
\emptybox
179
\fi
}
180 181
\def
\resetlayer
[#
1
]
%
182
{
\pack_layers_reset_box
{
#
1
}
%
183
\pack_layers_reset_box
{
\v!left
#
1
}
%
184
\pack_layers_reset_box
{
\v!right
#
1
}
%
185
\pack_layers_reset_box
{
#
1
:
\the
\realpageno
}}
186 187
%D \macros
188
%D {setlayer}
189
%D
190
%D Data is moved into a layer with the following macro. When \type {position} is
191
%D set, relative positioning is used, with the current point as reference point.
192
%D Otherwise the topleft corner is used as reference point.
193
%D
194
%D \starttyping
195
%D \setlayer [identifier] [optional parameters] {data}
196
%D \stoptyping
197 198
\def
\setcurrentlayerdimensions
199
{
\dodoubleempty
\pack_layers_set_current_dimensions
}
200 201
\def
\pack_layers_set_current_dimensions
[#
1
][#
2
]
% name left|right
202
{
\edef
\currentlayerwidth
{
\thelayerwidth
{
#
2
#
1
}}
%
203
\edef
\currentlayerheight
{
\thelayerheight
{
#
2
#
1
}}}
204 205
\def
\thelayerwidth
#
1
{
\the\ifcsname
\??layerbox
#
1
\endcsname\wd\lastnamedcs\else
\zeropoint
\fi
}
206
\def
\thelayerheight
#
1
{
\the\ifcsname
\??layerbox
#
1
\endcsname\ht\lastnamedcs\else
\zeropoint
\fi
}
207 208
\unexpanded
\def
\setlayer
209
{
\dotripleempty
\pack_layers_set
}
210 211
\def
\pack_layers_set
[#
1
][#
2
][#
3
]
% #4 == box do \fi is ok
212
{
\bgroup
213
\checkpositionoverlays
% otherwise funny regions
214
\edef
\currentlayer
{
#
1
}
%
215
\edef
\p_pack_layers_state
{
\layerparameter
\c!state
}
%
216
\ifx
\p_pack_layers_state
\v!stop
217
\dowithnextboxcs
\egroup
\hbox
% no pack ?
218
\orelse
\ifthirdargument
219
\pack_layers_set_indeed
[#
1
][#
2
][#
3
]
%
220
\else
221
\ifcondition
\validassignment
{
#
2
}
%
222
\pack_layers_set_indeed
[#
1
][][#
2
]
%
223
\else
224
\pack_layers_set_indeed
[#
1
][#
2
][]
%
225
\fi
226
\fi
}
227 228
\def
\pack_layers_set_indeed
[#
1
][#
2
][#
3
]
% #2 = links/rechts
229
{
\page_backgrounds_recalculate
% brrr
230
\global\advance
\c_pack_layers_current_data
\plusone
231
\forgetall
232
\dontcomplain
233
\edef
\p_pack_layers_option
{
\layerparameter
\c!option
}
%
234
\ifx
\p_pack_layers_option
\v!test
235
\settrue
\c_pack_layers_trace
236
\traceboxplacementtrue
237
\fi
238
\edef
\m_pack_layers_target
{
#
2
}
%
239
\dowithnextbox
{
\pack_layers_set_finish
{
#
3
}}
\hbox
}
240 241
\def
\pack_layers_set_finish
#
1
%
242
{
\ifcsname
\??layerbox
\currentlayer
\endcsname
% can move up
243
\ifx
\m_pack_layers_target
\v!even
244
\ifodd
\realpageno
245
% discard nextbox
246
\else
247
\let
\m_pack_layers_target
\v!left
248
\pack_layers_set_content
{
#
1
}
%
249
\fi
250
\orelse\ifx
\m_pack_layers_target
\v!odd
251
\ifodd
\realpageno
252
\let
\m_pack_layers_target
\v!right
253
\pack_layers_set_content
{
#
1
}
%
254
\else
255
% discard nextbox
256
\fi
257
\else
258
\pack_layers_set_content
{
#
1
}
%
259
\fi
260
\else
261
\writestatus
{
layer
}{
unknown
layer
\currentlayer
}
%
262
\fi
263
\egroup
}
264 265
% todo: left/right
266
% todo: get position data in one go
267 268
\def
\pack_layers_set_last_position_yes
% target: left|right
269
{
% this will become one call
270
\edef
\m_pack_layers_anchor
{
\??layerposition
\the
\c_pack_layers_current_data
}
%
271
\edef
\m_pack_layers_page
{
\MPp
\m_pack_layers_anchor
}
%
272
%edef\m_pack_layers_region{\MPr\m_pack_layers_anchor}% wrong one
273
\edef
\m_pack_layers_region
{
\layerparameter
\c!region
}
%
274
\d_pack_layers_x_position
\dimexpr
-
\MPx
\m_pack_layers_region
+
\MPx
\m_pack_layers_anchor
\relax
275
\d_pack_layers_y_position
\dimexpr
\MPy
\m_pack_layers_region
-
\MPy
\m_pack_layers_anchor
+
\MPh
\m_pack_layers_region
\relax
276
\xdef
\lastlayerxpos
{
\the
\d_pack_layers_x_position
}
%
277
\xdef
\lastlayerypos
{
\the
\d_pack_layers_y_position
}
%
278
% \writestatus{layering}{region: \m_pack_layers_region=>\MPxywhd\m_pack_layers_region}%
279
% \writestatus {}{anchor: \m_pack_layers_anchor=>\MPxywhd\m_pack_layers_anchor}%
280
% \writestatus {}{offset: \c!dx,\c!dy =>\lastlayerxpos,\lastlayerypos}%
281
\global
\letlayerparameter
\c!state\v!start
% needed ?
282
\setbox
\b_layers
\vpack
to
\d_pack_layers_y_size
283
{
\hpack
to
\d_pack_layers_x_size
284
{
\xypos
\m_pack_layers_anchor
\hss
}
%
285
\vss
}}
286 287
\def
\pack_layers_set_last_position_nop
288
{
\setbox
\b_layers
\emptybox
289
\d_pack_layers_x_position
\p_pack_layers_sx
\dimexpr
\p_pack_layers_x
\relax
290
\d_pack_layers_y_position
\p_pack_layers_sy
\dimexpr
\p_pack_layers_y
\relax
291
\glet
\lastlayerxpos
\!!zeropoint
292
\glet
\lastlayerypos
\!!zeropoint
293
\doifinset
\v!bottom
\p_pack_layers_corner
\pack_layers_set_bottom_positions
294
\doifinset
\v!right
\p_pack_layers_corner
\pack_layers_set_right_positions
295
\doifinset
\v!middle
\p_pack_layers_corner
\pack_layers_set_middle_positions
296
\edef
\m_pack_layers_page
{
\layerparameter
\c!page
}}
297 298
\unexpanded
\def
\definelayerpreset
299
{
\dodoubleargument
\pack_layers_define_preset
}
300 301
\def
\pack_layers_define_preset
[#
1
][#
2
]
%
302
{
\doifelseassignment
{
#
2
}
303
{
\setvalue
{
\??layerpreset
#
1
}{
\setupcurrentlayer
[#
2
]
}}
304
{
\setvalue
{
\??layerpreset
#
1
}{
\csname
\??layerpreset
#
2
\endcsname
}}}
305 306
\def
\pack_layers_set_content
#
1
%
307
{
\layerwidth
\layerparameter
\c!width
% global (local later)
308
\layerheight
\layerparameter
\c!height
% global (local later)
309
\d_pack_layers_x_size
\layerwidth
310
\d_pack_layers_y_size
\layerheight
311
%
312
\setupcurrentlayer
[#
1
]
% preroll
313
%
314
\edef
\p_pack_layers_preset
{
\layerparameter
\c!preset
}
%
315
%
316
\ifcsname
\??layerpreset
\p_pack_layers_preset
\endcsname
317
\lastnamedcs
318
\setupcurrentlayer
[#
1
]
% postroll
319
\fi
320
%
321
\edef
\p_pack_layers_rotation
{
\layerparameter
\c!rotation
}
%
322
\edef
\p_pack_layers_position
{
\layerparameter
\c!position
}
%
323
\edef
\p_pack_layers_hoffset
{
\layerparameter
\c!hoffset
}
%
324
\edef
\p_pack_layers_voffset
{
\layerparameter
\c!voffset
}
%
325
\edef
\p_pack_layers_offset
{
\layerparameter
\c!offset
}
%
326
\edef
\p_pack_layers_dx
{
\layerparameter
\c!dx
}
%
327
\edef
\p_pack_layers_dy
{
\layerparameter
\c!dy
}
%
328
\edef
\p_pack_layers_sx
{
\layerparameter
\c!sx
}
%
329
\edef
\p_pack_layers_sy
{
\layerparameter
\c!sy
}
%
330
\edef
\p_pack_layers_x
{
\layerparameter
\c!x
}
%
331
\edef
\p_pack_layers_y
{
\layerparameter
\c!y
}
%
332
\edef
\p_pack_layers_corner
{
\layerparameter
\c!corner
}
%
333
\edef
\p_pack_layers_location
{
\layerparameter
\c!location
}
%
334
\edef
\p_pack_layers_line
{
\layerparameter
\c!line
}
%
335
\edef
\p_pack_layers_column
{
\layerparameter
\c!column
}
%
336
\edef
\p_pack_layers_width
{
\layerparameter
\c!width
}
% local ones
337
\edef
\p_pack_layers_height
{
\layerparameter
\c!height
}
% local ones
338
\edef
\p_pack_layers_direction
{
\layerparameter
\c!direction
}
%
339
%
340
\ifx
\p_pack_layers_position
\v!overlay
341
\let
\p_pack_layers_width
\zeropoint
342
\let
\p_pack_layers_height
\zeropoint
343
\let
\p_pack_layers_position
\v!yes
344
\fi
345
\ifempty
\p_pack_layers_rotation
\else
346
% use direct call
347
\setbox
\nextbox
\hpack
348
{
\rotate
[
\c!location
=
\v!high
,
\c!rotation
=
\layerparameter
\c!rotation
]
{
\box
\nextbox
}}
%
349
\fi
350
\d_pack_layers_x_offset
\p_pack_layers_sx
\dimexpr
351
\ifx
\p_pack_layers_hoffset
\v!max
\d_pack_layers_x_size
\else
\p_pack_layers_hoffset
\fi
+
\p_pack_layers_offset
+
\p_pack_layers_dx
352
\relax
353
\d_pack_layers_y_offset
\p_pack_layers_sy
\dimexpr
354
\ifx
\p_pack_layers_voffset
\v!max
\d_pack_layers_y_size
\else
\p_pack_layers_voffset
\fi
+
\p_pack_layers_offset
+
\p_pack_layers_dy
355
\relax
356
\ifx
\p_pack_layers_position
\v!yes
357
\pack_layers_set_last_position_yes
358
\else
359
\pack_layers_set_last_position_nop
360
\fi
361
%
362
\ifempty
\m_pack_layers_page
\else
% is expanded
363
\edef
\m_pack_layers_page
{
:
\m_pack_layers_page
}
%
364
\ifcsname
\??layerbox
\m_pack_layers_target
\currentlayer
\m_pack_layers_page
\endcsname
\else
365
\expandafter
\newbox
\csname
\??layerbox
\m_pack_layers_target
\currentlayer
\m_pack_layers_page
\endcsname
366
\fi
367
\fi
368
\chardef
\layerpagebox
\csname
\??layerbox
\m_pack_layers_target
\currentlayer
\m_pack_layers_page
\endcsname
369
\ifvoid
\layerpagebox
370
\gsetboxllx
\layerpagebox
\zeropoint
371
\gsetboxlly
\layerpagebox
\zeropoint
372
\fi
373
\global\setbox
\layerpagebox
\vpack
%to \layerparameter\c!height % new, otherwise no negative y possible
374
{
\offinterlineskip
375
\ifvoid
\layerpagebox
376
\let
\lastlayerwidth
\zeropoint
377
\let
\lastlayerheight
\zeropoint
378
\else
379
\edef
\lastlayerwidth
{
\the\wd
\layerpagebox
}
%
380
\edef
\lastlayerheight
{
\the\ht
\layerpagebox
}
%
381
\ht
\layerpagebox
\zeropoint
382
\dp
\layerpagebox
\zeropoint
383
\wd
\layerpagebox
\zeropoint
384
\ifx
\p_pack_layers_direction
\v!reverse
\else
385
\box
\layerpagebox
386
\fi
387
\fi
388
% don't move
389
\xdef
\lastlayerwd
{
\the\wd
\nextbox
}
%
390
\xdef
\lastlayerht
{
\the\ht
\nextbox
}
% % not entirely ok when grid !
391
\xdef
\lastlayerdp
{
\the\dp
\nextbox
}
% % not entirely ok when grid !
392
% this code
393
\ifx
\p_pack_layers_location
\v!grid
394
\ht
\nextbox
\strutheight
395
\dp
\nextbox
\strutdepth
396
\else
397
\setbox
\nextbox
\hpack
398
{
\alignedbox
[
\p_pack_layers_location
]
\vpack
{
\box
\nextbox
}}
%
399
\fi
400
\ifnum
\p_pack_layers_line
=
\zerocount
\else
% no \ifcase, can be negative
401
\advance
\d_pack_layers_y_position
\dimexpr
\p_pack_layers_line
\lineheight
+
\topskip
-
\lineheight
-
\ht
\nextbox
\relax
402
\fi
403
\ifnum
\p_pack_layers_column
=
\zerocount
\else
% no \ifcase, can be negative
404
\advance
\d_pack_layers_x_position
\layoutcolumnoffset
\p_pack_layers_column
\relax
405
\fi
406
\ifx
\p_pack_layers_location
\v!grid
407
\setbox
\nextbox
\hpack
408
{
\alignedbox
[
rb
]
\vpack
{
\box
\nextbox
}}
%
409
\fi
410
% ll registration
411
\scratchdimen
\dimexpr
\d_pack_layers_x_position
+
\d_pack_layers_x_offset
\relax
412
\ifdim
\scratchdimen
<
\getboxllx
\layerpagebox
413
\gsetboxllx
\layerpagebox
\scratchdimen
414
\fi
415
\advance
\scratchdimen
\wd
\nextbox
416
\wd
\nextbox
\ifdim
\scratchdimen
>
\lastlayerwidth
\scratchdimen
\else
\lastlayerwidth
\fi
417
\scratchdimen
\dimexpr
\d_pack_layers_y_position
+
\d_pack_layers_y_offset
\relax
418
\ifdim
\scratchdimen
<
\getboxlly
\layerpagebox
419
\gsetboxlly
\layerpagebox
\scratchdimen
420
\fi
421
% ll compensation
422
\advance
\scratchdimen
\dimexpr\ht
\nextbox
+
\dp
\nextbox
\relax
423
\ht
\nextbox
\ifdim
\scratchdimen
>
\lastlayerheight
\scratchdimen
\else
\lastlayerheight
\fi
424
\dp
\nextbox
\zeropoint
425
% placement
426
\hsize
\p_pack_layers_width
427
\vpack
to
\p_pack_layers_height
\bgroup
428
\smashbox\nextbox
429
\vskip\dimexpr
\d_pack_layers_y_position
+
\d_pack_layers_y_offset
\relax
430
\hskip\dimexpr
\d_pack_layers_x_position
+
\d_pack_layers_x_offset
\relax
431
% or maybe instead of the \vskip
432
% \raise-\dimexpr\d_pack_layers_y_position+\d_pack_layers_y_offset\relax
433
\box
\nextbox
434
\ifvoid
\layerpagebox
435
% already flushed
436
\else
437
% the reverse case % check !
438
\vskip
-
\dimexpr
\d_pack_layers_y_position
+
\d_pack_layers_y_offset
\relax
439
\box
\layerpagebox
440
\fi
441
\egroup
}
%
442
% when position is true, the layerbox holds the compensation and needs
443
% to be placed; never change this !
444
\ifvoid
\b_layers
\else
445
\box
\b_layers
446
\fi
}
447 448
\def
\pack_layers_set_bottom_positions
449
{
\ifnum
\p_pack_layers_line
=
\zerocount
\else
% can be < 0
450
\edef
\p_pack_layers_line
{
\the\numexpr
-
\p_pack_layers_line
+
\layoutlines
+
\plusone
\relax
}
% use counter instead ?
451
\fi
452
\ifdim
\d_pack_layers_y_size
>
\zeropoint
453
\advance
\d_pack_layers_y_position
-
\d_pack_layers_y_size
454
\d_pack_layers_y_position
-
\d_pack_layers_y_position
455
\d_pack_layers_y_offset
-
\d_pack_layers_y_offset
456
\fi
}
457 458
\def
\pack_layers_set_right_positions
459
{
\ifnum
\p_pack_layers_column
=
\zerocount
\else
% can be < 0
460
\edef
\p_pack_layers_column
{
\the\numexpr
-
\layerparameter
\c!column
+
\layoutcolumns
+
\plusone
\relax
}
% use counter instead ?
461
\fi
462
\ifdim
\d_pack_layers_x_size
>
\zeropoint
463
\advance
\d_pack_layers_x_position
-
\d_pack_layers_x_size
464
\d_pack_layers_x_position
-
\d_pack_layers_x_position
465
\d_pack_layers_x_offset
-
\d_pack_layers_x_offset
466
\fi
}
467 468
\def
\pack_layers_set_middle_positions
469
{
\ifdim
\d_pack_layers_x_size
>
\zeropoint
\advance
\d_pack_layers_x_position
.
5
\d_pack_layers_x_size
\fi
470
\ifdim
\d_pack_layers_y_size
>
\zeropoint
\advance
\d_pack_layers_y_position
.
5
\d_pack_layers_y_size
\fi
}
471 472
%D Given the task to be accomplished, the previous macro is not even that
473
%D complicated. It mainly comes down to skipping to the right place and placing a
474
%D box on top of or below the existing content. In the case of position tracking,
475
%D another reference point is chosen.
476 477
%D \macros
478
%D {doifelselayerdata}
479 480
\def
\doifelselayerdata
#
1
%
481
{
\ifcsname
\??layerbox
#
1
\endcsname
482
%\ifvoid\csname\??layerbox#1\endcsname
483
\ifvoid
\lastnamedcs
484
\doubleexpandafter\secondoftwoarguments
485
\else
486
\doubleexpandafter\firstoftwoarguments
487
\fi
488
\else
489
\expandafter
\secondoftwoarguments
490
\fi
}
491 492
\let
\doiflayerdataelse\doifelselayerdata
493 494
%D \macros
495
%D {flushlayer}
496
%D
497
%D When we flush a layer, we flush both the main one and the page dependent one
498
%D (when defined). This feature is more efficient in \ETEX\ since there testing for
499
%D an undefined macro does not takes hash space.
500 501
% todo: setups before flush, handy hook
502 503
\unexpanded
\def
\flushlayer
[#
1
]
% quite core, so optimized (todo: check for void)
504
{
\begingroup
505
\forgetall
506
\edef
\currentlayer
{
#
1
}
%
507
\edef
\p_pack_layers_state
{
\layerparameter
\c!state
}
%
508
\ifx
\p_pack_layers_state
\v!stop
509
% nothing
510
\orelse\ifx
\p_pack_layers_state
\v!next
511
\global
\letlayerparameter
\c!state\v!start
% dangerous, stack-built-up
512
\orelse\ifx
\p_pack_layers_state
\v!continue
513
\global
\letlayerparameter
\c!state\v!repeat
% dangerous, stack-built-up
514
\else
515
\edef
\p_pack_layers_doublesided
{
\layerparameter
\c!doublesided
}
%
516
\ifx
\p_pack_layers_doublesided
\v!yes
517
\ifcsname
\??layerbox
#
1
\endcsname
518
% we can make a dedicated one for this
519
\doifbothsidesoverruled
520
{
\pack_layers_flush_double
\v!left
}
%
521
{
\pack_layers_flush_double
\v!right
}
%
522
{
\pack_layers_flush_double
\v!left
}
%
523
\else
524
\pack_layers_flush_single
525
\fi
526
\else
527
\pack_layers_flush_single
528
\fi
529
\fi
530
\endgroup
}
531 532
% \def\pack_layers_flush_single
533
% {\startoverlay
534
% {\ifcsname\??layerbox \currentlayer \endcsname\pack_layers_flush_indeed\plusone \currentlayer \fi}%
535
% {\ifcsname\??layerbox \currentlayer:\the\realpageno\endcsname\pack_layers_flush_indeed\zerocount{\currentlayer:\the\realpageno}\fi}%
536
% \stopoverlay}
537
%
538
% \def\pack_layers_flush_double#1%
539
% {\startoverlay
540
% {\ifcsname\??layerbox \currentlayer \endcsname\pack_layers_flush_indeed\plusone \currentlayer \fi}%
541
% {\ifcsname\??layerbox \currentlayer:\the\realpageno\endcsname\pack_layers_flush_indeed\zerocount {\currentlayer:\the\realpageno}\fi}%
542
% {\ifcsname\??layerbox#1\currentlayer \endcsname\pack_layers_flush_indeed\plusone {#1\currentlayer }\fi}%
543
% {\ifcsname\??layerbox#1\currentlayer:\the\realpageno\endcsname\pack_layers_flush_indeed\zerocount{#1\currentlayer:\the\realpageno}\fi}%
544
% \stopoverlay}
545 546
% optimized:
547 548
\def
\pack_layers_flush_single
549
{
\ifcsname
\??layerbox
\currentlayer
\endcsname
550
\ifvoid
\lastnamedcs
551
\ifcsname
\??layerbox
\currentlayer
:
\the
\realpageno
\endcsname
552
\ifvoid
\lastnamedcs\else
553
\chardef
\b_layer_two
\lastnamedcs
554
\pack_layers_flush_indeed
\zerocount
{
\currentlayer
:
\the
\realpageno
}
\b_layer_two
555
\fi
556
\fi
557
\else
558
\chardef
\b_layer_one
\lastnamedcs
559
\ifcsname
\??layerbox
\currentlayer
:
\the
\realpageno
\endcsname
560
\ifvoid
\lastnamedcs\else
561
\chardef
\b_layer_two
\lastnamedcs
562
\startoverlay
563
{
\pack_layers_flush_indeed
\plusone
\currentlayer
\b_layer_one
}
%
564
{
\pack_layers_flush_indeed
\zerocount
{
\currentlayer
:
\the
\realpageno
}
\b_layer_two
}
%
565
\stopoverlay
566
\fi
567
\else
568
\pack_layers_flush_indeed
\plusone
\currentlayer
\b_layer_one
569
\fi
570
\fi
571
\orelse\ifcsname
\??layerbox
\currentlayer
:
\the
\realpageno
\endcsname
572
\ifvoid
\lastnamedcs
573
% nothing
574
\else
575
\chardef
\b_layer_two
\lastnamedcs
576
\pack_layers_flush_indeed
\zerocount
{
\currentlayer
:
\the
\realpageno
}
\b_layer_two
577
\fi
578
\fi
}
579 580
% less optimized:
581 582
\def
\pack_layers_flush_double
#
1
%
583
{
\startoverlay
584
{
\ifcsname
\??layerbox
\currentlayer
\endcsname
585
\ifvoid
\lastnamedcs\else
\chardef
\b_layer_two
\lastnamedcs
586
\pack_layers_flush_indeed
\plusone
\currentlayer
\b_layer_two
587
\fi
588
\fi
}
%
589
{
\ifcsname
\??layerbox
\currentlayer
:
\the
\realpageno
\endcsname
590
\ifvoid
\lastnamedcs\else
\chardef
\b_layer_two
\lastnamedcs
591
\pack_layers_flush_indeed
\zerocount
{
\currentlayer
:
\the
\realpageno
}
\b_layer_two
592
\fi
593
\fi
}
%
594
{
\ifcsname
\??layerbox
#
1
\currentlayer
\endcsname
595
\ifvoid
\lastnamedcs\else
\chardef
\b_layer_two
\lastnamedcs
596
\pack_layers_flush_indeed
\plusone
{
#
1
\currentlayer
}
\b_layer_two
597
\fi
598
\fi
}
%
599
{
\ifcsname
\??layerbox
#
1
\currentlayer
:
\the
\realpageno
\endcsname
600
\ifvoid
\lastnamedcs\else
\chardef
\b_layer_two
\lastnamedcs
601
\pack_layers_flush_indeed
\zerocount
{
#
1
\currentlayer
:
\the
\realpageno
}
\b_layer_two
602
\fi
603
\fi
}
%
604
\stopoverlay
}
605 606
\let
\pack_layers_top_fill
\relax
607
\let
\pack_layers_bottom_fill
\vss
608 609
%def\pack_layers_flush_indeed#1#2%
610
\def
\pack_layers_flush_indeed
#
1
#
2
#
3
%
611
{
\begingroup
% already grouped
612
\offinterlineskip
613
\edef
\p_pack_layers_preset
{
\layerparameter
\c!preset
}
%
614
\ifcsname
\??layerpreset
\p_pack_layers_preset
\endcsname
615
\lastnamedcs
616
\fi
617
\edef
\p_pack_layers_method
{
\layerparameter
\c!method
}
%
618
\edef
\p_pack_layers_option
{
\layerparameter
\c!option
}
%
619
\ifx
\p_pack_layers_option
\v!test
620
\settrue
\c_pack_layers_trace
621
\traceboxplacementtrue
622
\fi
623
\ifcase
#
1
\relax
624
\setfalse
\c_pack_layers_repeated
625
\else
626
\edef
\p_pack_layers_position
{
\layerparameter
\c!position
}
%
627
\ifx
\p_pack_layers_position
\v!yes
628
\setfalse
\c_pack_layers_repeated
629
\else
630
\edef
\p_pack_layers_repeat
{
\layerparameter
\c!repeat
}
%
631
\ifx
\p_pack_layers_repeat
\v!yes
632
\settrue
\c_pack_layers_repeated
633
\orelse\ifx
\p_pack_layers_state
\v!repeat
634
\settrue
\c_pack_layers_repeated
635
\else
636
\setfalse
\c_pack_layers_repeated
637
\fi
638
\fi
639
\fi
640
%chardef\b_layers\csname\??layerbox#2\endcsname % trick
641
\let
\b_layers
#
3
%
642
% we need to copy in order to retain the negative offsets for a next
643
% stage of additions, i.e. llx/lly accumulate in repeat mode and the
644
% compensation may differ each flush depending on added content
645
\setbox
\nextbox
646
\ifx
\p_pack_layers_method
\v!fit
647
\pack_layers_positioned_box_yes
648
\else
649
\pack_layers_positioned_box_nop
650
\fi
651
% todo: method=offset => overlayoffset right/down (handy for backgrounds with offset)
652
\doifelseoverlay
{
#
2
}
%
653
{
\setlayoutcomponentattribute
{
\v!layer
:
#
2
}}
%
654
\resetlayoutcomponentattribute
655
% we have conflicting demands: some mechanisms want ll anchoring .. I need to figure this out
656
% and maybe we will have 'origin=bottom' or so
657
\setbox
\nextbox
658
\ifx
\p_pack_layers_option
\v!test
\ruledvbox
\else
\vpack
\fi
\ifx
\p_pack_layers_method
\v!overlay
to
\d_overlay_height
\fi
\layoutcomponentboxattribute
659
{
\pack_layers_top_fill
660
%
661
% \hpack \ifx\p_pack_layers_method\v!overlay to \d_overlay_width \fi
662
% {\box\nextbox
663
% \hss}%
664
%
665
\ifx
\p_pack_layers_method
\v!overlay
\wd
\nextbox
\d_overlay_width
\fi
666
\box
\nextbox
667
%
668
\pack_layers_bottom_fill
}
%
669
% \edef\currentlayer{#2}% :\the\realpageno}% local .. check \anchor
670
% \edef\p_pack_layers_position{\layerparameter\c!position}% local
671
\ifx
\p_pack_layers_position
\v!yes
672
\edef
\p_pack_layers_region
{
\layerparameter
\c!region
}
%
673
\ifempty
\p_pack_layers_region
\else
674
\anch_mark_tagged_box
\nextbox
\p_pack_layers_region
% was \layeranchor
675
\fi
676
\fi
677
\box
\nextbox
678
%
679
\ifconditional
\c_pack_layers_repeated
\else
680
\gsetboxllx
\b_layers
\zeropoint
681
\gsetboxlly
\b_layers
\zeropoint
682
\fi
683
\endgroup
}
684 685
\def
\pack_layers_positioned_box_yes
686
{
\vpack
687
{
\vskip
-
\getboxlly
\b_layers
688
\hskip
-
\getboxllx
\b_layers
689
\hsize
-
\dimexpr
\getboxllx
\b_layers
-
\wd
\b_layers
\relax
690
\ifconditional
\c_pack_layers_repeated
\copy\else\box\fi
\b_layers
}}
691 692
\def
\pack_layers_positioned_box_nop
693
{
\ifconditional
\c_pack_layers_repeated
\copy\else\box\fi
\b_layers
}
694 695
% \definelayer[test][method=fit] \setupcolors[state=start,option=test]
696
%
697
% \framed[framecolor=red,offset=overlay]{\setlayer[test]{aa}\setlayer[test][x=10pt]{g}\flushlayer[test]}
698
% \framed[framecolor=red,offset=overlay]{\setlayer[test]{aa}\setlayer[test][x=-10pt]{bb}\flushlayer[test]}
699
% \framed[framecolor=red,offset=overlay]{\setlayer[test][x=-20pt]{cccccc}\flushlayer[test]}
700
% \framed[framecolor=red,offset=overlay]{\setlayer[test]{dd}\setlayer[test][x=-20pt,y=-3pt]{eeeeee}\flushlayer[test]}
701 702
%D \macros
703
%D {composedlayer,placelayer,tightlayer}
704
%D
705
%D This is a handy shortcut, which saves a couple of braces when we use it as
706
%D parameter. This name also suits better to other layering commands.
707 708
\unexpanded
\def
\composedlayer
#
1
{
\flushlayer
[#
1
]
}
709 710
\unexpanded
\def
\tightlayer
[#
1
]
%
711
{
\hpack
712
{
\def
\currentlayer
{
#
1
}
% todo: left/right
713
\setbox
\nextbox
\emptybox
714
\d_overlay_width
\layerparameter
\c!width
715
\d_overlay_height
\layerparameter
\c!height
716
\composedlayer
{
#
1
}}}
717 718
\let
\placelayer\flushlayer
719 720
%D \macros
721
%D {setMPlayer}
722
%D
723
%D The following layer macro uses the positions that are registered by \METAPOST.
724
%D
725
%D \starttyping
726
%D \definelayer[test]
727
%D
728
%D \setMPlayer [test] [somepos-1] {Whatever we want here!}
729
%D \setMPlayer [test] [somepos-2] {Whatever we need there!}
730
%D \setMPlayer [test] [somepos-3] {\externalfigure[cow.mps][width=2cm]}
731
%D
732
%D \startuseMPgraphic{oeps}
733
%D draw fullcircle scaled 10cm withcolor red ;
734
%D register ("somepos-1",2cm,3cm,center currentpicture) ;
735
%D register ("somepos-2",8cm,5cm,(-1cm,-2cm)) ;
736
%D register ("somepos-3",0cm,0cm,(-2cm,2cm)) ;
737
%D \stopuseMPgraphic
738
%D
739
%D \getMPlayer[test]{\useMPgraphic{oeps}}
740
%D \stoptyping
741
%D
742
%D The last line is equivalent to
743
%D
744
%D \starttyping
745
%D \framed
746
%D [background={foreground,test},offset=overlay]
747
%D {\useMPgraphic{oeps}}
748
%D \stoptyping
749 750
\unexpanded
\def
\setMPlayer
751
{
\dotripleempty
\pack_layers_set_MP
}
752 753
\def
\MPlayerwidth
{
\hsize
}
754
\def
\MPlayerheight
{
\vsize
}
755 756
\def
\pack_layers_set_MP
[#
1
][#
2
][#
3
]
%
757
{
\edef
\MPlayerwidth
{
\MPw
{
#
2
}}
%
758
\edef
\MPlayerheight
{
\MPh
{
#
2
}}
%
759
\setlayer
[#
1
][
\c!x
=
\MPx
{
#
2
}
,
\c!y
=
\MPy
{
#
2
}
,
\c!position
=
\v!no
,
#
3
]
}
760 761
\unexpanded
\def
\getMPlayer
762
{
\dodoubleempty
\pack_layers_get_MP
}
763 764
\def
\pack_layers_get_MP
[#
1
][#
2
]
%
765
{
\framed
[
\c!background
=
{
\v!foreground
,
#
1
}
,
\c!frame
=
\v!off
,
\c!offset
=
\v!overlay
,
#
2
]
}
% takes argument
766 767
%D Watch out, a redefinition:
768 769
\ifdefined
\settextpagecontent
\else
770
\writestatus
\m!system
{
error
in
page
-
lyr
.
tex
}
\wait
771
\fi
772 773
\definelayer
774
[
OTRTEXT
]
775 776
\setuplayer
777
[
OTRTEXT
]
778
[
\c!width
=
\innermakeupwidth
,
779
\c!height
=
\textheight
]
780 781
\let
\normalsettextpagecontent
\settextpagecontent
% will be overloaded in page-spr
782 783
\unexpanded
\def
\settextpagecontent
#
1
#
2
#
3
% #2 and #3 will disappear
784
{
\doifelselayerdata
{
OTRTEXT
}
785
{
\setbox
#
1
\hpack
to
\makeupwidth
786
{
\startoverlay
787
{
\tightlayer
[
OTRTEXT
]
}
% first, otherwise problems with toc
788
{
\normalsettextpagecontent
{
#
1
}{
#
2
}{
#
3
}
\box
#
1
}
789
\stopoverlay
}
%
790
\dp
#
1
\zeropoint
}
%
791
{
\normalsettextpagecontent
{
#
1
}{
#
2
}{
#
3
}}}
792 793
\protect
\endinput
794