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 \pack_framed_initialize
81 \gobblespacetokens}
82
83\protected\def\page_fitting_stop_normal
84 {\removeunwantedspaces
85 \egroup
86 \egroup
87
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
112 \enforced\let\checkcurrentlayout\relax
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
123 \egroup
124 \autostoptext}
125
126\permanent\let\stopfittingpage\page_fitting_stop_normal
127
128\setupfittingpage
129 [
130
131 \c!strut=\v!none,
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
139
140
141
142
143
144
145
146
147
148
149\definefittingpage
150 [TEXpage]
151 [\c!align=\v!normal]
152
153\permanent\protected\def\setupTEXpage
154 {\setupfittingpage[TEXpage]}
155
156
157
158
159
160
161
162
163
164
165\permanent\tolerant\protected\def\startTEXstream[#1]
166 {\page
167 \enableoutputstream[tex]}
168
169\permanent\protected\def\stopTEXstream
170 {\disableoutputstream
171 \startTEXpage
172 \outputstreamunvbox[tex]
173 \stopTEXpage}
174
175
176
177\definetypesetting[TEXapplication]
178\definebuffer[TEXapplication]
179
180
181
182\permanent\def\TEXapplicationfilename{\jobnametexapplication.tex}
183
184\permanent\protected\def\stopTEXapplication
185 {\savebuffer[\thedefinedbuffer{TEXapplication}][\TEXapplicationfilename]
186 \typesetfile[TEXapplication][\TEXapplicationfilename]\relax}
187
188
189
190
191
192
193
194
195\defineexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay]
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}
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 |