mp-grph.mpiv /size: 6217 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
context_grph
:
endinput
;
fi
;
17 18
boolean
context_grph
;
context_grph
:
=
true
;
19 20
picture
_currentpicture_
;
21 22
numeric
_fig_nesting_
;
_fig_nesting_
:
=
0
;
23 24
def
beginfig
(
expr
c
)
=
25
_fig_nesting_
:
=
_fig_nesting_
+
1
;
26
if
_fig_nesting_
=
1
:
27
begingroup
28
charcode
:
=
c
;
29
resetfig
;
30
scantokens
extra_beginfig
;
31
fi
;
32
enddef
;
33 34
def
endfig
=
35
;
% safeguard
36
if
_fig_nesting_
=
1
:
37
scantokens
extra_endfig
;
38
shipit
;
39
endgroup
;
40
fi
;
41
_fig_nesting_
:
=
_fig_nesting_
-
1
;
42
enddef
;
43 44
def
resetfig
=
45
clearxy
;
46
clearit
;
47
clearpen
;
48
pickup
defaultpen
;
49
interim
linecap
:
=
linecap
;
50
interim
linejoin
:
=
linejoin
;
51
interim
miterlimit
:
=
miterlimit
;
52
save
stacking
;
numeric
stacking
;
stacking
:
=
0
;
53
save
makingfigure
;
boolean
makingfigure
;
makingfigure
:
=
true
;
54
save
_background_
;
color
_background_
;
_background_
:
=
background
;
55
save
background
;
color
background
;
background
:
=
_background_
;
56
drawoptions
(
)
;
57
enddef
;
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
interim
prologues
:
=
prologues
;
65
resetfig
;
% resets currentpicture
66
enddef
;
67 68
numeric
currentgraphictext
;
currentgraphictext
:
=
0
;
69 70
def
begingraphictextfig
(
expr
n
)
=
71
foundpicture
:
=
n
;
72
scratchpicture
:
=
nullpicture
;
73
enddef
;
74 75
def
endgraphictextfig
=
76
if
foundpicture
=
currentgraphictext
:
77
expandafter
endinput
78
else
:
79
scratchpicture
:
=
nullpicture
;
80
fi
;
81
enddef
;
82 83
def
loadfigure
primary
filename
=
84
mfun_load_figure
(
filename
)
85
enddef
;
86 87
def
mfun_load_figure
(
expr
filename
)
text
figureattributes
=
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
enddef
;
119 120
% We only use the new method now.
121 122
boolean
mfun_gt_color_fill
;
123
boolean
mfun_gt_color_draw
;
124
boolean
mfun_gt_shade_fill
;
125
boolean
mfun_gt_reverse_fill
;
126
boolean
mfun_gt_outline_fill
;
127
picture
mfun_gt_picture
;
128 129
def
mfun_gt_default
=
% somewhat compatible
130
scaled
11.5
131
withpen
pencircle
scaled
.1
132
enddef
;
133 134
def
graphictext
primary
t
=
% use outlinetext instead
135
begingroup
;
136
mfun_graphic_text_indeed
(
t
)
137
enddef
;
138 139
def
mfun_graphic_text_indeed
(
expr
t
)
text
rest
=
140
interim
linecap
:
=
butt
;
% normally rounded
141
interim
linejoin
:
=
mitered
;
% normally rounded
142
% interim miterlimit := 10 ; % todo
143
%
144
let
normalwithshade
=
withshade
;
145
%
146
save
reversefill
,
outlinefill
,
withshade
,
withfillcolor
,
withdrawcolor
;
147
%
148
def
mfun_gt_fill
=
enddef
;
149
def
mfun_gt_draw
=
enddef
;
150
def
mfun_gt_shade
=
enddef
;
151
%
152
mfun_gt_color_fill
:
=
false
;
153
mfun_gt_color_draw
:
=
false
;
154
mfun_gt_shade_fill
:
=
false
;
155
mfun_gt_reverse_fill
:
=
false
;
156
%
157
def
reversefill
=
hide
(
mfun_gt_reverse_fill
:
=
true
)
enddef
;
158
def
outlinefill
=
enddef
;
159
def
withshade
primary
c
=
hide
(
mfun_gt_shade_fill
:
=
true
;
def
mfun_gt_shade
=
normalwithshade
c
enddef
;
)
enddef
;
160
def
withfillcolor
primary
c
=
hide
(
mfun_gt_color_fill
:
=
true
;
def
mfun_gt_fill
=
withcolor
c
enddef
;
)
enddef
;
161
def
withdrawcolor
primary
c
=
hide
(
mfun_gt_color_draw
:
=
true
;
def
mfun_gt_draw
=
withcolor
c
enddef
;
)
enddef
;
162
%
163
mfun_gt_picture
:
=
nullpicture
;
164
addto
mfun_gt_picture
doublepath
origin
rest
;
% preroll
165
mfun_gt_picture
:
=
nullpicture
;
166
%
167
def
reversefill
=
enddef
;
168
def
outlinefill
=
enddef
;
169
def
withshade
primary
c
=
enddef
;
170
def
withfillcolor
primary
c
=
enddef
;
171
def
withdrawcolor
primary
c
=
enddef
;
172
%
173
if
mfun_gt_shade_fill
:
174
draw
outlinetext
.
f
(
t
)
(
mfun_gt_shade
)
rest
;
175
elseif
mfun_gt_color_fill
and
mfun_gt_color_draw
:
176
if
mfun_gt_reverse_fill
:
177
draw
outlinetext
.
r
(
t
)
(
mfun_gt_default
mfun_gt_fill
)
(
mfun_gt_default
mfun_gt_draw
)
rest
;
178
else
:
179
draw
outlinetext
.
b
(
t
)
(
mfun_gt_default
mfun_gt_draw
)
(
mfun_gt_default
mfun_gt_fill
)
rest
;
180
fi
;
181
elseif
mfun_gt_color_fill
:
182
draw
outlinetext
.
f
(
t
)
(
mfun_gt_default
mfun_gt_fill
)
rest
;
183
elseif
mfun_gt_color_draw
:
184
draw
outlinetext
.
d
(
t
)
(
mfun_gt_default
mfun_gt_draw
)
rest
;
185
else
:
186
draw
outlinetext
.
d
(
t
)
(
mfun_gt_default
)
rest
;
187
fi
;
188
%
189
endgroup
;
190
enddef
;
191 192
% example
193
%
194
% beginfig (1) ;
195
% graphictext
196
% "\vbox{\hsize10cm \input tufte }"
197
% scaled 8
198
% withdrawcolor blue
199
% withfillcolor red
200
% withpen pencircle scaled 2pt ;
201
% endfig ;
202
%
203
% beginfig(1) ;
204
% loadfigure "gracht.mp" rotated 20 ;
205
% loadfigure "koe.mp" number 1 scaled 2 ;
206
% endfig ;
207
%
208
% end
209