summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/page-fac.mkiv
blob: 88789abe9fb0ea4817611032a88c03825f068cbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
%D \module
%D   [       file=page-fac,   % moved from page-ini
%D        version=2011.12.07, % 2000.10.20,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Facing Pages,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Page Macros / Facing Pages}

\unprotect

%D \macros
%D   {setupoppositeplacing,startopposite}
%D
%D \starttyping
%D \starttext
%D test \startopposite \blackrule[width=3cm,height=4cm] \stopopposite test
%D test \startopposite \blackrule[width=3cm,height=4cm] \stopopposite test
%D \stoptext
%D \stoptyping

\newbox        \b_page_facings_content
\newconditional\c_page_facings_busy

\installcorenamespace{oppositeplacing}

\installsetuponlycommandhandler \??oppositeplacing {oppositeplacing}

\unexpanded\def\startopposite
  {\dowithnextboxcontent
     {\hsize\makeupwidth}%
     {\global\setbox\b_page_facings_content\vbox
        {\ifvoid\b_page_facings_content
           \directoppositeplacingparameter\c!before
         \else
           \directoppositeplacingparameter\c!inbetween
           \unvbox\b_page_facings_content
         \fi
         \box\nextbox}}%
     \vbox\bgroup}

\unexpanded\def\stopopposite
  {\egroup}

\def\page_facings_finish
  {\ifvoid\b_page_facings_content \else
     \global\setbox\b_page_facings_content\vbox to \makeupheight
       {\unvbox\b_page_facings_content
        \directoppositeplacingparameter\c!after
        \vss}%
   \fi}

\def\page_facings_flush
  {\ifconditional\c_page_facings_busy
     \ifvoid\b_page_facings_content \else
        \page_facings_flush_indeed
     \fi
   \fi}

\def\page_facings_flush_indeed
  {\ifnum\realpageno>\plusone
     \begingroup
     \pageornamentstate\plusone % tricky
     \page_facings_finish
     \page_boxes_shipout{\page_boxes_constructed_page\box\b_page_facings_content}%
     \endgroup
   \else
     \global\setbox\b_page_facings_content\emptybox
   \fi}

\appendtoks
    \doifelse{\directoppositeplacingparameter\c!state}\v!start\settrue\setfalse\c_page_facings_busy
\to \everysetupoppositeplacing

\setupoppositeplacing
  [\c!state=\v!start,
   \c!before=,
   \c!inbetween=\blank,
   \c!after=]

\protect \endinput