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\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,
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
54 \autostarttext
55 \bgroup
56 \setupinterlinespace[\v!top=0]
57 \cdef\currentfittingpage{#1}
58 \dontcomplain
59
60 \setupcurrentfittingpage[\c!paper=,#2]
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 \ignorepars}
81
82\protected\def\page_fitting_stop_normal
83 {\removeunwantedspaces
84 \egroup
85 \egroup
86
87 \ifcstok{\fittingpageparameter\c!margin}\v!page
88 \setbox\b_page_fitting\hpack\bgroup
89 \offsetbox
90 [\c!leftoffset=\backspace,
91 \c!rightoffset=\cutspace,
92 \c!topoffset=\topspace,
93 \c!bottomoffset=\bottomspace]
94 {\box\b_page_fitting}
95 \egroup
96 \fi
97 \ifempty{\fittingpageparameter\c!scale}\else
98 \setbox\b_page_fitting\hpack\bgroup
99 \scale[\c!scale=\fittingpageparameter\c!scale]{\box\b_page_fitting}
100 \egroup
101 \fi
102 \ifzeropt\ht\b_page_fitting
103 \ht\b_page_fitting\onepoint
104 \fi
105 \ifzeropt\wd\b_page_fitting
106 \wd\b_page_fitting\onepoint
107 \fi
108 \d_page_fitting_width \wd\b_page_fitting
109
110
111 \d_page_fitting_height\htdp\b_page_fitting
112 \startlocallayout
113 \enforced\let\checkcurrentlayout\relax
114 \processaction
115 [\fittingpageparameter\c!paper]
116 [ \v!auto=>\let\scratchstringone\printpapersize,
117 \s!unknown=>\let\scratchstringone\commalistelement,
118 \s!default=>\def\scratchstringone{fittingpage}]
119 \normalexpanded{\setuppapersize[fittingpage][\scratchstringone]}
120
121 \edef\p_label{\fittingpageparameter\c!label}
122 \ifempty\p_label\else
123 \normalexpanded{\setuppagenumber[\c!label=\p_label]}
124 \fi
125
126 \startmakeup[fittingpage]
127 \box\b_page_fitting
128 \stopmakeup
129 \stoplocallayout
130 \egroup
131 \autostoptext}
132
133\permanent\let\stopfittingpage\page_fitting_stop_normal
134
135\setupfittingpage
136 [
137
138 \c!strut=\v!none,
139 \c!align=\v!normal,
140 \c!offset=\v!overlay,
141 \c!width=\v!fit,
142 \c!height=\v!fit,
143 \c!frame=\v!off]
144
145
146
147
148
149
150
151
152
153
154
155
156\definefittingpage
157 [TEXpage]
158 [\c!align=\v!normal]
159
160\permanent\protected\def\setupTEXpage
161 {\setupfittingpage[TEXpage]}
162
163
164
165
166
167
168
169
170
171
172\permanent\tolerant\protected\def\startTEXstream[#1]
173 {\page
174 \enableoutputstream[tex]}
175
176\permanent\protected\def\stopTEXstream
177 {\disableoutputstream
178 \startTEXpage
179 \outputstreamunvbox[tex]
180 \stopTEXpage}
181
182
183
184\definetypesetting[TEXapplication]
185\definebuffer[TEXapplication]
186
187
188
189\permanent\def\TEXapplicationfilename{\jobnametexapplication.tex}
190
191\permanent\protected\def\stopTEXapplication
192 {\savebuffer[\thedefinedbuffer{TEXapplication}][\TEXapplicationfilename]
193 \typesetfile[TEXapplication][\TEXapplicationfilename]\relax}
194
195
196
197
198
199
200
201
202\defineexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay]
203
204\permanent\tolerant\protected\def\startpagefigure[#1]#*[#S#2]
205 {\bgroup
206 \setupexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay,#2]
207 \startTEXpage[\c!offset=\namedexternalfigureparameter{\v!page:\v!figure}\c!offset,\c!align=\v!normal]
208 \externalfigure[#1][\v!page:\v!figure]\ignorespaces}
209
210\permanent\protected\def\stoppagefigure
211 {\stopTEXpage
212 \egroup}
213
214\permanent\tolerant\protected\def\pagefigure[#1]#*[#S#2]
215 {\startpagefigure[#1][#2]\stoppagefigure}
216
217\protect \endinput
218 |