summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/page-app.mkxl
blob: e8cc12aaaf04222b2d659d7853d6fecb83ebf4b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
%D \module
%D   [       file=page-app, % from meta-fig
%D        version=1998.01.15,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Independent page building,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Page Macros / Applications}

%D This needs an update with a proper define and inheritance.

\unprotect

\installcorenamespace{fittingpage}

\installframedcommandhandler \??fittingpage {fittingpage} \??fittingpage

\newdimen\d_page_fitting_width
\newdimen\d_page_fitting_height
\newbox  \b_page_fitting

\definepapersize
  [fittingpage]
  [\c!width=\d_page_fitting_width,
   \c!height=\d_page_fitting_height]

\definemakeup
  [fittingpage]
  [\c!textstate=\v!empty,
   \c!doublesided=\v!no,
   \c!location=\v!top, % no topskip
   \c!pagestate=\fittingpageparameter\c!pagestate]%

\definelayout
  [fittingpage]
  [\v!page]
  [\c!width=\d_page_fitting_width,
   \c!height=\d_page_fitting_height,
   \c!location=\v!middle]

\appendtoks
    \frozen\instance\protected\edefcsname\e!start\currentfittingpage\endcsname{\startfittingpage[\currentfittingpage]}%
    \frozen\instance\protected\edefcsname\e!stop \currentfittingpage\endcsname{\stopfittingpage}%
\to \everydefinefittingpage

\permanent\tolerant\protected\def\startfittingpage[#1]#*[#2]%
  {\page % this is kind of tricky! there can be preceding page refs
   \autostarttext
   \bgroup % resulting in a zero height page; test fig-make !
   \setupinterlinespace[\v!top=0]% no topskip
   \def\currentfittingpage{#1}%
   \dontcomplain
   % runs under current page regime, i.e. page variables passed to mp
   \setupcurrentfittingpage[\c!paper=,#2]% auto or size or nothing
   \doifelsenothing{\fittingpageparameter\c!command}
     \page_fitting_start_normal
     \page_fitting_start_command}

\def\page_fitting_start_command
  {\grabuntil{\e!stop\currentfittingpage}\page_fitting_stop_command}

\def\page_fitting_stop_command#1%
  {\page_fitting_start_normal
   \fittingpageparameter\c!command{#1}%
   \page_fitting_stop_normal}

\def\page_fitting_start_normal
   {\setbox\b_page_fitting\hbox
      \bgroup
      \inheritedfittingpageframed
      \bgroup
      \pack_framed_initialize
      \gobblespacetokens}

\protected\def\page_fitting_stop_normal % todo: figure out why a small mp image gets shifted
  {\removeunwantedspaces
   \egroup
   \egroup
   % finalize
   \doif{\fittingpageparameter\c!margin}\v!page
     {\setbox\b_page_fitting\hpack\bgroup
        \offsetbox
          [\c!leftoffset=\backspace,
           \c!rightoffset=\cutspace,
           \c!topoffset=\topspace,
           \c!bottomoffset=\bottomspace]
          {\box\b_page_fitting}%
       \egroup}%
   \doifsomething{\fittingpageparameter\c!scale}
     {\setbox\b_page_fitting\hpack\bgroup
        \scale[\c!scale=\fittingpageparameter\c!scale]{\box\b_page_fitting}%
      \egroup}%
   \ifzeropt\ht\b_page_fitting
     \ht\b_page_fitting\onepoint
   \fi
   \ifzeropt\wd\b_page_fitting
     \wd\b_page_fitting\onepoint
   \fi
   \d_page_fitting_width \wd\b_page_fitting
   \d_page_fitting_height\ht\b_page_fitting
   \startlocallayout % hm, we change the papersize so we still need it
   \enforced\let\checkcurrentlayout\relax % else interference with odd/even layout
   \processaction
     [\fittingpageparameter\c!paper]
     [   \v!auto=>\let\scratchstringone\printpapersize,
      \s!unknown=>\let\scratchstringone\commalistelement,
      \s!default=>\def\scratchstringone{fittingpage}]%
   \normalexpanded{\setuppapersize[fittingpage][\scratchstringone]}%
   \startmakeup[fittingpage]%
     \box\b_page_fitting
   \stopmakeup
   \stoplocallayout % we need to get rid of this and use the built-in
   \egroup
   \autostoptext}

\permanent\let\stopfittingpage\page_fitting_stop_normal

\setupfittingpage
  [%\c!scale=1000,
   %\c!pagestate=,
   \c!strut=\v!none, % was no, but we get a noindent then (with the danger of a lineskip)
   \c!align=\v!normal,
   \c!offset=\v!overlay,
   \c!width=\v!fit,
   \c!height=\v!fit,
   \c!frame=\v!off]

%D \TEX\ pages (for \METAPOST\ pages, see \type {meta-fig}):

%D \starttyping
%D \startTEXpage[align=normal,width=900pt,autowidth=force]
%D     \framed[width=800pt,frame=off]{\number\dimexpr800pt}\par
%D     \input tufte\par
%D \stopTEXpage
%D \stoptyping
%D
%D Beware: the width is the textwidth!

\definefittingpage
  [TEXpage]
  [\c!align=\v!normal] % needed, else problems !

\permanent\protected\def\setupTEXpage
  {\setupfittingpage[TEXpage]}

%D For Mojca:
%D
%D \starttyping
%D \startTEXstream \chapter{Bla} Hello world!\crlf Hello world! \stopTEXstream
%D \startTEXpage   \chapter{Bla} Hello world!\crlf Hello world! \stopTEXpage
%D \stoptyping
%D
%D maybe I should support stream=yes in framed.

\permanent\tolerant\protected\def\startTEXstream[#1]% old code, to be redone
  {\page
   \enableoutputstream[tex]}

\permanent\protected\def\stopTEXstream
  {\disableoutputstream
   \startTEXpage % [\c!align=\v!normal]
     \outputstreamunvbox[tex]%
   \stopTEXpage}

%D Application pages, a quick \MKIV\ hack:

\definetypesetting[TEXapplication]
\definebuffer[TEXapplication]

% we could use a counter and saves runs on numbering them.

\permanent\def\TEXapplicationfilename{\jobname-texapplication.tex}

\permanent\protected\def\stopTEXapplication
  {\savebuffer[\thedefinedbuffer{TEXapplication}][\TEXapplicationfilename]%
   \typesetfile[TEXapplication][\TEXapplicationfilename]\relax}

%D \macros
%D   {startpagefigure}
%D
%D \starttyping
%D \starttext \pagefigure[two.1] \stoptext
%D \stoptyping

\defineexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay] % we force a parent

\permanent\tolerant\protected\def\startpagefigure[#1]#*[#2]%
  {\bgroup
   \setupexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay,#2]%
   \startTEXpage[\c!offset=\namedexternalfigureparameter{\v!page:\v!figure}\c!offset,\c!align=\v!normal]%
     \externalfigure[#1][\v!page:\v!figure]\ignorespaces} % so we can put some text below the graphic

\permanent\protected\def\stoppagefigure
  {\stopTEXpage
   \egroup}

\permanent\tolerant\protected\def\pagefigure[#1]#*[#2]%
  {\startpagefigure[#1][#2]\stoppagefigure}

\protect \endinput