summaryrefslogtreecommitdiff
path: root/tex/context/base/page-app.tex
blob: 5b5d49f49aa77c2250b0c4b46c6ea4ca3e52fa84 (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
%D \module
%D   [       file=page-app, % from meta-fig 
%D        version=1998.01.15,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Independent page building, 
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%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 The fitting page code is moved from \type {meta-fig} to 
%D here. 

\unprotect 

\def\dostartfittingpage[#1][#2]%
  {\pagina % this is kind of tricky! there can be preceding page refs 
   \bgroup % resulting in a zero height page; test fig-make ! 
   \dontcomplain
   \setbox\scratchbox\hbox
     \bgroup
     \getparameters[#1][#2]%
     \schaal[\c!schaal=\getvalue{#1\c!schaal}]\bgroup\localframed[#1]\bgroup}

\definepapersize
  [\??fp\s!dummy]
  [\c!breedte=\fittingwd,
   \c!hoogte=\fittinght]

\definelayout
  [\??fp\s!dummy]
  [\c!breedte=\fittingwd,\c!hoogte=\fittinght,\c!plaats=\v!midden,
   \c!kopwit=\!!zeropoint,\c!rugwit=\!!zeropoint,
   \c!snijwit=\!!zeropoint,\c!bodemwit=\!!zeropoint,
   \c!tekstafstand=\!!zeropoint,\c!regels=0,\c!grid=\v!nee,
   \c!hoofd=\!!zeropoint,\c!voet=\!!zeropoint]

\def\dostopfittingpage
  {\egroup\egroup\egroup
   \edef\fittingwd{\the\wd\scratchbox}%
   \edef\fittinght{\the\ht\scratchbox}%
   \startlocallayout
   \ifdim\fittinght<\lineheight 
     % write status : too small 
     \setbox\scratchbox\vbox to \lineheight{\vss\box\scratchbox\vss}%
     \edef\fittinght{\the\lineheight}%
   \fi
   \setuppapersize
     [\??fp\s!dummy][\??fp\s!dummy]%
   \setuplayout
     [\??fp\s!dummy]%
   \startmakeup[\v!standaard][\c!tekststatus=\v!leeg,\c!dubbelzijdig=\v!nee,\c!pagina=]%
     \centerbox{\box\scratchbox}%
   \stopmakeup
   \stoplocallayout
   \egroup}

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

\presetlocalframed[\??tg]

\def\setupTEXpage
  {\dodoubleargument\getparameters[\??tg]}

\def\startTEXpage
  {\dosingleempty\dostartTEXpage}

\def\dostartTEXpage[#1]%
  {\dostartfittingpage[\??tg][#1]\gobblespacetokens}

\def\stopTEXpage
  {\removelastspace
   \dostopfittingpage}

\setupTEXpage
  [\c!schaal=1000,
   \c!strut=\v!nee,
   \c!uitlijnen=\v!normaal, % needed, else problems !
   \c!offset=\v!overlay,
   \c!breedte=\v!passend,
   \c!hoogte=\v!passend,
   \c!kader=\v!uit]

%D Application pages (for an example, see \type {m-pstric}): 

\def\@@texapp{texapp}
\def\@@texdim{texdim}

\def\saveTEXapplication#1#2%
  {\immediate\openout\scratchwrite=\bufferprefix\@@texdim.tmp
   \immediate\write\scratchwrite{\dimen#1=\the\ht\scratchbox}%
   \immediate\write\scratchwrite{\dimen#2=\the\wd\scratchbox}%
   \immediate\closeout\scratchwrite}

\def\restoreTEXapplication
  {\readlocfile{\bufferprefix\@@texdim.tmp}\donothing\donothing}

\def\startTEXapplication
  {\dosingleempty\dostartTEXapplication}

\long\def\dostartTEXapplication[#1]#2#3\stopTEXapplication
  {\bgroup
   \bgroup
   \let\f!temporaryextension\c!tex
   \setbuffer[\@@texapp]%
     \starttext 
     #2% preamble 
     \startTEXpage[#1]%
       \setbox\scratchbox\hbox{#3}%
       \saveTEXapplication02% dimensions 
       \box\scratchbox
     \stopTEXpage
     \stoptext 
   \endbuffer
   \egroup
   \doifelse\jobsuffix{dvi}\donetrue\donefalse
   \executesystemcommand{texexec \bufferprefix\@@texapp.tex --once --batch}%
   \ifdone % eps 
     \executesystemcommand{dvips -E* -o \@@texapp.eps \@@texapp}%
   \else % pdf 
     \executesystemcommand{dvips \bufferprefix\@@texapp}%
     \executesystemcommand{ps2pdf \bufferprefix\@@texapp.ps \bufferprefix\@@texapp.pdf}%
   \fi
   \restoreTEXapplication % dimensions 
   \setbox\scratchbox\hbox
     {\expanded{\externalfigure
        [\bufferprefix\@@texapp.\ifdone eps\else pdf\fi]
        [\c!object=\v!nee]}}%
   \setbox\scratchbox\hbox
     {\lower\ht\scratchbox\hbox{\raise\dimen2\box\scratchbox}}%
   \wd\scratchbox\dimen0
   \ht\scratchbox\dimen2
   \dp\scratchbox\zeropoint
   \box\scratchbox
   \egroup}

\protect \endinput