summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkxl/scrn-pag.mklx
blob: 09c542678fdbd58c882d0d287d5ea0bd18178d76 (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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
%D \module
%D   [       file=scrn-pag,
%D        version=1998.01.15,
%D          title=\CONTEXT\ Screen Macros,
%D       subtitle=Pages, % moved code
%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.

% pagecomments will be done differently

\writestatus{loading}{ConTeXt Screen Macros / Pages}

\registerctxluafile{scrn-pag}{autosuffix}

\unprotect

\installcorenamespace{interactionscreen}

\installparameterhandler \??interactionscreen {interactionscreen}
\installsetuphandler     \??interactionscreen {interactionscreen}

\newdimen\canvaswidth
\newdimen\canvasheight
\newdimen\canvasbackoffset
\newdimen\canvastopoffset
\newdimen\canvasmaxwidth
\newdimen\canvasmaxheight
\newdimen\canvascropoffset
\newdimen\canvastrimoffset
\newdimen\canvasbleedoffset
\newdimen\canvasartoffset

\mutable\let\currentinteractionscreendelay \empty
\mutable\let\currentinteractionscreenheight\empty
\mutable\let\currentinteractionscreenwidth \empty

\newconditional\c_scrn_canvas_tight_page

\def\scrn_canvas_calculate
  {\begingroup
   \edef\currentinteractionscreenwidth {\interactionscreenparameter\c!width }%
   \edef\currentinteractionscreenheight{\interactionscreenparameter\c!height}%
   \canvasbackoffset\backspace
   \canvastopoffset\topspace
   \donetrue
   \ifx\currentinteractionscreenwidth\v!max
     \global\canvaswidth\printpaperwidth
   \orelse\ifx\currentinteractionscreenwidth\v!fit
     \donefalse
     \global\canvaswidth\dimexpr
       \leftcombitotal
     + \makeupwidth
     + \rightcombitotal
     + 2\dimexpr
          \interactionscreenparameter\c!backspace
        + \interactionscreenparameter\c!horoffset
        \relax
     \relax
   \orelse\ifx\currentinteractionscreenwidth\v!tight
     \donefalse
     \ifdim\backspace>\canvaswidth
       \ifdim\backspace>\zeropoint\relax
         \global\advance\canvasbackoffset -\canvaswidth
       \fi
     \fi
     \global\advance\canvaswidth\dimexpr
       \makeupwidth
     + \rightcombitotal
     + 2\dimexpr
          \interactionscreenparameter\c!backspace
        + \interactionscreenparameter\c!horoffset
        \relax
     \relax
   \else
     \donefalse
     \global\canvaswidth\currentinteractionscreenwidth
   \fi
   \ifx\currentinteractionscreenheight\v!max
     \global\canvasheight\printpaperheight
   \orelse\ifx\currentinteractionscreenheight\v!fit
     \donefalse
     \global\canvasheight\dimexpr
       \topheight
     + \topdistance
     + \makeupheight
     + \bottomdistance
     + \bottomheight
     + 2\dimexpr
          \interactionscreenparameter\c!topspace
        + \interactionscreenparameter\c!veroffset
        \relax
     \relax
   \orelse\ifx\currentinteractionscreenheight\v!tight
     \donefalse
     \global\canvasheight\dimexpr\topheight+\topdistance\relax
     \ifdim\topspace>\canvasheight
       \ifdim\topspace>\zeropoint\relax
         \global\advance\canvastopoffset -\canvasheight
       \fi
     \fi
     \global\advance\canvasheight\dimexpr
       \makeupheight
     + \bottomdistance
     + \bottomheight
     + 2\dimexpr
          \interactionscreenparameter\c!topspace
        + \interactionscreenparameter\c!veroffset
        \relax
     \relax
   \else
     \donefalse
     \global\canvasheight\currentinteractionscreenheight
   \fi
   \ifconditional\c_page_layouts_location_is_set
     \global\setfalse\c_scrn_canvas_tight_page
   \fi
   \ifconditional\c_scrn_canvas_tight_page
     \global\canvasmaxwidth \paperwidth
     \global\canvasmaxheight\paperheight
   \else
     \global\canvasmaxwidth \printpaperwidth
     \global\canvasmaxheight\printpaperheight
   \fi
   % new:
   \ifdone
     \global\canvascropoffset \layoutcropoffset
     \global\canvastrimoffset \layouttrimoffset
     \global\canvasbleedoffset\layoutbleedoffset
     \global\canvasartoffset  \layoutartoffset
   \else
     \global\canvascropoffset \zeropoint
     \global\canvastrimoffset \zeropoint
     \global\canvasbleedoffset\zeropoint
     \global\canvasartoffset  \zeropoint
   \fi
   \endgroup}

\newdimen\layoutcropoffset
\newdimen\layouttrimoffset
\newdimen\layoutbleedoffset
\newdimen\layoutartoffset

\appendtoks
   \edef\p_cropoffset{\layoutparameter\c!cropoffset}%
   \ifx\p_cropoffset\v!auto
     \ifconditional\c_page_layouts_location_is_middle
       \scratchheight\dimexpr(\printpaperheight-\paperheight)/2\relax
       \scratchwidth \dimexpr(\printpaperwidth -\paperwidth )/2\relax
       \layoutcropoffset\ifdim\scratchheight>\scratchwidth\scratchheight\else\scratchwidth\fi
       \layouttrimoffset \layoutparameter\c!trimoffset
       \layoutbleedoffset\layoutparameter\c!bleedoffset
       \layoutartoffset  \layoutparameter\c!artoffset
     \else
       \writestatus\m!system{auto crop etc only supported when location=middle}%
       \layoutcropoffset \zeropoint
       \layouttrimoffset \zeropoint
       \layoutbleedoffset\zeropoint
       \layoutartoffset  \zeropoint
     \fi
   \else
     \layoutcropoffset \layoutparameter\c!cropoffset
     \layouttrimoffset \layoutparameter\c!trimoffset
     \layoutbleedoffset\layoutparameter\c!bleedoffset
     \layoutartoffset  \layoutparameter\c!artoffset
   \fi
   \relax
\to \everysetuplayout

\setuplayout
  [\c!cropoffset=\zeropoint,
   \c!trimoffset=\zeropoint,
   \c!bleedoffset=\zeropoint,
   \c!artoffset=\zeropoint]

% test the next when something is changed here:
%
% \setuppapersize[A5][A3]  \showframe
%
% % \setuplayout[location=middle] \setupinteractionscreen[option=fit]
% % \setuplayout[location=middle] \setupinteractionscreen[option=auto]
% %                               \setupinteractionscreen[option=fit]
% %                               \setupinteractionscreen[option=auto]
%
% \starttext \input ward \stoptext

\let\scrn_canvas_synchronize_simple \relax
\let\scrn_canvas_synchronize_complex\relax

\appendtoks
    \glet\scrn_canvas_synchronize_simple \scrn_canvas_synchronize_simple_indeed
    \glet\scrn_canvas_synchronize_complex\scrn_canvas_synchronize_complex_indeed
\to \everysetuplayout

\appendtoks
    \glet\scrn_canvas_synchronize_simple \scrn_canvas_synchronize_simple_indeed
    \glet\scrn_canvas_synchronize_complex\scrn_canvas_synchronize_complex_indeed
\to \everysetuplayouttarget

\def\scrn_canvas_synchronize_common {
    mode        {\interactionscreenparameter\c!option}%
    singlesided \ifsinglesided true\else false\fi\space
    doublesided \ifdoublesided true\else false\fi\space
    copies      \numexpr\interactionscreenparameter\c!copies\relax
    print       {\interactionscreenparameter\c!print}%
}

\appendtoks
    \let\scrn_canvas_synchronize_common\empty
\to \everyaftershipout

\def\scrn_canvas_synchronize_only
  {\clf_setupcanvas
     paperwidth  \printpaperwidth
     paperheight \printpaperheight
     \scrn_canvas_synchronize_common
   \relax}

\def\scrn_canvas_synchronize_set#width#height%
  {\clf_setupcanvas
     paperwidth  \dimexpr#width\relax
     paperheight \dimexpr#height\relax
   \relax}

\let\scrn_canvas_synchronize_reset\scrn_canvas_synchronize_only

\def\scrn_canvas_synchronize_simple_indeed
  {\scrn_canvas_synchronize_only
  %\glet\scrn_canvas_synchronize_simple \relax
   \glet\scrn_canvas_synchronize_complex\relax}

\def\scrn_canvas_synchronize_complex_indeed
  {\scrn_canvas_calculate % otherwise we need to hook it into setuppage etc
   \clf_setupcanvas
        leftoffset  \canvasbackoffset
        topoffset   \canvastopoffset
        width       \canvaswidth
        height      \canvasheight
        paperwidth  \canvasmaxwidth
        paperheight \canvasmaxheight
        cropoffset  \canvascropoffset
        trimoffset  \canvastrimoffset
        bleedoffset \canvasbleedoffset
        artoffset   \canvasartoffset
        \scrn_canvas_synchronize_common
   \relax
  %\glet\scrn_canvas_synchronize_simple \relax
   % one shot only
   \glet\scrn_canvas_synchronize_complex\relax}

\appendtoks
    \begingroup
    \edef\p_option{\interactionscreenparameter\c!option}%
    \ifx\p_option\v!max
      \global\settrue \c_scrn_canvas_tight_page
    \orelse\ifx\p_option\v!fit
      \global\settrue \c_scrn_canvas_tight_page
    \else
      \global\setfalse\c_scrn_canvas_tight_page
    \fi
    \endgroup
\to \everysetupinteractionscreen

\setupinteractionscreen
  [\c!width=\printpaperwidth,
   \c!height=\printpaperheight,
   \c!horoffset=\zeropoint,
   \c!veroffset=\zeropoint,
   \c!backspace=\backspace,
   \c!topspace=\topspace,
   \c!copies=\plusone, % not the best place but backend anyway
   \c!option=\v!auto]

\appendtoks
    \glet\scrn_canvas_synchronize_simple \scrn_canvas_synchronize_simple_indeed
    \glet\scrn_canvas_synchronize_complex\scrn_canvas_synchronize_complex_indeed
\to \everysetupinteractionscreen

%D Conditional page breaks:

\permanent\tolerant\protected\def\screen[#list]%
  {\iflocation
     \page[#list]%
   \fi}

%D Page transitions:

\let\scrn_transitions_list\empty

\permanent\tolerant\protected\def\setuppagetransitions[#list]%
  {\edef\scrn_transitions_list{#list}%
   \ifx\scrn_transitions_list\v!reset
     \let\scrn_transitions_list\empty
   \fi}

\def\scrn_transitions_set
  {\iflocation \ifempty\scrn_transitions_list \else
     \scrn_transitions_set_indeed
   \fi \fi}

\def\scrn_transitions_set_indeed
  {\begingroup
   \edef\currentinteractionscreendelay{\interactionscreenparameter\c!delay}%
   \clf_setpagetransition
      n     {\scrn_transitions_list}%
      delay \ifx\currentinteractionscreendelay\v!none \zerocount\else\currentinteractionscreendelay\fi
   \relax
   \endgroup}

\prependtoks
    \scrn_transitions_set
\to \everyshipout

\setupinteractionscreen
  [\c!delay=\v!none]

\setuppagetransitions
  [\v!reset]

\protect \endinput