page-app.mkxl /size: 6411 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=page-app, % from meta-fig
3%D        version=1998.01.15,
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Independent page building,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Page Macros / Applications}
15
16%D This needs an update with a proper define and inheritance.
17
18\unprotect
19
20\installcorenamespace{fittingpage}
21
22\installframedcommandhandler \??fittingpage {fittingpage} \??fittingpage
23
24\newdimension\d_page_fitting_width
25\newdimension\d_page_fitting_height
26\newbox      \b_page_fitting
27
28\definepapersize
29  [fittingpage]
30  [\c!width=\d_page_fitting_width,
31   \c!height=\d_page_fitting_height]
32
33\definemakeup
34  [fittingpage]
35  [\c!textstate=\v!empty,
36   \c!doublesided=\v!no,
37   \c!location=\v!top, % no topskip
38   \c!pagestate=\fittingpageparameter\c!pagestate]%
39
40\definelayout
41  [fittingpage]
42  [\v!page]
43  [\c!width=\d_page_fitting_width,
44   \c!height=\d_page_fitting_height,
45   \c!location=\v!middle]
46
47\appendtoks
48    \frozen\instance\protected\edefcsname\e!start\currentfittingpage\endcsname{\startfittingpage[\currentfittingpage]}%
49    \frozen\instance\protected\edefcsname\e!stop \currentfittingpage\endcsname{\stopfittingpage}%
50\to \everydefinefittingpage
51
52\permanent\tolerant\protected\def\startfittingpage[#1]#*[#S#2]%
53  {\page % this is kind of tricky! there can be preceding page refs
54   \autostarttext
55   \bgroup % resulting in a zero height page; test fig-make !
56   \setupinterlinespace[\v!top=0]% no topskip
57   \cdef\currentfittingpage{#1}%
58   \dontcomplain
59   % runs under current page regime, i.e. page variables passed to mp
60   \setupcurrentfittingpage[\c!paper=,#2]% auto or size or nothing
61   \ifempty{\fittingpageparameter\c!command}%
62     \expandafter\page_fitting_start_normal
63   \else
64     \expandafter\page_fitting_start_command
65   \fi}
66
67\def\page_fitting_start_command
68  {\grabuntil{\e!stop\currentfittingpage}\page_fitting_stop_command}
69
70\def\page_fitting_stop_command#1%
71  {\page_fitting_start_normal
72   \fittingpageparameter\c!command{#1}%
73   \page_fitting_stop_normal}
74
75\def\page_fitting_start_normal
76   {\setbox\b_page_fitting\hbox
77      \bgroup
78      \inheritedfittingpageframed
79      \bgroup
80      \pack_framed_initialize
81      \gobblespacetokens}
82
83\protected\def\page_fitting_stop_normal % todo: figure out why a small mp image gets shifted
84  {\removeunwantedspaces
85   \egroup
86   \egroup
87   % finalize
88   \ifcstok{\fittingpageparameter\c!margin}\v!page
89     \setbox\b_page_fitting\hpack\bgroup
90       \offsetbox
91         [\c!leftoffset=\backspace,
92          \c!rightoffset=\cutspace,
93          \c!topoffset=\topspace,
94          \c!bottomoffset=\bottomspace]
95         {\box\b_page_fitting}%
96     \egroup
97   \fi
98   \ifempty{\fittingpageparameter\c!scale}\else
99     \setbox\b_page_fitting\hpack\bgroup
100       \scale[\c!scale=\fittingpageparameter\c!scale]{\box\b_page_fitting}%
101     \egroup
102   \fi
103   \ifzeropt\ht\b_page_fitting
104     \ht\b_page_fitting\onepoint
105   \fi
106   \ifzeropt\wd\b_page_fitting
107     \wd\b_page_fitting\onepoint
108   \fi
109   \d_page_fitting_width \wd\b_page_fitting
110   \d_page_fitting_height\ht\b_page_fitting
111   \startlocallayout % hm, we change the papersize so we still need it
112   \enforced\let\checkcurrentlayout\relax % else interference with odd/even layout
113   \processaction
114     [\fittingpageparameter\c!paper]
115     [   \v!auto=>\let\scratchstringone\printpapersize,
116      \s!unknown=>\let\scratchstringone\commalistelement,
117      \s!default=>\def\scratchstringone{fittingpage}]%
118   \normalexpanded{\setuppapersize[fittingpage][\scratchstringone]}%
119   \startmakeup[fittingpage]%
120     \box\b_page_fitting
121   \stopmakeup
122   \stoplocallayout % we need to get rid of this and use the built-in
123   \egroup
124   \autostoptext}
125
126\permanent\let\stopfittingpage\page_fitting_stop_normal
127
128\setupfittingpage
129  [%\c!scale=1000,
130   %\c!pagestate=,
131   \c!strut=\v!none, % was no, but we get a noindent then (with the danger of a lineskip)
132   \c!align=\v!normal,
133   \c!offset=\v!overlay,
134   \c!width=\v!fit,
135   \c!height=\v!fit,
136   \c!frame=\v!off]
137
138%D \TEX\ pages (for \METAPOST\ pages, see \type {meta-fig}):
139
140%D \starttyping
141%D \startTEXpage[align=normal,width=900pt,autowidth=force]
142%D     \framed[width=800pt,frame=off]{\number\dimexpr800pt}\par
143%D     \input tufte\par
144%D \stopTEXpage
145%D \stoptyping
146%D
147%D Beware: the width is the textwidth!
148
149\definefittingpage
150  [TEXpage]
151  [\c!align=\v!normal] % needed, else problems !
152
153\permanent\protected\def\setupTEXpage
154  {\setupfittingpage[TEXpage]}
155
156%D For Mojca:
157%D
158%D \starttyping
159%D \startTEXstream \chapter{Bla} Hello world!\crlf Hello world! \stopTEXstream
160%D \startTEXpage   \chapter{Bla} Hello world!\crlf Hello world! \stopTEXpage
161%D \stoptyping
162%D
163%D maybe I should support stream=yes in framed.
164
165\permanent\tolerant\protected\def\startTEXstream[#1]% old code, to be redone
166  {\page
167   \enableoutputstream[tex]}
168
169\permanent\protected\def\stopTEXstream
170  {\disableoutputstream
171   \startTEXpage % [\c!align=\v!normal]
172     \outputstreamunvbox[tex]%
173   \stopTEXpage}
174
175%D Application pages, a quick \MKIV\ hack:
176
177\definetypesetting[TEXapplication]
178\definebuffer[TEXapplication]
179
180% we could use a counter and saves runs on numbering them.
181
182\permanent\def\TEXapplicationfilename{\jobname-texapplication.tex}
183
184\permanent\protected\def\stopTEXapplication
185  {\savebuffer[\thedefinedbuffer{TEXapplication}][\TEXapplicationfilename]%
186   \typesetfile[TEXapplication][\TEXapplicationfilename]\relax}
187
188%D \macros
189%D   {startpagefigure}
190%D
191%D \starttyping
192%D \starttext \pagefigure[two.1] \stoptext
193%D \stoptyping
194
195\defineexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay] % we force a parent
196
197\permanent\tolerant\protected\def\startpagefigure[#1]#*[#S#2]%
198  {\bgroup
199   \setupexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay,#2]%
200   \startTEXpage[\c!offset=\namedexternalfigureparameter{\v!page:\v!figure}\c!offset,\c!align=\v!normal]%
201     \externalfigure[#1][\v!page:\v!figure]\ignorespaces} % so we can put some text below the graphic
202
203\permanent\protected\def\stoppagefigure
204  {\stopTEXpage
205   \egroup}
206
207\permanent\tolerant\protected\def\pagefigure[#1]#*[#S#2]%
208  {\startpagefigure[#1][#2]\stoppagefigure}
209
210\protect \endinput
211