mp-grph.mpxl /size: 6255 b    last modification: 2021-10-28 13:50
1
%D \module
2
%D [ file=mp-grph.mpiv,
3
%D version=2000.12.14,
4
%D title=\CONTEXT\ \METAPOST\ graphics,
5
%D subtitle=graphic text support,
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 licen-en.pdf for
12
%C details.
13 14
%D Under construction.
15 16
if
known
metafun_loaded_grph
:
endinput
;
fi
;
17 18
newinternal
boolean
metafun_loaded_grph
;
metafun_loaded_grph
:
=
true
;
immutable
metafun_loaded_grph
;
19 20
numeric
mfun_fig_nesting
;
mfun_fig_nesting
:
=
0
;
21 22
def
beginfig
(
expr
c
)
=
23
mfun_fig_nesting
:
=
mfun_fig_nesting
+
1
;
24
if
mfun_fig_nesting
=
1
:
25
begingroup
26
charcode
:
=
c
;
27
resetfig
;
28
scantokens
extra_beginfig
;
29
fi
;
30
enddef
;
31 32
def
endfig
=
33
;
% safeguard
34
if
mfun_fig_nesting
=
1
:
35
scantokens
extra_endfig
;
36
shipit
;
37
endgroup
;
38
fi
;
39
mfun_fig_nesting
:
=
mfun_fig_nesting
-
1
;
40
enddef
;
41 42
def
resetfig
=
43
clearxy
;
44
clearit
;
45
clearpen
;
46
pickup
defaultpen
;
47
interim
linecap
:
=
linecap
;
48
interim
linejoin
:
=
linejoin
;
49
interim
miterlimit
:
=
miterlimit
;
50
interim
stacking
:
=
0
;
51
interim
makingfigure
:
=
true
;
52
save
temp_b
;
color
temp_b
;
temp_b
:
=
background
;
53
save
background
;
color
background
;
background
:
=
temp_b
;
54
drawoptions
(
)
;
55
enddef
;
56 57
permanent
beginfig
,
endfig
,
resetfig
;
58 59
def
protectgraphicmacros
=
60
save
showtext
;
61
save
beginfig
;
let
beginfig
=
begingraphictextfig
;
62
save
endfig
;
let
endfig
=
endgraphictextfig
;
63
save
end
;
let
end
=
relax
;
64
resetfig
;
% resets currentpicture
65
enddef
;
66 67
numeric
currentgraphictext
;
currentgraphictext
:
=
0
;
68 69
def
begingraphictextfig
(
expr
n
)
=
70
foundpicture
:
=
n
;
71
scratchpicture
:
=
nullpicture
;
72
enddef
;
73 74
def
endgraphictextfig
=
75
if
foundpicture
=
currentgraphictext
:
76
expandafter
endinput
77
else
:
78
scratchpicture
:
=
nullpicture
;
79
fi
;
80
enddef
;
81 82
def
loadfigure
primary
filename
=
83
mfun_load_figure
(
filename
)
84
enddef
;
85 86
def
mfun_load_figure
(
expr
filename
)
text
figureattributes
=
87
mutable
beginfig
,
endfig
;
88
begingroup
;
89
save
figurenumber
,
figurepicture
,
number
,
fixedplace
;
90
numeric
figurenumber
;
figurenumber
:
=
0
;
91
boolean
figureshift
;
figureshift
:
=
true
;
92
picture
figurepicture
;
figurepicture
:
=
currentpicture
;
93
def
number
primary
n
=
hide
(
figurenumber
:
=
n
)
enddef
;
94
def
fixedplace
=
hide
(
figureshift
:
=
false
)
enddef
;
95
protectgraphicmacros
;
96
% defaults
97
interim
linecap
:
=
rounded
;
98
interim
linejoin
:
=
rounded
;
99
interim
miterlimit
:
=
10
;
100
%
101
currentpicture
:
=
nullpicture
;
102
draw
fullcircle
figureattributes
;
% expand number
103
currentpicture
:
=
nullpicture
;
104
def
beginfig
(
expr
n
)
=
105
currentpicture
:
=
nullpicture
;
106
if
(
figurenumber
=
n
)
or
(
figurenumber
=
0
)
:
107
let
endfig
=
endinput
;
108
fi
;
109
enddef
;
110
let
endfig
=
relax
;
111
readfile
(
filename
)
;
112
if
figureshift
:
113
currentpicture
:
=
currentpicture
shifted
-
llcorner
currentpicture
;
114
fi
;
115
addto
figurepicture
also
currentpicture
figureattributes
;
116
currentpicture
:
=
figurepicture
;
117
endgroup
;
118
permanent
beginfig
,
endfig
;
119
enddef
;
120 121
% We only use the new method now.
122 123
boolean
mfun_gt_color_fill
;
124
boolean
mfun_gt_color_draw
;
125
boolean
mfun_gt_shade_fill
;
126
boolean
mfun_gt_reverse_fill
;
127
boolean
mfun_gt_outline_fill
;
128
picture
mfun_gt_picture
;
129 130
def
mfun_gt_default
=
% somewhat compatible
131
scaled
11.5
132
withpen
pencircle
scaled
.1
133
enddef
;
134 135
def
graphictext
primary
t
=
% use outlinetext instead
136
begingroup
;
137
mfun_graphic_text_indeed
(
t
)
138
enddef
;
139 140
def
mfun_graphic_text_indeed
(
expr
t
)
text
rest
=
141
interim
linecap
:
=
butt
;
% normally rounded
142
interim
linejoin
:
=
mitered
;
% normally rounded
143
% interim miterlimit := 10 ; % todo
144
%
145
let
normalwithshade
=
withshade
;
146
%
147
save
reversefill
,
outlinefill
,
withshade
,
withfillcolor
,
withdrawcolor
;
148
%
149
def
mfun_gt_fill
=
enddef
;
150
def
mfun_gt_draw
=
enddef
;
151
def
mfun_gt_shade
=
enddef
;
152
%
153
mfun_gt_color_fill
:
=
false
;
154
mfun_gt_color_draw
:
=
false
;
155
mfun_gt_shade_fill
:
=
false
;
156
mfun_gt_reverse_fill
:
=
false
;
157
%
158
def
reversefill
=
hide
(
mfun_gt_reverse_fill
:
=
true
)
enddef
;
159
def
outlinefill
=
enddef
;
160
def
withshade
primary
c
=
hide
(
mfun_gt_shade_fill
:
=
true
;
def
mfun_gt_shade
=
normalwithshade
c
enddef
;
)
enddef
;
161
def
withfillcolor
primary
c
=
hide
(
mfun_gt_color_fill
:
=
true
;
def
mfun_gt_fill
=
withcolor
c
enddef
;
)
enddef
;
162
def
withdrawcolor
primary
c
=
hide
(
mfun_gt_color_draw
:
=
true
;
def
mfun_gt_draw
=
withcolor
c
enddef
;
)
enddef
;
163
%
164
mfun_gt_picture
:
=
nullpicture
;
165
addto
mfun_gt_picture
doublepath
origin
rest
;
% preroll
166
mfun_gt_picture
:
=
nullpicture
;
167
%
168
def
reversefill
=
enddef
;
169
def
outlinefill
=
enddef
;
170
def
withshade
primary
c
=
enddef
;
171
def
withfillcolor
primary
c
=
enddef
;
172
def
withdrawcolor
primary
c
=
enddef
;
173
%
174
if
mfun_gt_shade_fill
:
175
draw
outlinetext
.
f
(
t
)
(
mfun_gt_shade
)
rest
;
176
elseif
mfun_gt_color_fill
and
mfun_gt_color_draw
:
177
if
mfun_gt_reverse_fill
:
178
draw
outlinetext
.
r
(
t
)
(
mfun_gt_default
mfun_gt_fill
)
(
mfun_gt_default
mfun_gt_draw
)
rest
;
179
else
:
180
draw
outlinetext
.
b
(
t
)
(
mfun_gt_default
mfun_gt_draw
)
(
mfun_gt_default
mfun_gt_fill
)
rest
;
181
fi
;
182
elseif
mfun_gt_color_fill
:
183
draw
outlinetext
.
f
(
t
)
(
mfun_gt_default
mfun_gt_fill
)
rest
;
184
elseif
mfun_gt_color_draw
:
185
draw
outlinetext
.
d
(
t
)
(
mfun_gt_default
mfun_gt_draw
)
rest
;
186
else
:
187
draw
outlinetext
.
d
(
t
)
(
mfun_gt_default
)
rest
;
188
fi
;
189
%
190
endgroup
;
191
enddef
;
192 193
% example
194
%
195
% beginfig (1) ;
196
% graphictext
197
% "\vbox{\hsize10cm \input tufte }"
198
% scaled 8
199
% withdrawcolor blue
200
% withfillcolor red
201
% withpen pencircle scaled 2pt ;
202
% endfig ;
203
%
204
% beginfig(1) ;
205
% loadfigure "gracht.mp" rotated 20 ;
206
% loadfigure "koe.mp" number 1 scaled 2 ;
207
% endfig ;
208
%
209
% end
210