mp-page.mpxl /size: 11 Kb    last modification: 2021-10-28 13:50
1
%D \module
2
%D [ file=mp-page.mpiv,
3
%D version=1999.03.10,
4
%D title=\CONTEXT\ \METAPOST\ graphics,
5
%D subtitle=page enhancements,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
%D This module is rather preliminary and subjected to changes.In the process of
15
%D moving to \METAFUN2\ this might change.
16 17
if
known
metafun_loaded_page
:
endinput
;
fi
;
18 19
newinternal
boolean
metafun_loaded_page
;
metafun_loaded_page
:
=
true
;
immutable
metafun_loaded_page
;
20 21
def
LoadPageState
=
enddef
;
% just in case some old style uses it
22 23
% Next we implement the the page area model. First some constants. We use a
24
% matrix approach as we do at the TeX end but we could have gone for a period
25
% separated variant. Too late.
26 27
LeftEdge
:
=
-4
;
Top
:
=
-40
;
28
LeftEdgeSeparator
:
=
-3
;
TopSeparator
:
=
-30
;
29
LeftMargin
:
=
-2
;
Header
:
=
-20
;
30
LeftMarginSeparator
:
=
-1
;
HeaderSeparator
:
=
-10
;
31
Text
:
=
0
;
Text
:
=
0
;
32
RightMarginSeparator
:
=
+1
;
FooterSeparator
:
=
+10
;
33
RightMargin
:
=
+2
;
Footer
:
=
+20
;
34
RightEdgeSeparator
:
=
+3
;
BottomSeparator
:
=
+30
;
35
RightEdge
:
=
+4
;
Bottom
:
=
+40
;
36 37
numeric
HorPos
;
HorPos
:
=
0
;
38
numeric
VerPos
;
VerPos
:
=
0
;
39 40
immutable
% permanent
41
Text
,
HorPos
,
VerPos
,
42
LeftEdge
,
LeftEdgeSeparator
,
LeftMargin
,
LeftMarginSeparator
,
43
RightMarginSeparator
,
RightMargin
,
RightEdgeSeparator
,
RightEdge
,
44
Top
,
TopSeparator
,
Header
,
HeaderSeparator
,
45
FooterSeparator
,
Footer
,
BottomSeparator
,
Bottom
;
46 47
% Because metapost > 1.50 has dynamic memory management and is less efficient than
48
% before we now delay calculations ... (on a document with 150 pages the time spent
49
% in mp was close to 5 seconds which was only due to initialising the page related
50
% areas, something that was hardly noticeable before. At least now we're back to
51
% half a second for such a case.
52 53
% We could go for just setting them (:=):
54 55
path
mfun_page_area
[
]
[
]
;
56
pair
mfun_page_location
[
]
[
]
;
57
path
mfun_page_field
[
]
[
]
;
58
numeric
mfun_page_vsize
[
]
;
59
numeric
mfun_page_hsize
[
]
;
60
numeric
mfun_page_vstep
[
]
;
61
numeric
mfun_page_hstep
[
]
;
62 63
newinternal
mfun_page_done
;
mfun_page_done
:
=
0
;
64 65
def
mfun_page_check_vsize
=
66
mfun_page_vsize
[
Top
]
:
=
TopHeight
;
67
mfun_page_vsize
[
TopSeparator
]
:
=
TopDistance
;
68
mfun_page_vsize
[
Header
]
:
=
HeaderHeight
;
69
mfun_page_vsize
[
HeaderSeparator
]
:
=
HeaderDistance
;
70
mfun_page_vsize
[
Text
]
:
=
TextHeight
;
71
mfun_page_vsize
[
FooterSeparator
]
:
=
FooterDistance
;
72
mfun_page_vsize
[
Footer
]
:
=
FooterHeight
;
73
mfun_page_vsize
[
BottomSeparator
]
:
=
BottomDistance
;
74
mfun_page_vsize
[
Bottom
]
:
=
BottomHeight
;
75
enddef
;
76 77
def
mfun_page_check_hsize
=
78
mfun_page_hsize
[
LeftEdge
]
:
=
LeftEdgeWidth
;
79
mfun_page_hsize
[
LeftEdgeSeparator
]
:
=
LeftEdgeDistance
;
80
mfun_page_hsize
[
LeftMargin
]
:
=
LeftMarginWidth
;
81
mfun_page_hsize
[
LeftMarginSeparator
]
:
=
LeftMarginDistance
;
82
mfun_page_hsize
[
Text
]
:
=
MakeupWidth
;
83
mfun_page_hsize
[
RightMarginSeparator
]
:
=
RightMarginDistance
;
84
mfun_page_hsize
[
RightMargin
]
:
=
RightMarginWidth
;
85
mfun_page_hsize
[
RightEdgeSeparator
]
:
=
RightEdgeDistance
;
86
mfun_page_hsize
[
RightEdge
]
:
=
RightEdgeWidth
;
87
enddef
;
88 89
def
mfun_page_check_vstep
=
90
mfun_page_vstep
[
TopSeparator
]
:
=
PaperHeight
-
TopSpace
;
91
mfun_page_vstep
[
Top
]
:
=
mfun_page_vstep
[
TopSeparator
]
+
mfun_page_vsize
[
TopSeparator
]
;
92
mfun_page_vstep
[
Header
]
:
=
mfun_page_vstep
[
TopSeparator
]
-
mfun_page_vsize
[
Header
]
;
93
mfun_page_vstep
[
HeaderSeparator
]
:
=
mfun_page_vstep
[
Header
]
-
mfun_page_vsize
[
HeaderSeparator
]
;
94
mfun_page_vstep
[
Text
]
:
=
mfun_page_vstep
[
HeaderSeparator
]
-
mfun_page_vsize
[
Text
]
;
95
mfun_page_vstep
[
FooterSeparator
]
:
=
mfun_page_vstep
[
Text
]
-
mfun_page_vsize
[
FooterSeparator
]
;
96
mfun_page_vstep
[
Footer
]
:
=
mfun_page_vstep
[
FooterSeparator
]
-
mfun_page_vsize
[
Footer
]
;
97
mfun_page_vstep
[
BottomSeparator
]
:
=
mfun_page_vstep
[
Footer
]
-
mfun_page_vsize
[
BottomSeparator
]
;
98
mfun_page_vstep
[
Bottom
]
:
=
mfun_page_vstep
[
BottomSeparator
]
-
mfun_page_vsize
[
Bottom
]
;
99
enddef
;
100 101
def
mfun_page_check_hstep
=
102
mfun_page_hstep
[
Text
]
:
=
BackSpace
;
103
mfun_page_hstep
[
LeftMarginSeparator
]
:
=
mfun_page_hstep
[
Text
]
-
mfun_page_hsize
[
LeftMarginSeparator
]
;
104
mfun_page_hstep
[
RightMarginSeparator
]
:
=
mfun_page_hstep
[
Text
]
+
mfun_page_hsize
[
Text
]
;
105
mfun_page_hstep
[
LeftMargin
]
:
=
mfun_page_hstep
[
LeftMarginSeparator
]
-
mfun_page_hsize
[
LeftMargin
]
;
106
mfun_page_hstep
[
RightMargin
]
:
=
mfun_page_hstep
[
RightMarginSeparator
]
+
mfun_page_hsize
[
RightMarginSeparator
]
;
107
mfun_page_hstep
[
LeftEdgeSeparator
]
:
=
mfun_page_hstep
[
LeftMargin
]
-
mfun_page_hsize
[
LeftEdgeSeparator
]
;
108
mfun_page_hstep
[
LeftEdge
]
:
=
mfun_page_hstep
[
LeftEdgeSeparator
]
-
mfun_page_hsize
[
LeftEdge
]
;
109
mfun_page_hstep
[
RightEdgeSeparator
]
:
=
mfun_page_hstep
[
RightMargin
]
+
mfun_page_hsize
[
RightMargin
]
;
110
mfun_page_hstep
[
RightEdge
]
:
=
mfun_page_hstep
[
RightEdgeSeparator
]
+
mfun_page_hsize
[
RightEdgeSeparator
]
;
111
enddef
;
112 113
def
mfun_check_page_dimensions
=
114
if
mfun_page_done
<
>
RealPageNumber
:
115
if
LayoutHasChanged
:
116
mfun_page_check_vsize
;
117
mfun_page_check_hsize
;
118
mfun_page_check_vstep
;
119
mfun_page_check_hstep
;
120
fi
;
121
mfun_page_done
:
=
RealPageNumber
;
122
fi
;
123
enddef
;
124 125 126
def
mfun_check_page_area
=
127
mfun_check_page_dimensions
;
128
for
VerPos
=
Top
step
10
until
Bottom
:
129
for
HorPos
=
LeftEdge
step
1
until
RightEdge
:
130
mfun_page_area
[
HorPos
]
[
VerPos
]
:
=
unitsquare
xscaled
mfun_page_hsize
[
HorPos
]
yscaled
mfun_page_vsize
[
VerPos
]
;
131
mfun_page_area
[
VerPos
]
[
HorPos
]
:
=
mfun_page_area
[
HorPos
]
[
VerPos
]
;
132
endfor
;
133
endfor
;
134
enddef
;
135 136
def
mfun_check_page_location
=
137
mfun_check_page_dimensions
;
138
for
VerPos
=
Top
step
10
until
Bottom
:
139
for
HorPos
=
LeftEdge
step
1
until
RightEdge
:
140
mfun_page_location
[
HorPos
]
[
VerPos
]
:
=
(
mfun_page_hstep
[
HorPos
]
,
mfun_page_vstep
[
VerPos
]
)
;
141
mfun_page_location
[
VerPos
]
[
HorPos
]
:
=
mfun_page_location
[
HorPos
]
[
VerPos
]
;
142
endfor
;
143
endfor
;
144
enddef
;
145 146
def
mfun_check_page_field
=
147
mfun_check_page_dimensions
;
148
for
VerPos
=
Top
step
10
until
Bottom
:
149
for
HorPos
=
LeftEdge
step
1
until
RightEdge
:
150
mfun_page_field
[
HorPos
]
[
VerPos
]
:
=
unitsquare
xscaled
mfun_page_hsize
[
HorPos
]
yscaled
mfun_page_vsize
[
VerPos
]
shifted
(
mfun_page_hstep
[
HorPos
]
,
mfun_page_vstep
[
VerPos
]
)
;
151
mfun_page_field
[
VerPos
]
[
HorPos
]
:
=
mfun_page_field
[
HorPos
]
[
VerPos
]
;
152
endfor
;
153
endfor
;
154
enddef
;
155 156
def
Area
=
hide
(
mfun_check_page_area
;
)
mfun_page_area
enddef
;
157
def
Location
=
hide
(
mfun_check_page_location
;
)
mfun_page_location
enddef
;
158
def
Field
=
hide
(
mfun_check_page_field
;
)
mfun_page_field
enddef
;
159
def
Vsize
=
hide
(
mfun_check_page_dimensions
;
)
mfun_page_vsize
enddef
;
160
def
Hsize
=
hide
(
mfun_check_page_dimensions
;
)
mfun_page_hsize
enddef
;
161
def
Vstep
=
hide
(
mfun_check_page_dimensions
;
)
mfun_page_vstep
enddef
;
162
def
Hstep
=
hide
(
mfun_check_page_dimensions
;
)
mfun_page_hstep
enddef
;
163 164
immutable
% permanent
165
Area
,
Location
,
Field
,
Vsize
,
Hsize
,
Vstep
,
Hstep
;
166 167
vardef
FrontPageWidth
=
PaperWidth
enddef
;
168
vardef
BackPageWidth
=
PaperWidth
enddef
;
169
vardef
CoverWidth
=
2
*
PaperWidth
+
SpineWidth
enddef
;
170
vardef
CoverHeight
=
PaperHeight
enddef
;
171 172
vardef
FrontPageHeight
=
PaperHeight
enddef
;
173
vardef
BackPageHeight
=
PaperHeight
enddef
;
174
vardef
SpineHeight
=
PaperHeight
enddef
;
175 176
path
mfun_page_page
,
mfun_page_cover
,
mfun_page_spine
,
mfun_page_back
,
mfun_page_front
;
177 178
def
mfun_check_page
=
mfun_page_page
:
=
unitsquare
xscaled
PaperWidth
yscaled
PaperHeight
;
enddef
;
179
def
mfun_check_cover
=
mfun_page_cover
:
=
unitsquare
xscaled
CoverWidth
yscaled
CoverHeight
;
enddef
;
180
def
mfun_check_spine
=
mfun_page_spine
:
=
unitsquare
xscaled
SpineWidth
yscaled
CoverHeight
shifted
(
BackPageWidth
,
0
)
;
enddef
;
181
def
mfun_check_back
=
mfun_page_back
:
=
unitsquare
xscaled
BackPageWidth
yscaled
CoverHeight
;
enddef
;
182
def
mfun_check_front
=
mfun_page_front
:
=
unitsquare
xscaled
FrontPageWidth
yscaled
CoverHeight
shifted
(
BackPageWidth
+
SpineWidth
,
0
)
;
enddef
;
183 184
def
Page
=
hide
(
mfun_check_page
;
)
mfun_page_page
enddef
;
185
def
CoverPage
=
hide
(
mfun_check_cover
;
)
mfun_page_cover
enddef
;
186
def
Spine
=
hide
(
mfun_check_spine
;
)
mfun_page_spine
enddef
;
187
def
BackPage
=
hide
(
mfun_check_back
;
)
mfun_page_back
enddef
;
188
def
FrontPage
=
hide
(
mfun_check_front
;
)
mfun_page_front
enddef
;
189 190
% pages
191 192
def
StartPage
=
193
begingroup
;
194
setbounds
currentpicture
to
Page
;
195
enddef
;
196 197
def
StopPage
=
198
setbounds
currentpicture
to
Page
;
199
endgroup
;
200
enddef
;
201 202
% cover pages
203 204
def
StartCover
=
205
begingroup
;
206
setbounds
currentpicture
to
CoverPage
enlarged
PaperBleed
;
207
enddef
;
208 209
def
StopCover
=
210
setbounds
currentpicture
to
CoverPage
enlarged
PaperBleed
;
211
endgroup
;
212
enddef
;
213 214
immutable
% permanent
215
FrontPageWidth
,
BackPageWidth
,
CoverWidth
,
FrontPageHeight
,
BackPageHeight
,
CoverHeight
,
216
SpineHeight
,
Page
,
CoverPage
,
Spine
,
BackPage
,
FrontPage
,
217
StartPage
,
StopPage
,
StartCover
,
StopCover
;
218 219
% overlays:
220 221
def
OverlayBox
=
222
(
unitsquare
xyscaled
(
OverlayWidth
,
OverlayHeight
)
)
223
enddef
;
224 225
def
BoundToOverlayBox
=
226
setbounds
currentpicture
to
OverlayBox
;
227
enddef
;
228 229
immutable
% permanent
230
OverlayBox
;
231 232
permanent
233
BoundToOverlayBox
;
234 235
% handy
236 237
def
innerenlarged
=
238
if
OnRightPage
:
leftenlarged
else
:
rightenlarged
fi
239
enddef
;
240 241
def
outerenlarged
=
242
if
OnRightPage
:
rightenlarged
else
:
leftenlarged
fi
243
enddef
;
244 245
permanent
246
innerenlarged
,
outerenlarged
;
247 248
% obsolete
249 250
% def llEnlarged (expr p,d) = (llcorner p shifted (-d,-d)) enddef ;
251
% def lrEnlarged (expr p,d) = (lrcorner p shifted (+d,-d)) enddef ;
252
% def urEnlarged (expr p,d) = (urcorner p shifted (+d,+d)) enddef ;
253
% def ulEnlarged (expr p,d) = (ulcorner p shifted (-d,+d)) enddef ;
254 255
% def Enlarged (expr p, d) =
256
% (
257
% llEnlarged (p,d) --
258
% lrEnlarged (p,d) --
259
% urEnlarged (p,d) --
260
% ulEnlarged (p,d) --
261
% cycle
262
% )
263
% enddef ;
264 265
% for the moment we put these here:
266 267
string
RuleDirection
;
RuleDirection
:
=
"
"
;
268
string
RuleOption
;
RuleOption
:
=
"
"
;
269
numeric
RuleWidth
;
RuleWidth
:
=
0
;
270
numeric
RuleHeight
;
RuleHeight
:
=
0
;
271
numeric
RuleDepth
;
RuleDepth
:
=
0
;
272
numeric
RuleH
;
RuleH
:
=
0
;
273
numeric
RuleV
;
RuleV
:
=
0
;
274
numeric
RuleThickness
;
RuleThickness
:
=
0
;
275
numeric
RuleFactor
;
RuleFactor
:
=
0
;
276
numeric
RuleOffset
;
RuleOffset
:
=
0
;
277
def
RuleColor
=
(
.5
white
)
enddef
;
% yet undecided, might become a string
278 279
def
FakeWord
(
expr
RuleWidth
,
RuleHeight
,
RuleDepth
,
RuleThickness
)
(
text
RuleColor
)
=
280
fill
unitsquare
281
xscaled
RuleWidth
282
yscaled
(
RuleDepth
-
RuleThickness
/
2
)
283
withcolor
RuleColor
;
284
fill
unitsquare
285
xscaled
RuleWidth
286
yscaled
(
RuleHeight
-
RuleDepth
-
RuleThickness
/
2
)
287
shifted
(
0
,
RuleDepth
+
RuleThickness
)
288
withcolor
RuleColor
;
289
enddef
;
290 291
def
FakeRule
(
expr
RuleWidth
,
RuleHeight
,
RuleDepth
,
RuleThickness
)
(
text
RuleColor
)
=
292
fill
unitsquare
293
xscaled
RuleWidth
294
yscaled
RuleHeight
295
withcolor
RuleColor
;
296
enddef
;
297 298
mutable
299
RuleDirection
,
RuleOption
,
RuleWidth
,
RuleHeight
,
RuleDepth
,
RuleH
,
RuleV
,
RuleThickness
,
300
RuleFactor
,
RuleOffset
,
RuleColor
;
301 302
permanent
303
FakeWord
,
FakeRule
;
304