1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Page Macros Applications}
15
16
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,
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
57 \autostarttext
58 \bgroup
59 \setupinterlinespace[\v!top=0]
60 \def\currentfittingpage{#1}
61 \dontcomplain
62
63 \setupcurrentfittingpage[\c!paper=,#2]
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
84 {\removeunwantedspaces
85 \egroup
86 \egroup
87
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
110 \let\checkcurrentlayout\relax
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
121 \egroup
122 \autostoptext}
123
124\let\stopfittingpage\page_fitting_stop_normal
125
126\setupfittingpage
127 [
128
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
137
138\definefittingpage
139 [TEXpage]
140 [\c!align=\v!normal]
141
142\unexpanded\def\setupTEXpage
143 {\setupfittingpage[TEXpage]}
144
145
146
147
148
149
150
151
152
153
154\unexpanded\def\startTEXstream
155 {\dosingleempty\page_streams_TEX_start}
156
157\def\page_streams_TEX_start[#1]
158 {\page
159 \enableoutputstream[tex]}
160
161\unexpanded\def\stopTEXstream
162 {\disableoutputstream
163 \startTEXpage
164 \outputstreamunvbox[tex]
165 \stopTEXpage}
166
167
168
169\definetypesetting[TEXapplication]
170\definebuffer[TEXapplication]
171
172
173
174\def\TEXapplicationfilename{\jobnametexapplication.tex}
175
176\unexpanded\def\stopTEXapplication
177 {\savebuffer[\thedefinedbuffer{TEXapplication}][\TEXapplicationfilename]
178 \typesetfile[TEXapplication][\TEXapplicationfilename]\relax}
179
180
181
182
183
184
185
186
187\defineexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay]
188
189\unexpanded\def\startpagefigure
190 {\dodoubleempty\page_figures_start}
191
192
193
194
195
196
197
198
199
200
201
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][\v!page:\v!figure]\ignorespaces}
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 |