page-app.mkiv /size: 6353 b    last modification: 2020-07-01 14:35
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
\newdimen
\d_page_fitting_width
25
\newdimen
\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
\setuevalue
{
\e!start
\currentfittingpage
}{
\startfittingpage
[
\currentfittingpage
]
}
%
49
\setuevalue
{
\e!stop
\currentfittingpage
}{
\stopfittingpage
}
%
50
\to
\everydefinefittingpage
51 52
\unexpanded
\def
\startfittingpage
53
{
\dodoubleempty
\page_fitting_start
}
54 55
\def
\page_fitting_start
[#
1
][#
2
]
%
56
{
\page
% this is kind of tricky! there can be preceding page refs
57
\autostarttext
58
\bgroup
% resulting in a zero height page; test fig-make !
59
\setupinterlinespace
[
\v!top
=
0
]
% no topskip
60
\def
\currentfittingpage
{
#
1
}
%
61
\dontcomplain
62
% runs under current page regime, i.e. page variables passed to mp
63
\setupcurrentfittingpage
[
\c!paper
=
,
#
2
]
% auto or size or nothing
64
\doifelsenothing
{
\fittingpageparameter
\c!command
}
65
\page_fitting_start_normal
66
\page_fitting_start_command
}
67 68
\def
\page_fitting_start_command
69
{
\grabuntil
{
\e!stop
\currentfittingpage
}
\page_fitting_stop_command
}
70 71
\def
\page_fitting_stop_command
#
1
%
72
{
\page_fitting_start_normal
73
\fittingpageparameter
\c!command
{
#
1
}
%
74
\page_fitting_stop_normal
}
75 76
\def
\page_fitting_start_normal
77
{
\setbox
\b_page_fitting
\hbox
78
\bgroup
79
\inheritedfittingpageframed
80
\bgroup
81
\gobblespacetokens
}
82 83
\unexpanded
\def
\page_fitting_stop_normal
% todo: figure out why a small mp image gets shifted
84
{
\removeunwantedspaces
85
\egroup
86
\egroup
87
% finalize
88
\doif
{
\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
\doifsomething
{
\fittingpageparameter
\c!scale
}
98
{
\setbox
\b_page_fitting
\hpack
\bgroup
99
\scale
[
\c!scale
=
\fittingpageparameter
\c!scale
]
{
\box
\b_page_fitting
}
%
100
\egroup
}
%
101
\ifdim
\ht
\b_page_fitting
=
\zeropoint
102
\ht
\b_page_fitting
\onepoint
103
\fi
104
\ifdim
\wd
\b_page_fitting
=
\zeropoint
105
\wd
\b_page_fitting
\onepoint
106
\fi
107
\d_page_fitting_width
\wd
\b_page_fitting
108
\d_page_fitting_height
\ht
\b_page_fitting
109
\startlocallayout
% hm, we change the papersize so we still need it
110
\let
\checkcurrentlayout
\relax
% else interference with odd/even layout
111
\processaction
112
[
\fittingpageparameter
\c!paper
]
113
[
\v!auto
=>
\def
\fittingpapersize
{
\printpapersize
}
,
114
\s!unknown
=>
\let
\fittingpapersize
\commalistelement
,
115
\s!default
=>
\def
\fittingpapersize
{
fittingpage
}
]
%
116
\expanded
{
\setuppapersize
[
fittingpage
][
\fittingpapersize
]
}
%
117
\startmakeup
[
fittingpage
]
%
118
\box
\b_page_fitting
119
\stopmakeup
120
\stoplocallayout
% we need to get rid of this and use the built-in
121
\egroup
122
\autostoptext
}
123 124
\let
\stopfittingpage
\page_fitting_stop_normal
125 126
\setupfittingpage
127
[
%\c!scale=1000,
128
%\c!pagestate=,
129
\c!strut
=
\v!no
,
130
\c!align
=
\v!normal
,
131
\c!offset
=
\v!overlay
,
132
\c!width
=
\v!fit
,
133
\c!height
=
\v!fit
,
134
\c!frame
=
\v!off
]
135 136
%D \TEX\ pages (for \METAPOST\ pages, see \type {meta-fig}):
137 138
\definefittingpage
139
[
TEXpage
]
140
[
\c!align
=
\v!normal
]
% needed, else problems !
141 142
\unexpanded
\def
\setupTEXpage
143
{
\setupfittingpage
[
TEXpage
]
}
144 145
%D For Mojca:
146
%D
147
%D \starttyping
148
%D \startTEXstream \chapter{Bla} Hello world!\crlf Hello world! \stopTEXstream
149
%D \startTEXpage \chapter{Bla} Hello world!\crlf Hello world! \stopTEXpage
150
%D \stoptyping
151
%D
152
%D maybe I should support stream=yes in framed.
153 154
\unexpanded
\def
\startTEXstream
155
{
\dosingleempty
\page_streams_TEX_start
}
156 157
\def
\page_streams_TEX_start
[#
1
]
% old code, to be redone
158
{
\page
159
\enableoutputstream
[
tex
]
}
160 161
\unexpanded
\def
\stopTEXstream
162
{
\disableoutputstream
163
\startTEXpage
164
\outputstreamunvbox
[
tex
]
%
165
\stopTEXpage
}
166 167
%D Application pages, a quick \MKIV\ hack:
168 169
\definetypesetting
[
TEXapplication
]
170
\definebuffer
[
TEXapplication
]
171 172
% we could use a counter and saves runs on numbering them.
173 174
\def
\TEXapplicationfilename
{
\jobname
-
texapplication
.
tex
}
175 176
\unexpanded
\def
\stopTEXapplication
177
{
\savebuffer
[
\thedefinedbuffer
{
TEXapplication
}
][
\TEXapplicationfilename
]
%
178
\typesetfile
[
TEXapplication
][
\TEXapplicationfilename
]
\relax
}
179 180
%D \macros
181
%D {startpagefigure}
182
%D
183
%D \starttyping
184
%D \starttext \pagefigure[two.1] \stoptext
185
%D \stoptyping
186 187
\defineexternalfigure
[
\v!page
:
\v!figure
][
\c!offset
=
\v!overlay
]
% we force a parent
188 189
\unexpanded
\def
\startpagefigure
190
{
\dodoubleempty
\page_figures_start
}
191 192
% this one:
193
%
194
% \def\page_figures_start[#1][#2]%
195
% {\bgroup
196
% \def\currentexternalfigure{\v!page:\v!figure}%
197
% \setupcurrentexternalfigure[\c!offset=\v!overlay,#2]%
198
% \startTEXpage[\c!offset=\externalfigureparameter\c!offset]%
199
% \externalfigure[#1]\ignorespaces} % so we can put some text below the graphic
200
%
201
% or this one:
202 203
\def
\page_figures_start
[#
1
][#
2
]
%
204
{
\bgroup
205
\setupexternalfigure
[
\v!page
:
\v!figure
][
\c!offset
=
\v!overlay
,
#
2
]
%
206
\startTEXpage
[
\c!offset
=
\namedexternalfigureparameter
{
\v!page
:
\v!figure
}
\c!offset
]
%
207
\externalfigure
[#
1
]
\ignorespaces
}
% so we can put some text below the graphic
208 209
\unexpanded
\def
\stoppagefigure
210
{
\stopTEXpage
211
\egroup
}
212 213
\unexpanded
\def
\pagefigure
214
{
\dodoubleempty
\page_figure
}
215 216
\def
\page_figure
[#
1
][#
2
]
%
217
{
\page_figures_start
[#
1
][#
2
]
\stoppagefigure
}
218 219
\protect
\endinput
220