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