1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Packaging Macros Boxes}
15
16
17
18
19
20
21\unprotect
22
23
24
25
26
27
28
29
30
31
32\definelayer[\v!text2][\c!position=\v!yes,\c!region=,\c!width=\textwidth,\c!height=\textheight]
33\definelayer[\v!text1][\c!position=\v!yes,\c!region=,\c!width=\textwidth,\c!height=\textheight]
34\definelayer[\v!text1][\c!position=\v!yes,\c!region=,\c!width=\textwidth,\c!height=\textheight]
35\definelayer[\v!text2][\c!position=\v!yes,\c!region=,\c!width=\textwidth,\c!height=\textheight]
36
37\permanent\protected\def\internaltextoverlay#1
38 {\startoverlay
39 {\positionregionoverlay\textanchor{\v!text#1}}
40 {\composedlayer {\v!text#1}}
41 \stopoverlay}
42
43\defineoverlay[\v!text2][\internaltextoverlay{2}]
44\defineoverlay[\v!text1][\internaltextoverlay{1}]
45\defineoverlay[\v!text1][\internaltextoverlay{1}]
46\defineoverlay[\v!text2][\internaltextoverlay{2}]
47
48\installcorenamespace {anchor}
49
50
51
52
53
54\mutable\let\currentanchor\empty
55
56\permanent\tolerant\protected\def\defineanchor[#1]#*[#2]#*[#3]#*[#4]
57 {\setvalue{\??anchor#1}{\pack_anchors_process_defined{#2}{#3}{#4}}}
58
59\let\pack_anchors_process_defined_indeed\gobbletwooptionals
60
61\def\pack_anchors_process_defined#1#2#3
62 {\tolerant\def\pack_anchors_process_defined_indeed[##1]##*[##2]
63 {\ifarguments
64 \def\next{\pack_anchors_process_indeed{#1}{#2}{#3}}
65 \or
66 \def\next{\pack_anchors_process_indeed{#1}{#2,##1}{#2,##1}}
67 \or
68 \def\next{\pack_anchors_process_indeed{#1}{#2,##1}{#3,##2}}
69 \fi
70 \next}
71 \pack_anchors_process_defined_indeed}
72
73\permanent\protected\def\anchor[#1]
74 {\begingroup
75 \edef\currentanchor{#1}
76 \ifcsname\??anchor\currentanchor\endcsname
77 \expandafter\lastnamedcs
78 \else
79 \expandafter\pack_anchor_notdefined
80 \fi}
81
82\tolerant\def\pack_anchor_notdefined[#1]#*[#2]
83 {\ifarguments
84 \expandafter\gobbletwoarguments
85 \or
86 \expandafter\pack_anchor_notdefined_one
87 \else
88 \expandafter\pack_anchor_notdefined_two
89 \fi{#1}{#2}}
90
91\def\pack_anchor_notdefined_one #1#2{\dowithnextbox{\pack_anchors_process_finish\currentanchor{#1}{#1}}\vbox}
92\def\pack_anchor_notdefined_two #1#2{\dowithnextbox{\pack_anchors_process_finish\currentanchor{#1}{#2}}\vbox}
93\def\pack_anchors_process_indeed#1#2#3{\dowithnextbox{\pack_anchors_process_finish {#1}{#2}{#3}}\vbox}
94
95\newbox \b_pack_anchors
96\newdimen\d_pack_anchors_width
97\newdimen\d_pack_anchors_height
98\newdimen\d_pack_anchors_depth
99
100
101
102\newcount\c_pack_anchors_n
103\newtoks \t_pack_anchors_flush
104
105\protected\def\pack_anchors_register#1#2
106 {\global\advance\c_pack_anchors_n\plusone
107 \pagereference[\v!layer:\v!anchor:\number\c_pack_anchors_n]
108 \putboxincache\v!anchor{\number\c_pack_anchors_n}\b_pack_anchors
109
110 \doglobal\appendetoks
111 \pack_anchors_flush{\number\c_pack_anchors_n}{#1}{#2}
112 \to \t_pack_anchors_flush
113 \glet\pack_anchors_flush_all\pack_anchors_flush_all_indeed}
114
115\protected\def\pack_anchors_flush#1#2#3
116 {\doifelseboxincache\v!anchor{#1}
117 {\doifelsereferencefound{\v!layer:\v!anchor:#1}
118 {\ifnum\currentreferencerealpage=\realpageno\relax
119 \setlayer[#2][#3,\c!position=\v!no]{\directboxfromcache\v!anchor{#1}}
120 \else
121 \donetrue
122 \fi
123 }\donetrue}
124 \donetrue}
125
126\protected\def\pack_anchors_flush_all_indeed
127 {\donefalse
128 \the\t_pack_anchors_flush
129 \ifdone\else
130 \global\t_pack_anchors_flush\emptytoks
131 \glet\pack_anchors_flush_all\relax
132 \fi}
133
134\let\pack_anchors_flush_all\relax
135
136\appendtoks
137 \pack_anchors_flush_all
138\to \everybeforepagebody
139
140\def\pack_anchors_process_finish#1#2#3
141 {\checkpositionoverlays
142 \setbox\b_pack_anchors\box\nextbox
143 \framed
144 [\c!offset=\v!overlay,\c!frame=\v!off,#3]
145 {\pack_anchors_register{#1}{#2}
146 \novrule
147 \s!width \wd\b_pack_anchors
148 \s!height\ht\b_pack_anchors
149 \s!depth \dp\b_pack_anchors}
150 \endgroup}
151
152
153
154
155\permanent\tolerant\protected\def\setlayeranchored[#1]#*[#2]
156 {\begingroup
157 \ifarguments
158 \dowithnextbox
159 {\endgroup}
160 \else
161 \dowithnextbox
162 {\checkpositionoverlays
163 \setbox\b_pack_anchors\box\nextbox
164 \dontleavehmode\hpack{\pack_anchors_register{#1}{#2}}
165 \endgroup}
166 \fi
167 \hbox}
168
169
170
171\installcorenamespace{collectorbox}
172\installcorenamespace{collector}
173
174\installcommandhandler \??collector {collector} \??collector
175
176\setupcollector
177 [\c!state=\v!start,
178 \c!x=\zeropoint,
179 \c!y=\zeropoint,
180 \c!offset=\zeropoint,
181 \c!rotation=,
182 \c!hoffset=\zeropoint,
183 \c!voffset=\zeropoint,
184 \c!location=rb,
185 \c!corner=]
186
187\appendtoks
188 \ifcsname\??collectorbox\currentcollector\endcsname \else
189 \expandafter\newbox\csname\??collectorbox\currentcollector\endcsname
190 \fi
191\to \everydefinecollector
192
193\permanent\protected\def\resetcollector[#1]
194 {\ifcsname\??collectorbox#1\endcsname
195 \global\setbox\lastnamedcs\emptybox
196 \fi}
197
198\newconditional\c_pack_boxes_collector_valid_box
199
200\mutable\let\b_pack_boxes_collector\scratchbox
201
202\def\pack_boxes_collector_check_box#1
203 {\edef\currentcollector{#1}
204 \ifcsname\??collectorbox\currentcollector\endcsname
205 \settrue\c_pack_boxes_collector_valid_box
206 \expandafter\let\expandafter\b_pack_boxes_collector\lastnamedcs
207 \else
208 \setfalse\c_pack_boxes_collector_valid_box
209 \writestatus{collector}{unknown collector \currentcollector}
210 \fi}
211
212\permanent\tolerant\protected\def\setcollector[#1]#*[#2]
213 {\bgroup
214 \pack_boxes_collector_check_box{#1}
215 \ifconditional\c_pack_boxes_collector_valid_box
216 \setupcurrentcollector[#2]
217 \expandafter\pack_boxes_collector_yes
218 \else
219 \expandafter\pack_boxes_collector_nop
220 \fi}
221
222\def\pack_boxes_collector_yes
223 {\forgetall
224 \dontcomplain
225 \dowithnextboxcs\pack_boxes_collector_finish\hbox}
226
227\let\pack_boxes_collector_nop\egroup
228
229\installcorenamespace{collectorcorners}
230
231\setvalue{\??collectorcorners\v!middle}
232 {\ifdim\d_pack_layers_x_size>\zeropoint
233 \advance\d_pack_layers_x_position.5\d_pack_layers_x_size
234 \fi
235 \ifdim\d_pack_layers_y_size>\zeropoint
236 \advance\d_pack_layers_y_position.5\d_pack_layers_y_size
237 \fi}
238
239\setvalue{\??collectorcorners\v!bottom}
240 {\ifdim\d_pack_layers_y_size>\zeropoint
241 \advance\d_pack_layers_y_position\d_pack_layers_y_size
242 \d_pack_layers_y_position\d_pack_layers_y_position
243 \fi}
244
245\setvalue{\??collectorcorners\v!right}
246 {\ifdim\d_pack_layers_x_size>\zeropoint
247 \advance\d_pack_layers_x_position\d_pack_layers_x_size
248 \d_pack_layers_x_position\d_pack_layers_x_position
249 \fi}
250
251\def\pack_boxes_collector_check_corner#1
252 {\ifcsname\??collectorcorners#1\endcsname
253 \lastnamedcs
254 \fi}
255
256\def\pack_boxes_collector_finish
257 {\edef\p_collector_rotation{\collectorparameter\c!rotation}
258 \edef\p_collector_corner {\collectorparameter\c!corner}
259 \ifempty\p_collector_rotation \else
260 \setbox\nextbox\hpack
261 {\rotate
262 [\c!location=\v!high,
263 \c!rotation=\p_collector_rotation]
264 {\box\nextbox}}
265 \fi
266 \d_pack_layers_x_size\wd\b_pack_boxes_collector
267 \d_pack_layers_y_size\htdp\b_pack_boxes_collector
268 \d_pack_layers_x_position\dimexpr\collectorparameter\c!x\collectorparameter\c!hoffset\relax
269 \d_pack_layers_y_position\dimexpr\collectorparameter\c!y\collectorparameter\c!voffset\relax
270 \rawprocesscommacommand[\p_collector_corner]\pack_boxes_collector_check_corner
271 \setbox\nextbox\hpack
272 {\alignedbox[\collectorparameter\c!location]\vpack{\box\nextbox}}
273 \boxmaxdepth\zeropoint
274 \global\advance\boxhdisplacement\d_pack_layers_x_position
275 \ifdim\boxhdisplacement<\zeropoint
276 \global\setbox\b_pack_boxes_collector\hpack
277 {\kern\boxhdisplacement
278 \box\b_pack_boxes_collector}
279 \fi
280 \global\advance\boxvdisplacement\d_pack_layers_y_position
281 \ifdim\boxvdisplacement<\zeropoint
282 \global\setbox\b_pack_boxes_collector\hpack
283 {\lower\boxvdisplacement
284 \box\b_pack_boxes_collector}
285 \fi
286 \d_pack_layers_x_size\wd\b_pack_boxes_collector
287 \d_pack_layers_y_size\htdp\b_pack_boxes_collector
288 \global\setbox\b_pack_boxes_collector\hpack
289 {\box\b_pack_boxes_collector
290 \kern\dimexpr
291 \d_pack_layers_x_size
292 \d_pack_layers_x_position
293 \ifdim\boxhdisplacement<\zeropoint
294 \boxhdisplacement
295 \fi
296 \relax
297 \lower\d_pack_layers_y_position\hpack
298 {\ifdim\boxvdisplacement<\zeropoint
299 \lower\boxvdisplacement
300 \fi
301 \box\nextbox}}
302
303 \global\setbox\b_pack_boxes_collector\hpack
304 {\lower\ht\b_pack_boxes_collector\box\b_pack_boxes_collector}
305
306 \ifdim\wd\b_pack_boxes_collector<\d_pack_layers_x_size
307 \wd\b_pack_boxes_collector\d_pack_layers_x_size
308 \fi
309 \egroup}
310
311\permanent\protected\def\flushcollector[#1]
312 {\bgroup
313 \pack_boxes_collector_check_box{#1}
314 \ifconditional\c_pack_boxes_collector_valid_box
315 \edef\p_collector_state{\collectorparameter\c!state}
316 \ifx\p_collector_state\v!stop \else
317 \vpack{\hpack{\raise
318 \dp\b_pack_boxes_collector
319 \ifx\p_collector_state\v!repeat\copy\else\box\fi\b_pack_boxes_collector}}
320 \fi
321 \fi
322 \egroup}
323
324\permanent\protected\def\composedcollector#1
325 {\flushcollector[#1]}
326
327\permanent\tolerant\protected\def\adaptcollector[#1]#*[#2]
328 {\begingroup
329 \pack_boxes_collector_check_box{#1}
330 \ifconditional\c_pack_boxes_collector_valid_box
331 \letcollectorparameter\c!hoffset\zeropoint
332 \letcollectorparameter\c!voffset\zeropoint
333 \setupcurrentcollector[#2]
334 \global\wd\b_pack_boxes_collector\dimexpr\wd\b_pack_boxes_collector\collectorparameter\c!hoffset\relax
335 \global\ht\b_pack_boxes_collector\dimexpr\ht\b_pack_boxes_collector\collectorparameter\c!voffset\relax
336 \fi
337 \endgroup}
338
339
340
341
342
343
344
345
346
347
348\definecollector
349 [caption]
350
351\permanent\tolerant\protected\def\collectedtext[#1]#*[#2]
352 {\pack_boxes_collector_text[#1][#2]}
353
354\def\pack_boxes_collector_text[#1][#2]#3
355 {\bgroup
356 \dowithnextbox
357 {\setcollector
358 [caption]
359 {\box\nextbox}
360 \setcollector
361 [caption][#1]
362 {\letdummyparameter\c!style\empty
363 \letdummyparameter\c!color\empty
364 \getdummyparameters[#2]
365 \dousestyleparameter{\directdummyparameter\c!style}
366 \setupinterlinespace
367 \normalexpanded{\framed[\c!foregroundcolor=\directdummyparameter\c!color,\c!foregroundstyle=\directdummyparameter\c!style},\c!frame=\v!overlay,#2]{#3}}
368 \composedcollector{caption}
369 \egroup}
370 \hbox}
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390\installcorenamespace {layeredtext}
391\installcorenamespace {layeredtextlayer}
392\installcorenamespace {layeredtextframed}
393
394\installsimpleframedcommandhandler \??layeredtext {layeredtext} \??layeredtext
395
396\newdimen\d_pack_layeredtexts_width
397\newdimen\d_pack_layeredtexts_height
398
399\definelayer
400 [\??layeredtextlayer]
401
402\setuplayer
403 [\??layeredtextlayer]
404 [\c!width=\d_pack_layeredtexts_width,
405 \c!height=\d_pack_layeredtexts_height]
406
407\defineframed
408 [\??layeredtextframed]
409 [\c!offset=\v!overlay,
410 \c!frame=\v!off,
411 \c!background={\v!foreground,\??layeredtextlayer},
412 \c!width=\d_pack_layeredtexts_width,
413 \c!height=\d_pack_layeredtexts_height]
414
415\setuplayeredtext
416 [\c!frame=\v!overlay,
417 \c!color=,
418 \c!style=,
419 \c!foregroundcolor=\layeredtextparameter\c!color,
420 \c!foregroundstyle=\layeredtextparameter\c!style]
421
422\permanent\tolerant\protected\def\placelayeredtext[#1]#*[#2]#*[#3]#4
423 {\bgroup
424 \edef\currentlayeredtext{#1}
425 \checklayeredtextparent
426 \setupcurrentlayeredtext[#3]
427 \dowithnextbox
428 {\d_pack_layeredtexts_width \wd\nextbox
429 \d_pack_layeredtexts_height\ht\nextbox
430 \begingroup
431 \setlayer
432 [\??layeredtextlayer]
433 [#2]
434 {\setfalse\fontattributeisset
435 \uselayeredtextstyleparameter\c!style
436 \ifconditional\fontattributeisset
437 \setupinterlinespace
438 \fi
439 \inheritedlayeredtextframed{#4}}
440 \endgroup
441 \placeframed[\??layeredtextframed]{\flushnextbox}
442 \egroup}
443 \hbox}
444
445\permanent\protected\def\layeredtext
446 {\placelayeredtext[]}
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466\permanent\tolerant\protected\def\ornamenttext[#1]#*[#2]
467 {\bgroup
468 \doifelseassignment{#1}
469 {\letdummyparameter\c!alternative\v!a
470 \getdummyparameters[#1]
471 \doifelse{\directdummyparameter\c!alternative}\v!a
472 {\egroup\collectedtext}
473 {\egroup\layeredtext }
474 [#1][#2]}
475 {\egroup\csname#1\endcsname}}
476
477\permanent\tolerant\protected\def\defineornament[#1]#*[#2]#*[#3]
478 {\protected\frozen\instance\defcsname#1\endcsname{\ornamenttext[#2][#3]}}
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512\newcount\c_pack_boxes_bleeds
513
514\installcorenamespace {bleeding}
515
516\installdirectcommandhandler \??bleeding {bleeding}
517
518\setupbleeding
519 [\c!location=l,
520 \c!stretch=\v!yes,
521 \c!width=3cm,
522 \c!height=3cm,
523 \c!offset=2mm,
524 \c!page=\v!no,
525 \c!voffset=\scratchoffset,
526 \c!hoffset=\scratchoffset]
527
528\permanent\def\bleedwidth {\the\hsize}
529\permanent\def\bleedheight{\the\vsize}
530
531\newconditional\c_pack_boxes_l
532\newconditional\c_pack_boxes_r
533\newconditional\c_pack_boxes_t
534\newconditional\c_pack_boxes_b
535
536\installcorenamespace{bleedinglocation}
537
538\setvalue{\??bleedinglocation t}{\settrue\c_pack_boxes_t\scratchhoffset\zeropoint}
539\setvalue{\??bleedinglocation b}{\settrue\c_pack_boxes_b\scratchhoffset\zeropoint}
540\setvalue{\??bleedinglocation l}{\settrue\c_pack_boxes_l\scratchvoffset\zeropoint}
541\setvalue{\??bleedinglocation r}{\settrue\c_pack_boxes_r\scratchvoffset\zeropoint}
542\setvalue{\??bleedinglocation bl}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_b}
543\setvalue{\??bleedinglocation lb}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_b}
544\setvalue{\??bleedinglocation br}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_b}
545\setvalue{\??bleedinglocation rb}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_b}
546\setvalue{\??bleedinglocation tl}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_t}
547\setvalue{\??bleedinglocation lt}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_t}
548\setvalue{\??bleedinglocation tr}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_t}
549\setvalue{\??bleedinglocation rt}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_t}
550
551\mutable\let\currentbleedposition\empty
552\mutable\let\currentpageposition \empty
553
554\permanent\tolerant\protected\def\bleed[#1]
555 {\hbox\bgroup
556 \global\advance\c_pack_boxes_bleeds\plusone
557
558 \enforced\permanent\xdef\bleedwidth {\the\hsize}
559 \enforced\permanent\xdef\bleedheight{\the\vsize}
560
561 \edef\currentbleedposition{bleed:\number\c_pack_boxes_bleeds}
562 \edef\currentpageposition {page:0}
563
564 \setupcurrentbleeding[#1]
565
566 \scratchwidth \bleedingparameter\c!width
567 \scratchheight \bleedingparameter\c!height
568 \scratchoffset \bleedingparameter\c!offset
569 \scratchhoffset\bleedingparameter\c!hoffset
570 \scratchvoffset\bleedingparameter\c!voffset
571
572 \setfalse\c_pack_boxes_l
573 \setfalse\c_pack_boxes_r
574 \setfalse\c_pack_boxes_t
575 \setfalse\c_pack_boxes_b
576
577 \csname\??bleedinglocation\bleedingparameter\c!location\endcsname
578
579 \doifelse{\bleedingparameter\c!stretch}\v!yes\donetrue\donefalse
580
581 \enforced\permanent\xdef\bleedwidth{\the\dimexpr
582 \ifdone
583 \ifconditional\c_pack_boxes_l
584 \scratchwidth\MPx\currentbleedposition\MPx\currentpageposition
585 \orelse\ifconditional\c_pack_boxes_r
586 \paperwidth \MPx\currentbleedposition\MPx\currentpageposition
587 \else
588 \scratchwidth
589 \fi
590 \else
591 \scratchwidth
592 \fi\scratchhoffset
593 \relax}
594 \enforced\permanent\xdef\bleedheight{\the\dimexpr
595 \ifdone
596 \ifconditional\c_pack_boxes_t
597 \paperheight \MPy\currentbleedposition\MPy\currentpageposition
598 \orelse\ifconditional\c_pack_boxes_b
599 \scratchheight\MPy\currentbleedposition\MPy\currentpageposition \MPh\currentbleedposition
600 \else
601 \scratchheight
602 \fi
603 \else
604 \scratchheight
605 \fi\scratchvoffset
606 \relax}
607 \dowithnextboxcontentcs\pack_boxes_bleed_settings\pack_boxes_bleed_finish\hbox}
608
609\def\pack_boxes_bleed_settings
610 {\hsize\bleedwidth
611 \vsize\bleedheight}
612
613\def\pack_boxes_bleed_finish
614 {\doif{\bleedingparameter\c!page}\v!yes
615 {\setbox\nextbox\topskippedbox{\box\nextbox}}
616 \setbox\nextbox\hpack to \scratchwidth
617 {\ifconditional\c_pack_boxes_l\hss\fi
618 \box\nextbox
619 \ifconditional\c_pack_boxes_r\hss\fi}
620 \ifconditional\c_pack_boxes_b
621 \setbox\nextbox\hpack
622 {\lower\bleedheight\hpack{\raise\scratchheight\box\nextbox}}
623 \fi
624 \wd\nextbox\scratchwidth
625 \ht\nextbox\scratchheight
626 \dp\nextbox\zeropoint
627 \ifdone
628 \hpos\currentbleedposition{\box\nextbox}
629 \else
630 \box\nextbox
631 \fi
632 \egroup}
633
634\defineexternalfigure
635 [bleed]
636 [\c!width=\bleedwidth,
637 \c!height=\bleedheight]
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672\permanent\tolerant\protected\def\setlayerframed[#1]#*[#2]#*[#3]
673 {\ifarguments
674
675 \or
676 \expandafter\pack_layers_set_framed_s
677 \or
678 \expandafter\pack_layers_set_framed_d
679 \or
680 \expandafter\pack_layers_set_framed_t
681 \fi[#1][#2][#3]}
682
683\def\pack_layers_set_framed_s[#1][#2][#3]
684 {\setlayer[#1][\c!width=\wd\nextbox,\c!height=\ht\nextbox,\c!offset=\zeropoint]
685 \normalframedwithsettings[\c!location=\v!normal]}
686
687\def\pack_layers_set_framed_d[#1][#2][#3]
688 {\setlayer[#1][\c!width=\wd\nextbox,\c!height=\ht\nextbox,#2,\c!offset=\zeropoint]
689 \normalframedwithsettings[\c!location=\v!normal,#2]}
690
691\def\pack_layers_set_framed_t[#1][#2][#3]
692 {\setlayer[#1][#2]
693 \normalframedwithsettings[#3]}
694
695\permanent\tolerant\protected\def\setlayertext[#1]#*[#2]#*[#3]
696 {\bgroup
697 \letdummyparameter\c!align\empty
698 \letdummyparameter\c!width\hsize
699 \letdummyparameter\c!color\empty
700 \letdummyparameter\c!style\empty
701 \getdummyparameters[#3]
702 \dowithnextboxcontent
703 {\forgetall
704 \hsize\directdummyparameter\c!width
705 \usealignparameter\directdummyparameter
706 \dousestyleparameter{\directdummyparameter\c!style}}
707 {\setlayer[#1][#2]{\strut\dousecolorparameter{\directdummyparameter\c!color}\flushnextbox}
708 \egroup}
709 \vtop}
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733\definelayerpreset
734 [\v!left\v!top]
735 [\c!corner={\v!left,\v!top},\c!location={\v!right,\v!bottom}]
736
737\definelayerpreset
738 [\v!right\v!top]
739 [\c!corner={\v!right,\v!top},\c!location={\v!left,\v!bottom}]
740
741\definelayerpreset
742 [\v!left\v!bottom]
743 [\c!corner={\v!left,\v!bottom},\c!location={\v!right,\v!top}]
744
745\definelayerpreset
746 [\v!right\v!bottom]
747 [\c!corner={\v!right,\v!bottom},\c!location={\v!left,\v!top}]
748
749\definelayerpreset
750 [\v!middle]
751 [\c!corner=\v!middle,\c!location=\v!middle]
752
753\definelayerpreset
754 [\v!middle\v!top]
755 [\c!location=\v!bottom,\c!corner=\v!top,\c!dx=.5\layerwidth]
756
757\definelayerpreset
758 [\v!middle\v!bottom]
759 [\c!location=\v!top,\c!corner=\v!bottom,\c!dx=.5\layerwidth]
760
761\definelayerpreset
762 [\v!middle\v!left]
763 [\c!location=\v!right,\c!corner=\v!left,\c!dy=.5\layerheight]
764
765\definelayerpreset
766 [\v!middle\v!right]
767 [\c!location=\v!left,\c!corner=\v!right,\c!dy=.5\layerheight]
768
769
770
771\definelayerpreset
772 [\v!left\v!top\v!left]
773 [\c!location={\v!left,\v!bottom},\c!corner={\v!left,\v!top}]
774
775\definelayerpreset
776 [\v!right\v!top\v!right]
777 [\c!location={\v!right,\v!bottom},\c!corner={\v!right,\v!top}]
778
779\installcorenamespace{alignedboxes}
780
781\permanent\tolerant\protected\def\alignedbox[#1]{\bgroup\serializecommalist[#1]\dowithnextboxcs\pack_boxes_aligned_finish}
782\permanent\tolerant\protected\def\aligned [#1]{\bgroup\serializecommalist[#1]\dowithnextboxcs\pack_boxes_aligned_finish\hbox}
783
784\def\pack_boxes_aligned_finish
785 {\ifcsname\??alignedboxes\serializedcommalist\endcsname
786 \expandafter\lastnamedcs
787 \else
788 \expandafter\middlebox
789 \fi{\flushnextbox}
790 \egroup}
791
792\letcsname\??alignedboxes \endcsname\middlebox
793\letcsname\??alignedboxes\v!middle \endcsname\middlebox
794\letcsname\??alignedboxes\v!middle\v!middle\endcsname\middlebox
795\letcsname\??alignedboxes\v!left \endcsname\leftbox
796\letcsname\??alignedboxes\v!left \v!top \endcsname\lefttopbox
797\letcsname\??alignedboxes\v!left \v!bottom\endcsname\leftbottombox
798\letcsname\??alignedboxes\v!right \endcsname\rightbox
799\letcsname\??alignedboxes\v!right \v!top \endcsname\righttopbox
800\letcsname\??alignedboxes\v!right \v!bottom\endcsname\rightbottombox
801\letcsname\??alignedboxes\v!bottom \endcsname\bottombox
802\letcsname\??alignedboxes\v!bottom\v!left \endcsname\bottomleftbox
803\letcsname\??alignedboxes\v!bottom\v!right \endcsname\bottomrightbox
804\letcsname\??alignedboxes\v!top \endcsname\topbox
805\letcsname\??alignedboxes\v!top \v!left \endcsname\topleftbox
806\letcsname\??alignedboxes\v!top \v!right \endcsname\toprightbox
807\letcsname\??alignedboxes\v!line \endcsname\baselinemiddlebox
808\letcsname\??alignedboxes\v!line \v!left \endcsname\baselineleftbox
809\letcsname\??alignedboxes\v!line \v!middle\endcsname\baselinemiddlebox
810\letcsname\??alignedboxes\v!line \v!right \endcsname\baselinerightbox
811\letcsname\??alignedboxes c\endcsname\middlebox
812\letcsname\??alignedboxes l\endcsname\leftbox
813\letcsname\??alignedboxes r\endcsname\rightbox
814\letcsname\??alignedboxes b\endcsname\bottombox
815\letcsname\??alignedboxes t\endcsname\topbox
816\letcsname\??alignedboxes lt\endcsname\lefttopbox
817\letcsname\??alignedboxes lb\endcsname\leftbottombox
818\letcsname\??alignedboxes rt\endcsname\righttopbox
819\letcsname\??alignedboxes rb\endcsname\rightbottombox
820\letcsname\??alignedboxes tl\endcsname\topleftbox
821\letcsname\??alignedboxes bl\endcsname\bottomleftbox
822\letcsname\??alignedboxes tr\endcsname\toprightbox
823\letcsname\??alignedboxes br\endcsname\bottomrightbox
824\letcsname\??alignedboxes m\endcsname\middlebox
825\letcsname\??alignedboxes g\endcsname\baselinemiddlebox
826\letcsname\??alignedboxes gl\endcsname\baselineleftbox
827\letcsname\??alignedboxes gc\endcsname\baselinemiddlebox
828\letcsname\??alignedboxes gr\endcsname\baselinerightbox
829
830
831
832
833\installcorenamespace{offsetbox}
834
835\installautocommandhandler \??offsetbox {offsetbox} \??offsetbox
836
837\setupoffsetbox
838 [\c!x=\zeropoint,
839 \c!y=\zeropoint,
840 \c!width=\wd\nextbox,
841 \c!height=\ht\nextbox,
842 \c!depth=\dp\nextbox,
843 \c!location=,
844 \c!leftoffset=\zeropoint,
845 \c!rightoffset=\zeropoint,
846 \c!topoffset=\zeropoint,
847 \c!bottomoffset=\zeropoint,
848 \c!method=]
849
850\aliased\let\setupoffset\setupoffsetbox
851
852\permanent\tolerant\protected\def\offsetbox[#1]
853 {\bgroup
854 \pack_boxes_offset_check[#1]
855 \dowithnextboxcs\pack_boxes_offsetfinish}
856
857\permanent\tolerant\protected\def\offset[#1]
858 {\bgroup
859 \pack_boxes_offset_check[#1]
860 \dowithnextboxcs\pack_boxes_offsetfinish\hbox}
861
862\newcount\c_pack_boxes_offset_level
863
864\def\pack_boxes_offset_check
865 {\advance\c_pack_boxes_offset_level\plusone
866 \edef\currentoffsetbox{\the\c_pack_boxes_offset_level}
867 \checkoffsetboxparent
868 \setupcurrentoffsetbox}
869
870\def\pack_boxes_offsetfinish
871 {\donefalse
872 \scratchxposition \offsetboxparameter\c!x
873 \scratchyposition \offsetboxparameter\c!y
874 \scratchleftoffset \offsetboxparameter\c!leftoffset
875 \scratchrightoffset \offsetboxparameter\c!rightoffset
876 \scratchtopoffset \offsetboxparameter\c!topoffset
877 \scratchbottomoffset\offsetboxparameter\c!bottomoffset
878 \relax
879 \ifzeropt\scratchleftoffset \else\donetrue\fi
880 \ifzeropt\scratchrightoffset \else\donetrue\fi
881 \ifzeropt\scratchtopoffset \else\donetrue\fi
882 \ifzeropt\scratchbottomoffset\else\donetrue\fi
883 \ifdone
884 \edef\p_method{\offsetboxparameter\c!method}
885 \ifx\p_method\v!fixed
886 \ifzeropt\scratchleftoffset
887 \ifzeropt\scratchrightoffset \else
888 \scratchxposition\scratchrightoffset
889 \scratchrightoffset\zeropoint
890 \fi
891 \else
892 \scratchxposition\scratchleftoffset
893 \scratchleftoffset\zeropoint
894 \fi
895 \ifzeropt\scratchtopoffset
896 \ifzeropt\scratchbottomoffset \else
897 \scratchyposition\scratchbottomoffset
898 \scratchbottomoffset\zeropoint
899 \fi
900 \else
901 \scratchyposition\scratchtopoffset
902 \scratchtopoffset\zeropoint
903 \fi
904 \donefalse
905 \fi
906 \fi
907 \ifdone
908 \setbox\nextbox\vpack
909 {\forgetall
910 \offinterlineskip
911 \kern\scratchtopoffset
912 \hpack
913 {\kern\scratchleftoffset
914 \box\nextbox
915 \kern\scratchrightoffset}
916 \kern\scratchbottomoffset}
917 \ht\nextbox\htdp\nextbox
918 \dp\nextbox\zeropoint
919 \fi
920 \scratchwidth \offsetboxparameter\c!width
921 \scratchheight\offsetboxparameter\c!height
922 \scratchdepth \offsetboxparameter\c!depth
923 \edef\p_location{\offsetboxparameter\c!location}
924 \setbox\nextbox\hpack
925 {\kern\scratchxposition
926 \lower\scratchyposition\hpack
927 {\ifempty\p_location
928 \box\nextbox
929 \else
930 \alignedbox[\p_location]\hpack{\box\nextbox}
931 \fi}}
932 \wd\nextbox\scratchwidth
933 \ht\nextbox\scratchheight
934 \dp\nextbox\scratchdepth
935 \box\nextbox
936 \egroup}
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972\def\pack_boxes_tabbed#1#2#3#4
973 {\dontleavehmode
974 \begingroup
975 \setbox\scratchbox\hpack{#3}
976 \hpack to \wd\scratchbox{#1#4#2}
977 \endgroup}
978
979\permanent\protected\def\ltabbed{\pack_boxes_tabbed\relax\hss}
980\permanent\protected\def\rtabbed{\pack_boxes_tabbed\hss \relax}
981\permanent\protected\def\ctabbed{\pack_boxes_tabbed\hss \hss}
982
983\aliased\let\mtabbed\ctabbed
984
985
986
987\permanent\protected\def\phantombox[#1]
988 {\hpack\bgroup
989 \letdummyparameter\c!width \zeropoint
990 \letdummyparameter\c!height\zeropoint
991 \letdummyparameter\c!depth \zeropoint
992 \getdummyparameters[#1]
993 \setbox\scratchbox\emptyhbox
994 \wd\scratchbox\directdummyparameter\c!width
995 \ht\scratchbox\directdummyparameter\c!height
996 \dp\scratchbox\directdummyparameter\c!depth
997 \box\scratchbox
998 \egroup}
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020\permanent\protected\def\backgroundimage#1#2#3
1021 {\bgroup
1022 \forgetall
1023 \scratchcounter#1\relax
1024 \scratchwidth #2\relax
1025 \scratchheight #3\relax
1026 \dowithnextboxcs\pack_boxes_background_image\hbox}
1027
1028\def\pack_boxes_background_image
1029 {\offinterlineskip
1030 \ifcase\scratchcounter
1031
1032 \else
1033 \scratchdimen\scratchwidth \divide\scratchdimen\wd\nextbox\scratchnx\scratchdimen\advance\scratchnx\plusone\relax
1034 \scratchdimen\scratchheight\divide\scratchdimen\ht\nextbox\scratchny\scratchdimen\advance\scratchny\plusone\relax
1035
1036 \ifcase\scratchcounter
1037 \or
1038 \setbox\nextbox\hpack{\dorecurse\scratchnx{\copy\nextbox}}
1039 \setbox\nextbox\vpack{\dorecurse\scratchny{\copy\nextbox\endgraf}}
1040 \or
1041 \setbox\nextbox\hpack{\dorecurse\scratchnx{\copy\nextbox}}
1042 \or
1043 \setbox\nextbox\vpack{\dorecurse\scratchny{\copy\nextbox\endgraf}}
1044 \fi
1045 \fi
1046 \ifdim\wd\nextbox>\scratchwidth
1047 \setbox\nextbox\hpack to \scratchwidth{\hss\box\nextbox\hss}
1048 \setbox\nextbox\hpack{\normalexpanded{\clip[\c!width=\the\scratchwidth,\c!height=\the\ht\nextbox]{\box\nextbox}}}
1049 \fi
1050 \ifdim\ht\nextbox>\scratchheight
1051 \setbox\nextbox\vpack to \scratchheight{\vss\box\nextbox\vss}
1052 \setbox\nextbox\hpack{\normalexpanded{\clip[\c!width=\the\wd\nextbox,\c!height=\the\scratchheight]{\box\nextbox}}}
1053 \fi
1054 \box\nextbox
1055 \egroup}
1056
1057\permanent\protected\def\backgroundimagefill#1#2#3
1058 {\bgroup
1059 \forgetall
1060 \scratchcounter#1\relax
1061 \scratchwidth #2\relax
1062 \scratchheight #3\relax
1063 \dowithnextboxcs\pack_boxes_background_image_fill\hbox}
1064
1065\def\pack_boxes_background_image_fill
1066 {\offinterlineskip
1067 \setbox\nextbox\hpack\bgroup
1068 \ifdim\scratchwidth>\scratchheight
1069 \scale[\c!width=\the\scratchwidth]{\box\nextbox}
1070 \else
1071 \scale[\c!height=\the\scratchheight]{\box\nextbox}
1072 \fi
1073 \egroup
1074 \ifdim\wd\nextbox>\scratchwidth
1075 \setbox\nextbox\hpack to \scratchwidth
1076 {\ifcase\scratchcounter
1077 \hss\box\nextbox\hss
1078 \or
1079 \box\nextbox\hss
1080 \or
1081 \hss\box\nextbox
1082 \else
1083 \hss\box\nextbox\hss
1084 \fi}
1085 \setbox\nextbox\hpack
1086 {\normalexpanded{\clip[\c!width=\the\scratchwidth,\c!height=\the\ht\nextbox]{\box\nextbox}}}
1087 \fi
1088 \ifdim\ht\nextbox>\scratchheight
1089 \setbox\nextbox\vpack to \scratchheight
1090 {\ifcase\scratchcounter
1091 \vss\box\nextbox\vss
1092 \or
1093 \box\nextbox\vss
1094 \or
1095 \vss\box\nextbox
1096 \else
1097 \vss\box\nextbox\vss
1098 \fi}
1099 \setbox\nextbox\hpack
1100 {\normalexpanded{\clip[\c!width=\the\wd\nextbox,\c!height=\the\scratchheight]{\box\nextbox}}}
1101 \fi
1102 \box\nextbox
1103 \egroup}
1104
1105\permanent\protected\def\overlayimage#1
1106 {\vpack to \overlayheight\bgroup
1107 \vss
1108 \hpack to \overlaywidth\bgroup
1109 \hss
1110 \externalfigure[#1][\c!factor=\v!min,\c!equalwidth=\overlaywidth,\c!equalheight=\overlayheight]
1111 \hss
1112 \egroup
1113 \vss
1114 \egroup}
1115
1116\permanent\protected\def\clippedoverlayimage#1
1117 {\clip
1118 [\c!width=\overlaywidth,\c!height=\overlayheight]
1119 {\overlayimage{#1}}}
1120
1121\protect \endinput
1122 |