summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/page-log.mkii
blob: 18c7991b1b7a8836bbb536adf139747666c92686 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
%D \module
%D   [       file=page-log, % moved here from main-001
%D        version=1997.03.31,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Logos,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%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 / Logos}

\unprotect

%D Although logos can conveniently be implemented on top of
%D background and text areas, we provide a dedicated mechanism
%D here. One reason is that such a separate mechanism cannot
%D interfere with the other ones, but an even more important
%D reason is that logos are kind of special in the sense that
%D they have a short life span and may change after the first
%D page.

%D \macros
%D  {recalculatelogos,addlogobackground}
%D
%D The interface to the other low level page building routines
%D is provided by a macro that signals changes in layout
%D specifications:
%D
%D \starttyping
%D \recalculatelogos
%D \stoptyping
%D
%D as well as a simple placement macro:
%D
%D \starttyping
%D \addlogobackground <box>
%D \stoptyping
%D
%D In no way the following boolean switch should be used
%D directly.

\newif\ifnewlogos

\def\recalculatelogos
  {\global\newlogostrue}

%D The current state of logos is registered in a status
%D variable \type {\logostatus}.
%D
%D \starttabulate[|l|l|l|]
%D \NC 0 \NC don't place              \NC remains 0 \NC \NR
%D \NC 1 \NC place now                \NC remains 1 \NC \NR
%D \NC 2 \NC calulate and place       \NC becomes 1 \NC \NR
%D \NC 3 \NC calculate and place once \NC becomes 2 \NC \NR
%D \stoptabulate

\chardef\logostatus=0

\def\addlogobackground#1% todo: dimension spec
  {\ifcase\logostatus \else
     \ifcase\logostatus
       % no logos to take care of
     \or % 1
       \ifnewlogos
         \chardef\logostatus2
         \setlogoboxes
         \chardef\logostatus1
         \global\newlogosfalse
       \fi
     \or % 2
       \setlogoboxes
       \chardef\logostatus1
     \or % 3
       \setlogoboxes
       \global\chardef\logostatus2
     \fi
     \setbox#1\vbox
       {\offinterlineskip
        \doifmarginswapelse
          {\copy\leftlogos}
          {\copy\rightlogos}
        \box#1}%
   \fi}

%D For efficiency reasons (and since logos seldom change inside
%D a document) we can save the left and right hand (or first
%D and following page) logos in boxes. The areas are slightly
%D different from the ones used in backgrounds and text
%D placement, but still related to the page layout. The {\em
%D left} and {\em right edge}, as well as {\em top} and {\em
%D bottom} touch the bounding box of the paper and are
%D therefore not the sams as their background adn text
%D counterparts. In addition there are {\em left}, {\em right}
%D and {\em middle} areas as well as a {\em page} one.

\newbox\leftlogos
\newbox\rightlogos

\def\setlogoboxes
  {\showmessage\m!layouts7\empty
   \dosetlogobox\leftlogos\relax
   \ifdoublesided
     \dosetlogobox\rightlogos\doswapmargins
   \fi}

\def\dosetlogobox#1#2%
  {\global\setbox#1\vbox to \paperheight
     {\dontcomplain           % needed here ?
      \calculatereducedvsizes % needed here ?
      \offinterlineskip
      #2\relax
      \vskip-\topspace
      \dodosetlogobox\v!top\blap
      \vskip\topspace
      \dodosetlogobox\v!header\blap
      \vskip\dimexpr\headerheight+\headerdistance\relax
      \dodosetlogobox\v!text\blap
      \vskip\dimexpr\textheight+\footerdistance+\footerheight\relax
      \dodosetlogobox\v!footer \tlap
      \vfilll
      \dodosetlogobox\v!bottom\tlap
      \vskip\topspace}
  \smashbox#1}

\def\dodosetlogobox#1#2%
  {\hbox % width equals \makeupwidth
     {\def\docommand##1%
        {\donefalse
         \ifnum\logostatus=3 \ExpandBothAfter
           \doifinset{\getvalue{\??lo#1##1}}\requestedlogos\donetrue
         \else
           \doifvalue{\??lo#1##1\c!state}\v!start\donetrue
         \fi
         \ifdone
           #2{\hbox{\getvalue{\??lo#1##1\c!command}}}%
         \fi}%
      \def\dodocommand##1##2##3##4##5##6%
        {\hsmash
           {\hskip-\texthoffset
            \hbox to \paperwidth
              {\rlap{\docommand##1}\hss\llap{\docommand##6}}%
            \hskip-\paperwidth
            \hbox to \paperwidth
              {\hskip\texthoffset
               \hskip-\leftmarginwidth
               \hskip-\leftmargindistance
               \hbox to \leftmarginwidth{\docommand##2\hss}%
               \hskip\leftmargindistance
               \hbox to \makeupwidth{\docommand##3\hss\docommand##4}%
               \hskip\rightmargindistance
               \hbox to \rightmarginwidth{\hss\docommand##5}%
               \hfill}}}%
      \normalbaselines
      \settexthoffset
      \hsmash
        {\hbox to \makeupwidth{\hss\docommand\c!middle\hss}}%
      \hsmash
        {\hskip-\texthoffset
         \hbox to \paperwidth{\docommand\v!page\hss}}%
      \swapmargins
      \doifbothsidesoverruled
        {\dodocommand
          \v!leftedge \v!leftmargin  \v!left
          \v!right     \v!rightmargin \v!rightedge}
        {\dodocommand
          \v!leftedge \v!leftmargin  \v!left
          \v!right     \v!rightmargin \v!rightedge}
        {\dodocommand
          \v!rightedge \v!rightmargin \v!right
          \v!left       \v!leftmargin  \v!leftedge}}}

%D The user interface is relatively simple and provides
%D macros for assigning logos to logo areas as well as
%D forcing placement.
%D
%D \showsetup{definelogo}
%D \showsetup{placelogos}

\let\definedlogos  \empty
\let\requestedlogos\empty

\long\def\dodefinelogo[#1][#2][#3][#4]%
  {\addtocommalist{#1}\definedlogos
   \long\setvalue{\??lo#2#3}{#1}%
   \getparameters[\??lo#2#3][#4]%
   \global\chardef\logostatus2 }

\def\definelogo
  {\doquadrupleargument\dodefinelogo}

\def\placelogos
  {\dosingleempty\doplacelogos}

\def\doplacelogos[#1]%
  {\xdef\requestedlogos{\iffirstargument#1\else\definedlogos\fi}%
   \global\chardef\logostatus3 }

\protect \endinput