summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/page-app.mkiv
blob: e4858d48ffba9a80b848117b0940ef9b61fa7969 (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
%D \module
%D   [       file=page-app, % from meta-fig
%D        version=1998.01.15,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Independent page building,
%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 / Applications}

%D This needs an update with a proper define and inheritance.

\unprotect

\installcorenamespace{fittingpage}

\installframedcommandhandler \??fittingpage {fittingpage} \??fittingpage

\newdimen\d_page_fitting_width
\newdimen\d_page_fitting_height
\newbox  \b_page_fitting

\definepapersize
  [fittingpage]
  [\c!width=\d_page_fitting_width,
   \c!height=\d_page_fitting_height]

\definemakeup
  [fittingpage]
  [\c!textstate=\v!empty,
   \c!doublesided=\v!no,
   \c!location=\v!top, % no topskip
   \c!pagestate=\fittingpageparameter\c!pagestate]%

\definelayout
  [fittingpage]
  [\v!page]
  [\c!width=\d_page_fitting_width,
   \c!height=\d_page_fitting_height,
   \c!location=\v!middle]

\appendtoks
    \setuevalue{\e!start\currentfittingpage}{\startfittingpage[\currentfittingpage]}%
    \setuevalue{\e!stop \currentfittingpage}{\stopfittingpage}%
\to \everydefinefittingpage

\unexpanded\def\startfittingpage
   {\dodoubleempty\page_fitting_start}

\def\page_fitting_start[#1][#2]%
  {\page % this is kind of tricky! there can be preceding page refs
   \autostarttext
   \bgroup % resulting in a zero height page; test fig-make !
   \setupinterlinespace[\v!top=0]% no topskip
   \def\currentfittingpage{#1}%
   \dontcomplain
   % runs under current page regime, i.e. page variables passed to mp
   \setupcurrentfittingpage[\c!paper=,#2]% auto or size or nothing
   \doifelsenothing{\fittingpageparameter\c!command}
     \page_fitting_start_normal
     \page_fitting_start_command}

\def\page_fitting_start_command
  {\grabuntil{\e!stop\currentfittingpage}\page_fitting_stop_command}

\def\page_fitting_stop_command#1%
  {\page_fitting_start_normal
   \fittingpageparameter\c!command{#1}%
   \page_fitting_stop_normal}

\def\page_fitting_start_normal
   {\setbox\b_page_fitting\hbox
      \bgroup
      \inheritedfittingpageframed
      \bgroup
      \gobblespacetokens}

\unexpanded\def\page_fitting_stop_normal % todo: figure out why a small mp image gets shifted
  {\removeunwantedspaces
   \egroup
   \egroup
   % finalize
   \doif{\fittingpageparameter\c!margin}\v!page
     {\setbox\b_page_fitting\hbox\bgroup
        \offsetbox
          [\c!leftoffset=\backspace,
           \c!rightoffset=\cutspace,
           \c!topoffset=\topspace,
           \c!bottomoffset=\bottomspace]
          {\box\b_page_fitting}%
       \egroup}%
   \doifsomething{\fittingpageparameter\c!scale}
     {\setbox\b_page_fitting\hbox\bgroup
        \scale[\c!scale=\fittingpageparameter\c!scale]{\box\b_page_fitting}%
      \egroup}%
   \ifdim\ht\b_page_fitting=\zeropoint
     \ht\b_page_fitting\onepoint
   \fi
   \ifdim\wd\b_page_fitting=\zeropoint
     \wd\b_page_fitting\onepoint
   \fi
   \d_page_fitting_width \wd\b_page_fitting
   \d_page_fitting_height\ht\b_page_fitting
   \startlocallayout % hm, we change the papersize so we still need it
   \let\checkcurrentlayout\relax % else interference with odd/even layout
   \processaction
     [\fittingpageparameter\c!paper]
     [   \v!auto=>\def\fittingpapersize{\printpapersize},
      \s!unknown=>\let\fittingpapersize\commalistelement,
      \s!default=>\def\fittingpapersize{fittingpage}]%
   \expanded{\setuppapersize[fittingpage][\fittingpapersize]}%
   \startmakeup[fittingpage]%
     \box\b_page_fitting
   \stopmakeup
   \stoplocallayout % we need to get rid of this and use the built-in
   \egroup
   \autostoptext}

\let\stopfittingpage\page_fitting_stop_normal

\setupfittingpage
  [%\c!scale=1000,
   %\c!pagestate=,
   \c!strut=\v!no,
   \c!align=\v!normal,
   \c!offset=\v!overlay,
   \c!width=\v!fit,
   \c!height=\v!fit,
   \c!frame=\v!off]

%D \TEX\ pages (for \METAPOST\ pages, see \type {meta-fig}):

\definefittingpage
  [TEXpage]
  [\c!align=\v!normal] % needed, else problems !

%D For Mojca:
%D
%D \starttyping
%D \startTEXstream \chapter{Bla} Hello world!\crlf Hello world! \stopTEXstream
%D \startTEXpage   \chapter{Bla} Hello world!\crlf Hello world! \stopTEXpage
%D \stoptyping
%D
%D maybe I should support stream=yes in framed.

\unexpanded\def\startTEXstream
  {\dosingleempty\page_streams_TEX_start}

\def\page_streams_TEX_start[#1]% old code, to be redone
  {\page
   \enableoutputstream[tex]}

\unexpanded\def\stopTEXstream
  {\disableoutputstream
   \startTEXpage
     \outputstreamunvbox[tex]%
   \stopTEXpage}

%D Application pages, a quick \MKIV\ hack:

\definetypesetting[TEXapplication]
\definebuffer[TEXapplication]

% we could use a counter and saves runs on numbering them.

\def\TEXapplicationfilename{\jobname-texapplication.tex}

\unexpanded\def\stopTEXapplication
  {\savebuffer[\thedefinedbuffer{TEXapplication}][\TEXapplicationfilename]%
   \typesetfile[TEXapplication][\TEXapplicationfilename]\relax}

%D \macros
%D   {startpagefigure}
%D
%D \starttyping
%D \starttext \pagefigure[two.1] \stoptext
%D \stoptyping

\defineexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay] % we force a parent

\unexpanded\def\startpagefigure
  {\dodoubleempty\page_figures_start}

% this one:
%
% \def\page_figures_start[#1][#2]%
%   {\bgroup
%    \def\currentexternalfigure{\v!page:\v!figure}%
%    \setupcurrentexternalfigure[\c!offset=\v!overlay,#2]%
%    \startTEXpage[\c!offset=\externalfigureparameter\c!offset]%
%      \externalfigure[#1]\ignorespaces} % so we can put some text below the graphic
%
% or this one:

\def\page_figures_start[#1][#2]%
  {\bgroup
   \setupexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay,#2]%
   \startTEXpage[\c!offset=\namedexternalfigureparameter{\v!page:\v!figure}\c!offset]%
     \externalfigure[#1]\ignorespaces} % so we can put some text below the graphic

\unexpanded\def\stoppagefigure
  {\stopTEXpage
   \egroup}

\unexpanded\def\pagefigure
  {\dodoubleempty\page_figure}

\def\page_figure[#1][#2]%
  {\page_figures_start[#1][#2]\stoppagefigure}

\protect \endinput