meta-ini.mkxl /size: 44 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=meta-ini,
3
%D version=2008.03.25,
4
%D title=\METAPOST\ Graphics,
5
%D subtitle=Initialization,
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
% initializations:
15
%
16
% - pass settings from tex to mp (delayed expansion)
17
% - used by context core (and modules)
18
% - cummulative definitions
19
% - flushed each graphic
20
% - can be disabled per instance
21
% - managed at the tex end
22
%
23
% extensions:
24
%
25
% - add mp functionality (immediate expansion)
26
% - cummulative
27
% - all instances or subset of instances
28
% - can be disabled per instance
29
% - managed at the lua/mp end
30
% - could be managed at the tex end but no real reason and also messy
31
%
32
% definitions:
33
%
34
% - add mp functionality (delayed expansion)
35
% - cummulative
36
% - per instance
37
% - managed at the tex end
38
%
39
% inclusions:
40
%
41
% - add mp functionality (delayed expansion)
42
% - cummulative only when [+]
43
% - per instance
44
% - managed at the tex end
45
%
46
% order of execution:
47
%
48
% definitions
49
% extensions
50
% inclusions
51
% beginfig
52
% initializations
53
% graphic
54
% endfig
55 56
% The instance will be implemented stepwise ... I should redo some code in order to
57
% make the macros look better than they do now.
58 59
\writestatus
{
loading
}{
MetaPost
Graphics
/
Initializations
}
60 61
\registerctxluafile
{
meta
-
ini
}{}
62 63
\unprotect
64 65
\newtoks
\everyMPgraphic
% mp % public or not ?
66 67
\appendtoks
68
\restoreendofline
% see interferences-001.tex
69
\to
\everyMPgraphic
70 71
\def
\MPruntimefile
{
mprun
}
72
\def
\currentMPformat
{
metafun
}
73
\def
\defaultMPinstance
{
metafun
}
74 75
\installcorenamespace
{
mpinstance
}
76
\installcorenamespace
{
mpinclusions
}
77
\installcorenamespace
{
mpdefinitions
}
78
\installcorenamespace
{
mpgraphic
}
79
\installcorenamespace
{
mpstaticgraphic
}
80
\installcorenamespace
{
mpclip
}
81 82
\newtoks
\t_meta_initializations
% tex, each
83
\def
\t_meta_inclusions
{
\csname
\??mpinclusions
\currentMPinstance
\endcsname
}
% token register
84
\def
\t_meta_definitions
{
\csname
\??mpdefinitions
\currentMPinstance
\endcsname
}
% token register
85 86
%D The next command is, of course, dedicated to Mojca, who needs it for gnuplot.
87
%D Anyway, the whole multiple engine mechanism is to keep her gnuplot from
88
%D interfering.
89 90
\unexpanded
\def
\startMPdefinitions
91
{
\dosinglegroupempty\meta_start_definitions
}
92 93
\def
\meta_start_definitions
#
1
#
2
\stopMPdefinitions
94
{
\let
\m_meta_saved_instance
\currentMPinstance
95
\edef
\currentMPinstance
{
#
1
}
%
96
\ifempty
\currentMPinstance
97
\let
\currentMPinstance
\defaultMPinstance
98
\fi
99
\gtoksapp
\t_meta_definitions
{
#
2
}
%
100
\let
\currentMPinstance
\m_meta_saved_instance
}
101 102
\let
\stopMPdefinitions
\relax
103 104
\unexpanded
\def
\startMPextensions
105
{
\dosinglegroupempty\meta_start_extensions
}
106 107
\def
\meta_start_extensions
#
1
#
2
\stopMPextensions
% we could use buffers instead
108
{
\clf_setmpextensions
{
#
1
}{
#
2
}}
109 110
\let
\stopMPextensions
\relax
111 112
\unexpanded
\def
\startMPinitializations
#
1
\stopMPinitializations
% for all instances, when enabled
113
{
\gtoksapp
\t_meta_initializations
{
#
1
}}
114 115
\let
\stopMPinitializations
\relax
116 117
\unexpanded
\def
\startMPinclusions
118
{
\dosingleempty\meta_start_inclusions
}
119 120
\unexpanded
\def
\meta_start_inclusions
[
#
1
]
%
121
{
\edef
\m_meta_option
{
#
1
}
%
122
\dosinglegroupempty
\meta_start_inclusions_indeed
}
123 124
\def
\meta_start_inclusions_indeed
#
1
#
2
\stopMPinclusions
125
{
\let
\m_meta_saved_instance
\currentMPinstance
126
\edef
\currentMPinstance
{
#
1
}
%
127
\ifempty
\currentMPinstance
128
\let
\currentMPinstance
\defaultMPinstance
129
\fi
130
\ifx
\m_meta_option
\!!plustoken
\else
131
\global
\t_meta_inclusions
\emptytoks
132
\fi
133
\gtoksapp
\t_meta_inclusions
{
#
2
}
%
134
\let
\currentMPinstance
\m_meta_saved_instance
}
135 136
\let
\stopMPinclusions
\relax
137 138
% The next was broken since we added instances so it will go away!
139 140
\unexpanded
\def
\MPinclusions
141
{
\dosingleempty
\meta_inclusions
}
142 143
\def
\meta_inclusions
[#
1
]
%
144
{
\edef
\m_meta_option
{
#
1
}
%
145
\dodoublegroupempty
\meta_inclusions_indeed
}
146 147
\def
\meta_inclusions_indeed
#
1
#
2
%
148
{
\let
\m_meta_saved_instance
\currentMPinstance
149
\ifx
\m_meta_option
\!!plustoken
\else
150
\global
\t_meta_inclusions
\emptytoks
151
\fi
152
\ifsecondargument
153
\edef
\currentMPinstance
{
#
1
}
%
154
\ifx
\currentMPinstance
\empty
155
\let
\currentMPinstance
\defaultMPinstance
156
\fi
157
\gtoksapp
\t_meta_inclusions
{
#
2
}
%
158
\else
159
\let
\currentMPinstance
\defaultMPinstance
160
\gtoksapp
\t_meta_inclusions
{
#
1
}
%
161
\fi
162
\let
\currentMPinstance
\m_meta_saved_instance
}
163 164
% so far
165 166
\installcommandhandler
\??mpinstance
{
MPinstance
}
\??mpinstance
167 168
\setupMPinstance
169
[
\s!format
=
metafun
,
170
\s!extensions
=
\v!no
,
171
\s!initializations
=
\v!no
,
172
\c!method
=
\s!default
,
173
\c!textstyle
=
,
174
\c!textcolor
=]
175 176
\appendtoks
177
\ifcsname
\??mpdefinitions
\currentMPinstance
\endcsname
\else
178
\expandafter
\newtoks
\csname
\??mpdefinitions
\currentMPinstance
\endcsname
179
\fi
180
\ifcsname
\??mpinclusions
\currentMPinstance
\endcsname
\else
181
\expandafter
\newtoks
\csname
\??mpinclusions
\currentMPinstance
\endcsname
182
\fi
183
\t_meta_definitions
\emptytoks
% in case we redefine
184
\t_meta_inclusions
\emptytoks
% in case we redefine
185
\to
\everydefineMPinstance
186 187
\unexpanded
\def
\resetMPinstance
[#
1
]
%
188
{
\writestatus
\m!metapost
{
reset
will
be
implemented
when
needed
}}
189 190
\def
\meta_analyze_graphicname
[#
1
]
%
191
%{\normalexpanded{\meta_analyze_graphicname_indeed[#1::::]}}
192
{
\normalexpanded
{
\meta_analyze_graphicname_indeed
[#
1
}
:
:
:
:
]
}
193 194
\def
\meta_show_properties_indeed
195
{
\writestatus
{
metapost
}{
name
:
\currentMPgraphicname
,
instance
:
\currentMPinstance
,
format
:
\currentMPformat
}}
196 197
\let
\meta_show_properties
\donothing
198 199
\installtextracker
200
{
metapost
.
properties
}
201
{
\let
\meta_show_properties
\meta_show_properties_indeed
}
202
{
\let
\meta_show_properties
\donothing
}
203 204
\unexpanded
\def
\meta_analyze_graphicname_indeed
[#
1
:
:
#
2
:
:
#
3
]
% instance ::
205
{
\edef
\currentMPgraphicname
{
#
2
}
%
206
\ifempty
\currentMPgraphicname
207
\edef
\currentMPgraphicname
{
#
1
}
%
208
\let
\currentMPinstance
\defaultMPinstance
209
\orelse\ifcsname
\??mpdefinitions
#
1
\endcsname
210
\edef
\currentMPinstance
{
#
1
}
%
211
\else
212
\let
\currentMPinstance
\defaultMPinstance
213
\fi
214
\edef
\currentMPformat
{
\MPinstanceparameter
\s!format
}
%
215
\meta_show_properties
}
216 217
\def
\currentMPgraphicname
{
\s!unknown
}
218
\def
\currentMPinstance
{
\defaultMPinstance
}
219
\def
\currentMPformat
{
\currentMPinstance
}
220 221
\defineMPinstance
[
metafun
]
[
\s!format
=
metafun
,
\s!extensions
=
\v!yes
,
\s!initializations
=
\v!yes
]
222
\defineMPinstance
[
minifun
]
[
\s!format
=
minifun
,
\s!extensions
=
\v!yes
,
\s!initializations
=
\v!yes
]
223
\defineMPinstance
[
extrafun
]
[
\s!format
=
metafun
,
\s!extensions
=
\v!yes
,
\s!initializations
=
\v!yes
]
224
\defineMPinstance
[
lessfun
]
[
\s!format
=
metafun
]
225
\defineMPinstance
[
doublefun
]
[
\s!format
=
metafun
,
\s!extensions
=
\v!yes
,
\s!initializations
=
\v!yes
,
\c!method
=
\s!double
]
226
\defineMPinstance
[
binaryfun
]
[
\s!format
=
metafun
,
\s!extensions
=
\v!yes
,
\s!initializations
=
\v!yes
,
\c!method
=
\s!binary
]
227
\defineMPinstance
[
decimalfun
]
[
\s!format
=
metafun
,
\s!extensions
=
\v!yes
,
\s!initializations
=
\v!yes
,
\c!method
=
\s!decimal
]
228 229
\defineMPinstance
[
mprun
]
[
\s!format
=
metafun
,
\s!extensions
=
\v!yes
,
\s!initializations
=
\v!yes
]
230 231
\defineMPinstance
[
metapost
]
[
\s!format
=
mpost
]
232
\defineMPinstance
[
nofun
]
[
\s!format
=
mpost
]
233
\defineMPinstance
[
doublepost
]
[
\s!format
=
mpost
,
\c!method
=
\s!double
]
234
\defineMPinstance
[
binarypost
]
[
\s!format
=
mpost
,
\c!method
=
\s!binary
]
235
\defineMPinstance
[
decimalpost
][
\s!format
=
mpost
,
\c!method
=
\s!decimal
]
236 237
\defineMPinstance
[
simplefun
]
[
\s!format
=
metafun
,
\c!method
=
\s!double
]
% maybe use minifun
238 239
%defineMPinstance[megapost] [\s!format=mpost,\c!method=\s!decimal]
240 241
\newconditional
\c_meta_include_initializations
242 243
\def
\meta_begin_graphic_group
#
1
%
244
{
\begingroup
245
\meta_analyze_graphicname
[#
1
]
}
246 247
\def
\meta_end_graphic_group
248
{
\endgroup
}
249 250
\def
\MPaskedfigure
{
false
}
251 252
\def
\meta_flush_current_initializations
253
{
\ifconditional
\c_meta_include_initializations
254
\the
\t_meta_initializations
255
\fi
}
256 257
\def
\meta_flush_current_inclusions
258
{
\the
\t_meta_inclusions
}
259 260
\def
\meta_flush_current_definitions
261
{
\the
\t_meta_definitions
}
262 263
\def
\meta_start_current_graphic
264
{
\begingroup
265
\meta_enable_include
266
\the
\everyMPgraphic
267
\edef
\p_initializations
{
\MPinstanceparameter
\s!initializations
}
%
268
\ifx
\p_initializations
\v!yes
269
\settrue
\c_meta_include_initializations
270
\else
271
\setfalse
\c_meta_include_initializations
272
\fi
273
\edef
\p_setups
{
\MPinstanceparameter
\c!setups
}
%
274
\ifempty
\p_setups
\else
275
\setups
[
\p_setups
]
%
276
\fi
277
\useMPinstancestyleparameter
\c!textstyle
}
278 279
\def
\meta_set_current_color
280
{
\useMPinstancecolorparameter
\c!textcolor
}
281 282
\def
\meta_stop_current_graphic
283
{
\global
\t_meta_definitions
\emptytoks
284
\global
\t_meta_inclusions
\emptytoks
285
\endgroup
}
286 287
\def
\meta_process_graphic_start
288
{
\pushMPboundingbox
289
\setbox
\b_meta_graphic
\hpack
\bgroup
}
290 291
\let
\meta_relocate_graphic
\relax
% experimental hook
292 293
\def
\meta_process_graphic_stop
294
{
\egroup
295
\meta_place_graphic
296
\meta_relocate_graphic
297
\popMPboundingbox
}
298 299
\unexpanded
\def
\meta_process_graphic_instance
#
1
%
300
{
\edef
\currentMPinstance
{
#
1
}
%
301
\ifempty
\currentMPinstance
302
\let
\currentMPinstance
\defaultMPinstance
303
\fi
304
\edef
\currentMPformat
{
\MPinstanceparameter
\s!format
}
%
305
\meta_process_graphic
}
306 307
\unexpanded
\def
\meta_process_graphic
#
1
% todo: extensions and inclusions outside beginfig
308
{
\meta_start_current_graphic
309
\forgetall
310
\edef
\p_extensions
{
\MPinstanceparameter
\s!extensions
}
%
311
\meta_process_graphic_start
312
\normalexpanded
{
\noexpand
\clf_mpgraphic
313
instance
{
\currentMPinstance
}
%
314
format
{
\currentMPformat
}
%
315
data
{
#
1
;
}
%
316
initializations
{
\meta_flush_current_initializations
}
%
317
\ifx
\p_extensions
\v!yes
318
extensions
{
\clf_getmpextensions
{
\currentMPinstance
}}
% goes through tex again
319
\fi
320
inclusions
{
\meta_flush_current_inclusions
}
%
321
definitions
{
\meta_flush_current_definitions
}
%
322
figure
{
\MPaskedfigure
}
%
323
method
{
\MPinstanceparameter
\c!method
}
%
324
namespace
{
\??graphicvariable
\currentmpvariableclass
:
}
%
325
\relax
}
%
326
\meta_process_graphic_stop
327
\meta_stop_current_graphic
}
328 329
\let
\meta_process_graphic_figure_start
\relax
330
\let
\meta_process_graphic_figure_stop
\relax
331 332
\unexpanded
\def
\processMPfigurefile
#
1
% special case: obeys beginfig .. endfig and makes pages
333
{
\begingroup
334
\let
\normal_meta_process_graphic_start
\meta_process_graphic_start
335
\let
\normal_meta_process_graphic_stop
\meta_process_graphic_stop
336
\let
\meta_process_graphic_start
\relax
337
\let
\meta_process_graphic_stop
\relax
338
\def
\meta_process_graphic_figure_start
{
\startTEXpage
[
\c!offset
=
\v!overlay
,
\c!align
=]
\normal_meta_process_graphic_start
}
%
339
\def
\meta_process_graphic_figure_stop
{
\normal_meta_process_graphic_stop
\stopTEXpage
}
340
\def
\MPaskedfigure
{
all
}
%
341
\meta_process_graphic
{
input
"#
1
"
;
}
%
342
\endgroup
}
343 344
%D Calling up previously defined graphics.
345 346
% \def\includeMPgraphic#1% gets expanded !
347
% {\ifcsname\??mpgraphic#1\endcsname
348
% \csname\??mpgraphic#1\endcsname ; % ; is safeguard
349
% \fi}
350
%
351
% \unexpanded\def\meta_enable_include % public
352
% {\let\meta_handle_use_graphic \thirdofthreearguments
353
% \let\meta_handle_reusable_graphic\thirdofthreearguments}
354
%
355
% but ... we want this too:
356
%
357
% \startuseMPgraphic{x}
358
% draw textext("\externalfigure[foo.pdf]") ;
359
% \stopuseMPgraphic
360
%
361
% \useMPgraphic{x}
362
%
363
% so we cannot overload unless we let back to the original meanings each graphic
364
% ... a better solution is:
365 366
\def
\includeMPgraphic
#
1
% gets expanded !
367
{
\ifcsname
\??mpgraphic
#
1
\endcsname
368
\doubleexpandafter\fourthoffourarguments
\lastnamedcs
;
% ; is safeguard
369
\fi
}
370 371
\let
\meta_enable_include
\relax
372 373
%D Drawings (stepwise built):
374 375
\newif
\ifMPdrawingdone
\MPdrawingdonefalse
376 377
\unexpanded
\def
\finalizeMPdrawing
378
{
\MPdrawingdonetrue
}
379 380
\let
\MPdrawingdata
\empty
381 382
\unexpanded
\def
\resetMPdrawing
383
{
\glet
\MPdrawingdata
\empty
384
\global
\MPdrawingdonefalse
}
385 386
\unexpanded
\def
\pushMPdrawing
387
{
\globalpushmacro
\MPdrawingdata
388
\glet
\MPdrawingdata
\empty
}
389 390
\unexpanded
\def
\popMPdrawing
391
{
\globalpopmacro
\MPdrawingdata
}
392 393
\unexpanded
\def
\getMPdrawing
394
{
\ifMPdrawingdone
395
\expandafter
\meta_process_graphic
\expandafter
{
\MPdrawingdata
}
% is this expansion still needed?
396
\fi
}
397 398
\def
\startMPdrawing
399
{
\dosingleempty
\meta_start_drawing
}
400 401
\def
\meta_start_drawing
[#
1
]#
2
\stopMPdrawing
% to be redone, this ascii stuff
402
{
\relax
403
\bgroup
404
\meta_enable_include
405
\doifelse
{
#
1
}{
-
}{
\convertargument
#
2
\to
\asciia
}{
\def
\asciia
{
#
2
}}
%
406
\xdef
\MPdrawingdata
{
\MPdrawingdata
\asciia
}
%
407
\egroup
}
408 409
\let
\stopMPdrawing
\relax
410 411
\def
\MPdrawing
#
1
%
412
{
\relax
413
\bgroup
414
\meta_enable_include
415
\xdef
\MPdrawingdata
{
\MPdrawingdata
#
1
}
%
416
\egroup
}
417 418
\unexpanded
\def
\startMPclip
#
1
#
2
\stopMPclip
% todo: store at the lua end or just store less
419
{
\setgvalue
{
\??mpclip
#
1
}{
#
2
}}
420 421
\let
\stopMPclip
\relax
422 423
\unexpanded
\def
\meta_grab_clip_path
#
1
#
2
#
3
%
424
{
\begingroup
425
\d_overlay_width
#
2
\relax
426
\d_overlay_height
#
3
\relax
427
\edef
\width
{
\the
\d_overlay_width
\space
}
%
428
\edef
\height
{
\the
\d_overlay_height
\space
}
%
429
\edef
\currentMPclip
{
#
1
}
%
430
\ifcsname
\??mpclip
\currentMPclip
\endcsname
431
\meta_grab_clip_path_yes
432
\else
433
\meta_grab_clip_path_nop
434
\fi
435
\endgroup
}
436 437
\def
\meta_grab_clip_path_yes
438
{
\meta_start_current_graphic
439
\normalexpanded
{
\noexpand
\clf_mpsetclippath
440
instance
{
\currentMPinstance
}
%
441
format
{
\currentMPformat
}
%
442
data
{
\csname
\??mpclip
\currentMPclip
\endcsname
}
%
443
initializations
{
\meta_flush_current_initializations
}
%
444
useextensions
{
\MPinstanceparameter
\s!extensions
}
%
445
inclusions
{
\meta_flush_current_inclusions
}
%
446
method
{
\MPinstanceparameter
\c!method
}
%
447
width
\d_overlay_width
448
height
\d_overlay_height
449
\relax
}
%
450
\meta_stop_current_graphic
}
451 452
\def
\meta_grab_clip_path_nop
453
{
\clf_mpsetclippath
454
width
\d_overlay_width
455
height
\d_overlay_height
456
\relax
}
457 458
%D Since we want labels to follow the document settings, we also set the font
459
%D related variables.
460 461
\unexpanded
\def
\MPfontsizehskip
#
1
%
462
{
\dontleavehmode
463
\begingroup
464
\definedfont
[#
1
]
%
465
\hskip
\clf_currentdesignsize
\scaledpoint
\relax
466
\endgroup
}
467 468
\definefontsynonym
[
MetafunDefault
][
Regular
*
default
]
469 470
\startMPinitializations
% scale is not yet ok
471
defaultfont
:
=
"
\truefontname{MetafunDefault}
"
;
472
% defaultscale:=\the\bodyfontsize/10pt; % only when hard coded 10pt
473
% defaultscale:=1;
474
\stopMPinitializations
475 476
%D A signal that we're in combined \CONTEXT||\METAFUN mode:
477 478
\startMPextensions
479
string
contextversion
;
contextversion
:
=
"
\contextversion
"
;
% expanded
480
\stopMPextensions
481 482
%D \macros
483
%D {setupMPvariables}
484
%D
485
%D When we build collections of \METAPOST\ graphics, like background and buttons,
486
%D the need for passing settings arises. By (mis|)|using the local prefix that
487
%D belongs to \type {\framed}, we get a rather natural interface to backgrounds. To
488
%D prevent conflicts, we will use the \type {-} in \METAPOST\ specific variables,
489
%D like:
490
%D
491
%D \starttyping
492
%D \setupMPvariables[meta:button][size=20pt]
493
%D \stoptyping
494 495
% \lineheight 2pt 2 \scratchcounter red 0.4 .5\bodyfontsize
496
%
497
% see cont-loc for test code
498 499
%D Currently the inheritance of backgrounds does not work and we might drop it
500
%D anyway (too messy)
501 502
\newbox
\b_meta_variable_box
503 504
\let
\currentmpvariableclass
\empty
505
\let
\m_meta_current_variable
\empty
506
\let
\m_meta_current_variable_template
\empty
507 508
\installcorenamespace
{
graphicvariable
}
509 510
\def
\meta_prepare_variable_default
{
\MPcolor
{
black
}}
% just to be sure we use a color but ...
511 512
\unexpanded
\def
\setupMPvariables
513
{
\dodoubleempty
\meta_setup_variables
}
514 515
\def
\meta_setup_variables
[#
1
][#
2
]
%
516
{
\ifsecondargument
517
\getrawparameters
[
\??graphicvariable
#
1
:
][#
2
]
%
518
\else
519
\getrawparameters
[
\??graphicvariable
:
][#
1
]
%
520
\fi
}
521 522
\unexpanded
\def
\presetMPvariable
523
{
\dodoubleargument
\meta_preset_variable
}
524 525
\def
\meta_preset_variable
[#
1
][#
2
=#
3
]
%
526
{
\ifcsname
\??graphicvariable
#
1
:
#
2
\endcsname
\else
527
\setvalue
{
\??graphicvariable
#
1
:
#
2
}{
#
3
}
%
528
\fi
}
529 530
\def
\MPrawvar
#
1
#
2
% no checking
531
{
\begincsname
\??graphicvariable
#
1
:
#
2
\endcsname
}
532 533
\def
\MPvariable
#
1
% todo: could be a framed chain
534
{
\begincsname
\??graphicvariable
\currentmpvariableclass
:
#
1
\endcsname
}
535 536
\unexpanded
\def
\useMPvariables
537
{
\dodoubleargument
\meta_use_variables
}
538 539
\def
\meta_use_variables
[#
1
][#
2
]
%
540
{
\edef
\currentmpvariableclass
{
#
1
}
%
541
\meta_prepare_variables
{
#
2
}}
542 543
\unexpanded
\def
\meta_prepare_variables
#
1
%
544
{
\processcommalist
[#
1
]
\meta_prepare_variable
}
545 546
\unexpanded
\def
\meta_prepare_variable
#
1
%
547
{
\edef
\m_meta_current_variable_template
548
{
\??graphicvariable
\currentmpvariableclass
:
#
1
}
%
549
\edef
\m_meta_current_variable
550
{
\begincsname
\m_meta_current_variable_template
\endcsname
}
%
551
\ifempty
\m_meta_current_variable
552
\expandafter
\meta_prepare_variable_nop
553
\else
554
\expandafter
\meta_prepare_variable_yes
555
\fi
}
556 557
\unexpanded
\def
\meta_prepare_instance_variables
558
{
\expandafter
\processcommalist
\expandafter
[
\m_meta_instance_variables
]
\meta_prepare_instance_variable
}
559 560
\unexpanded
\def
\meta_prepare_instance_variable
#
1
%
561
{
\edef
\m_meta_current_variable_template
562
{
\??graphicvariable
\currentmpvariableclass
:
#
1
}
%
563
\edef
\m_meta_current_variable
564
{
\ifcsname
\m_meta_current_variable_template
\endcsname
565
\lastnamedcs
566
\else
567
\begincsname
\??graphicvariable
\currentMPgraphicname
:
#
1
\endcsname
568
\fi
}
%
569
\ifempty
\m_meta_current_variable
570
\expandafter
\meta_prepare_variable_nop
571
\else
572
\expandafter
\meta_prepare_variable_yes
573
\fi
}
574 575
\def
\meta_prepare_variable_nop
576
{
\expandafter
\let\csname
\m_meta_current_variable_template
\endcsname
\meta_prepare_variable_default
}
577 578
\def
\meta_prepare_variable_color
% we use the attribute so we dont' go through namedcolor (why not)
579
{
\expandafter\edef\csname
\m_meta_current_variable_template
\endcsname
{
\MPcolor
\m_meta_current_variable
}}
580 581
\def
\meta_prepare_variable_number
582
{
\expandafter\edef\csname
\m_meta_current_variable_template
\endcsname
{
\number
\m_meta_current_variable
}}
% also accepts 0.number
583 584
\def
\meta_prepare_variable_dimension
585
{
\expandafter\edef\csname
\m_meta_current_variable_template
\endcsname
{
\the\dimexpr
\m_meta_current_variable
}}
586 587
\def
\meta_prepare_variable_yes
588
{
\ifchkdim
\m_meta_current_variable
\or
589
\meta_prepare_variable_dimension
590
\else\ifchknum
\m_meta_current_variable
\or
591
\meta_prepare_variable_number
592
\else
593
\doifelsecolor
\m_meta_current_variable
594
\meta_prepare_variable_color
595
\meta_prepare_variable_dimension
596
\fi\fi
}
597 598
\let
\MPvar
\MPvariable
599
\let
\setMPvariables\setupMPvariables
600 601
%D \macros
602
%D {startuniqueMPgraphic, uniqueMPgraphic}
603
%D
604
%D This macros is probably of most use to myself, since I like to use graphics that
605
%D adapt themselves. The next \METAPOST\ kind of graphic is both unique and reused
606
%D when possible.
607
%D
608
%D \starttyping
609
%D \defineoverlay[example][\uniqueMPgraphic{test}]
610
%D
611
%D \startuniqueMPgraphic {test}
612
%D draw OverlayBox ;
613
%D \stopuniqueMPgraphic
614
%D
615
%D \startuniqueMPgraphic {test}
616
%D draw OverlayBox ;
617
%D \stopuniqueMPgraphic
618
%D \stoptyping
619 620
\def
\overlaystamp
% watch the \MPcolor, since colors can be redefined
621
{
\the
\d_overlay_width
:
%
622
\the
\d_overlay_height
:
%
623
\the
\d_overlay_depth
:
%
624
\the
\d_overlay_offset
:
%
625
\the
\d_overlay_linewidth
:
%
626
\MPcolor\overlaycolor
:
% % todo, expand once \m_overlaycolor
627
\MPcolor\overlaylinecolor
}
% todo, expand once \m_overlaylinecolor
628 629
%D A better approach is to let additional variables play a role in determining the
630
%D uniqueness. In the next macro, the second, optional, argument is used to
631
%D guarantee the uniqueness, as well as prepare variables for passing them to
632
%D \METAPOST.
633
%D
634
%D \starttyping
635
%D \startuniqueMPgraphic{meta:hash}{gap,angle,...}
636
%D \stoptyping
637
%D
638
%D The calling macro also accepts a second argument. For convenient use in overlay
639
%D definitions, we use \type {{}} instead of \type {[]}.
640
%D
641
%D \starttyping
642
%D \uniqueMPgraphic{meta:hash}{gap=10pt,angle=30}
643
%D \stoptyping
644 645
\newcount
\c_meta_object_counter
646
\newbox
\b_meta_graphic
647 648
% hm, isn't this already done elsewhere?
649 650
\unexpanded
\def
\meta_obey_box_depth
651
{
\setbox
\b_meta_graphic
\hpack
\bgroup
652
\raise
\MPlly
\box
\b_meta_graphic
653
\egroup
}
654 655
\unexpanded
\def
\meta_ignore_box_depth
656
{
\normalexpanded
657
{
\meta_obey_box_depth
% hence the \unexpanded
658
\wd
\b_meta_graphic
\the\wd
\b_meta_graphic
659
\ht
\b_meta_graphic
\the\ht
\b_meta_graphic
660
\dp
\b_meta_graphic
\the\dp
\b_meta_graphic
}}
661 662
\unexpanded
\def
\meta_obey_box_origin
663
{
\setbox
\b_meta_graphic
\hpack
\bgroup
664
\kern
\MPllx
\raise
\MPlly
\box
\b_meta_graphic
665
\egroup
}
666 667
\unexpanded
\def
\obeyMPboxdepth
{
\let
\meta_relocate_box
\meta_obey_box_depth
}
668
\unexpanded
\def
\ignoreMPboxdepth
{
\let
\meta_relocate_box
\meta_ignore_box_depth
}
669
\unexpanded
\def
\obeyMPboxorigin
{
\let
\meta_relocate_box
\meta_obey_box_origin
}
670
\unexpanded
\def
\normalMPboxdepth
{
\let
\meta_relocate_box
\relax
}
671 672
\let
\meta_relocate_box
\relax
673 674
\unexpanded
\def
\meta_place_graphic
% the converter also displaces so in fact we revert
675
{
\meta_relocate_box
676
\box
\b_meta_graphic
}
677 678
\unexpanded
\def
\meta_reuse_box
#
1
#
2
#
3
#
4
#
5
% space delimiting would save some tokens
679
{
\MPllx
#
2
\MPlly
#
3
\MPurx
#
4
\MPury
#
5
%
680
\hpack
{
\forcecolorhack
\getobject
{
MP
}{
#
1
}}}
% else no proper color intent
681 682
\unexpanded
\def
\meta_use_box
683
{
\setunreferencedobject
{
MP
}}
684 685
\def
\meta_handle_unique_graphic
#
1
#
2
#
3
% when there are too many, we can store data at the lua end, although,
686
{
\begingroup
% when there are that many they're probably not that unique anyway
687
\edef
\currentmpvariableclass
{
#
1
}
%
688
\extendMPoverlaystamp
{
#
2
}
% incl prepare
689
\ifcsname
\??mpgraphic
\overlaystamp
:
#
1
\endcsname
690
\lastnamedcs
691
\else
692
\meta_enable_include
% redundant
693
\global\advance
\c_meta_object_counter
\plusone
694
\meta_use_box
{
\number
\c_meta_object_counter
}
\hpack
{
\meta_process_graphic
{
#
3
}}
% was vbox, graphic must end up as hbox
695
\setxvalue
{
\??mpgraphic
\overlaystamp
:
#
1
}{
\meta_reuse_box
{
\number
\c_meta_object_counter
}{
\the
\MPllx
}{
\the
\MPlly
}{
\the
\MPurx
}{
\the
\MPury
}}
%
696
\csname
\??mpgraphic
\overlaystamp
:
#
1
\endcsname
\empty
697
\fi
698
\endgroup
}
699 700
\unexpanded
\def
\startuniqueMPgraphic
701
{
\dodoublegroupempty\meta_start_unique_graphic
}
702 703
\let
\stopuniqueMPgraphic
\relax
704 705
\def
\meta_start_unique_graphic
#
1
%
706
{
\normalexpanded
{
\meta_start_unique_graphic_indeed
{
#
1
}}}
707 708
\unexpanded
\def
\meta_start_unique_graphic_indeed
#
1
#
2
#
3
\stopuniqueMPgraphic
709
{
\setgvalue
{
\??mpgraphic
#
1
}{
\meta_handle_unique_graphic
{
#
1
}{
#
2
}{
#
3
}}}
710 711
\unexpanded
\def
\uniqueMPgraphic
712
{
\dodoublegroupempty\meta_unique_graphic
}
713 714
\def
\meta_unique_graphic
#
1
#
2
%
715
{
\meta_begin_graphic_group
{
#
1
}
%
716
\setupMPvariables
[#
1
][#
2
]
%
717
\begincsname
\??mpgraphic
#
1
\endcsname
\empty
718
\meta_end_graphic_group
}
719 720
\def
\meta_handle_use_graphic
#
1
#
2
#
3
%
721
{
\begingroup
722
\edef
\currentmpvariableclass
{
#
1
}
%
723
\edef
\m_meta_instance_variables
{
#
2
}
%
724
\ifempty
\m_meta_instance_variables
\else
725
\meta_prepare_instance_variables
726
\fi
727
\meta_enable_include
% redundant
728
\meta_process_graphic
{
#
3
}
%
729
\endgroup
}
730 731
\unexpanded
\def
\startuseMPgraphic
732
{
\dodoublegroupempty\meta_start_use_graphic
}
733 734
\let
\stopuseMPgraphic
\relax
735 736
\def
\meta_start_use_graphic
#
1
%
737
{
\normalexpanded
{
\meta_start_use_graphic_indeed
{
#
1
}}}
738 739
\unexpanded
\def
\meta_start_use_graphic_indeed
#
1
#
2
#
3
\stopuseMPgraphic
740
{
\setgvalue
{
\??mpgraphic
#
1
}{
\meta_handle_use_graphic
{
#
1
}{
#
2
}{
#
3
}}}
741 742
\unexpanded
\def
\startusableMPgraphic
% redundant but handy
743
{
\dodoublegroupempty
\meta_start_usable_graphic
}
744 745
\let
\stopusableMPgraphic
\relax
746 747
\def
\meta_start_usable_graphic
#
1
%
748
{
\normalexpanded
{
\meta_start_usable_graphic_indeed
{
#
1
}}}
749 750
\unexpanded
\def
\meta_start_usable_graphic_indeed
#
1
#
2
#
3
\stopusableMPgraphic
751
{
\setgvalue
{
\??mpgraphic
#
1
}{
\meta_handle_use_graphic
{
#
1
}{
#
2
}{
#
3
}}}
752 753
\def
\meta_handle_reusable_graphic
#
1
#
2
#
3
%
754
{
\begingroup
755
\edef
\currentmpvariableclass
{
#
1
}
%
756
\edef
\m_meta_instance_variables
{
#
2
}
%
757
\ifempty
\m_meta_instance_variables
\else
758
\meta_prepare_instance_variables
759
\fi
760
\meta_enable_include
% redundant
761
\global\advance
\c_meta_object_counter
\plusone
762
\meta_use_box
{
\number
\c_meta_object_counter
}
\hpack
{
\meta_process_graphic
{
#
3
}}
% was vbox, graphic must end up as hbox
763
\setxvalue
{
\??mpgraphic
#
1
}{
\meta_reuse_box
{
\number
\c_meta_object_counter
}{
\the
\MPllx
}{
\the
\MPlly
}{
\the
\MPurx
}{
\the
\MPury
}}
%
764
\csname
\??mpgraphic
#
1
\endcsname
\empty
765
\endgroup
}
766 767
\unexpanded
\def
\startreusableMPgraphic
768
{
\dodoublegroupempty\meta_start_reusable_graphic
}
769 770
\let
\stopreusableMPgraphic
\relax
771 772
\def
\meta_start_reusable_graphic
#
1
%
773
{
\normalexpanded
{
\meta_start_reusable_graphic_indeed
{
#
1
}}}
774 775
\unexpanded
\def
\meta_start_reusable_graphic_indeed
#
1
#
2
#
3
\stopreusableMPgraphic
776
{
\setgvalue
{
\??mpgraphic
#
1
}{
\meta_handle_reusable_graphic
{
#
1
}{
#
2
}{
#
3
}}}
777 778
\unexpanded
\def
\useMPgraphic
779
{
\dodoublegroupempty\meta_use_graphic
}
780 781
\def
\meta_use_graphic
#
1
#
2
%
782
{
\meta_begin_graphic_group
{
#
1
}
%
783
\ifcsname
\??mpgraphic
#
1
\endcsname
784
\edef
\usedMPgraphicname
{
#
1
}
%
785
\orelse\ifcsname
\??mpgraphic
\currentMPgraphicname
\endcsname
786
\let
\usedMPgraphicname
\currentMPgraphicname
787
\else
788
\let
\usedMPgraphicname
\empty
789
\fi
790
\ifempty
\usedMPgraphicname
791
% message
792
\else
793
\doifsomething
{
#
2
}{
\setupMPvariables
[
\usedMPgraphicname
][#
2
]
}
%
794
\csname
\??mpgraphic
\usedMPgraphicname
\endcsname
795
\fi
796
\meta_end_graphic_group
}
797 798
\let
\reuseMPgraphic
\useMPgraphic
% we can save a setup here if needed
799
\let
\reusableMPgraphic
\reuseMPgraphic
% we can save a setup here if needed
800 801
%D \macros
802
%D {startuniqueMPpagegraphic,uniqueMPpagegraphic}
803
%D
804
%D Experimental.
805 806
\def
\m_meta_page_prefix
{
\doifelseoddpage
oe
}
807 808
\def
\overlaypagestamp
809
{
\m_meta_page_prefix
:
%
810
\the
\d_overlay_width
:
%
811
\the
\d_overlay_height
:
%
812
\the
\d_overlay_depth
:
%
813
\the
\d_overlay_offset
:
%
814
\the
\d_overlay_linewidth
:
%
815
\MPcolor\overlaycolor
:
%
816
\MPcolor\overlaylinecolor
}
817 818
\unexpanded
\def
\startuniqueMPpagegraphic
819
{
\dodoublegroupempty\meta_start_unique_page_graphic
}
820 821
\let
\stopuniqueMPpagegraphic
\relax
822 823
\def
\meta_start_unique_page_graphic
#
1
%
824
{
\normalexpanded
{
\meta_start_unique_page_graphic_indeed
{
#
1
}}}
825 826
\unexpanded
\def
\meta_start_unique_page_graphic_indeed
#
1
#
2
#
3
\stopuniqueMPpagegraphic
% inefficient, double storage
827
{
\setgvalue
{
\??mpgraphic
o
:
#
1
}{
\meta_handle_unique_graphic
{
o
:
#
1
}{
#
2
}{
#
3
}}
% % but these also keep the state
828
\setgvalue
{
\??mpgraphic
e
:
#
1
}{
\meta_handle_unique_graphic
{
e
:
#
1
}{
#
2
}{
#
3
}}}
% and meaning will be redefined
829 830
\unexpanded
\def
\uniqueMPpagegraphic
831
{
\dodoublegroupempty\meta_unique_page_graphic
}
832 833
\def
\meta_unique_page_graphic
#
1
#
2
%
834
{
\meta_begin_graphic_group
{
#
1
}
%
835
\let
\overlaystamp
\overlaypagestamp
836
\setupMPvariables
[
\m_meta_page_prefix
:
#
1
][#
2
]
% prefix is new here
837
\csname
\??mpgraphic
\m_meta_page_prefix
:
#
1
\endcsname
\empty
838
\meta_end_graphic_group
}
839 840
%D One way of defining a stamp is:
841
%D
842
%D \starttyping
843
%D \def\extendMPoverlaystamp#1%
844
%D {\def\docommand##1%
845
%D {\edef\overlaystamp{\overlaystamp:\MPvariable{##1}}}%
846
%D \processcommalist[#1]\docommand}
847
%D \stoptyping
848
%D
849
%D Since we need to feed \METAPOST\ with expanded dimensions, we introduce a
850
%D dedicated expansion engine. We redefine \type {\extendMPoverlaystamp} to
851 852
\unexpanded
\def
\extendMPoverlaystamp
#
1
%
853
{
\processcommalist
[#
1
]
\meta_extend_overlay_stamp
}
854 855
\def
\meta_extend_overlay_stamp
#
1
%
856
{
\meta_prepare_instance_variable
{
#
1
}
%
857
\edef
\overlaystamp
{
\overlaystamp
:
\MPvariable
{
#
1
}}}
858 859
\unexpanded
\def
\getMPdata
{
\clf_getMPdata
}
860
\let
\rawMPdata
\clf_getMPdata
861 862
\unexpanded
\def
\getMPstored
{
\clf_getMPstored
}
863
\let
\rawMPstored
\clf_getMPstored
864 865
%D We need this trick because we need to make sure that the tex scanner sees
866
%D newlines and does not quit. Also, we do need to flush the buffer under a normal
867
%D catcode regime in order to expand embedded tex macros. As usual with buffers,
868
%D \type {#1} can be a list.
869 870
\unexpanded
\def
\processMPbuffer
871
{
\dosingleempty
\meta_process_buffer
}
872 873
\def
\meta_process_buffer
[#
1
]
%
874
{
\meta_begin_graphic_group
{
#
1
}
%
875
\meta_process_graphic
{
\clf_feedback
{
\currentMPgraphicname
}}
%
876
\meta_end_graphic_group
}
877 878
\unexpanded
\def
\runMPbuffer
879
{
\dosingleempty
\meta_run_buffer
}
880 881
\def
\meta_run_buffer
[#
1
]
% processing only
882
{
\startnointerference
\meta_process_buffer
[#
1
]
\stopnointerference
}
883 884
%D \macros
885
%D {startMPenvironment, resetMPenvironment}
886
%D
887
%D In order to synchronize the main \TEX\ run and the runs local to \METAPOST,
888
%D environments can be passed.
889 890
\unexpanded
\def
\startMPenvironment
891
{
\begingroup
892
\catcode
\endoflineasciicode
\ignorecatcode
893
\dosingleempty
\meta_start_environment
}
894 895
\def
\meta_start_environment
[#
1
]#
2
\stopMPenvironment
896
{
\endgroup
897
\edef
\m_meta_option
{
#
1
}
898
\ifx
\m_meta_option
\s!reset
899
\resetMPenvironment
% reset mp toks
900
\orelse\ifx
\m_meta_option
\v!global
901
#
2
% % use in main doc too
902
\orelse\ifx
\m_meta_option
\!!plustoken
903
#
2
% % use in main doc too
904
\fi
905
\clf_mptexset
{
\detokenize
{
#
2
}}}
906 907
\let
\stopMPenvironment
\relax
908 909
\unexpanded
\def
\resetMPenvironment
910
{
\clf_mptexreset
}
911 912
\unexpanded
\def
\useMPenvironmentbuffer
[#
1
]
%
913
{
\clf_mptexsetfrombuffer
{
#
1
}}
914 915
%D This command takes \type {[reset]} as optional argument.
916
%D
917
%D \starttyping
918
%D \startMPenvironment
919
%D \setupbodyfont[pos,14.4pt]
920
%D \stopMPenvironment
921
%D
922
%D \startMPcode
923
%D draw btex \sl Hans Hagen etex scaled 5 ;
924
%D \stopMPcode
925
%D \stoptyping
926
%D
927
%D The most simple case:
928 929
\unexpanded
\def
\startMPcode
930
{
\dosinglegroupempty\meta_start_code
}
931 932
\let
\stopMPcode
\relax
933 934
\def
\meta_start_code
935
{
\iffirstargument
936
\expandafter
\meta_start_code_instance
937
\else
938
\expandafter
\meta_start_code_standard
939
\fi
}
940 941
\def
\meta_start_code_instance
#
1
#
2
\stopMPcode
942
{
\begingroup
943
\edef
\currentMPinstance
{
#
1
}
%
944
\let
\currentMPgraphicname
\empty
945
\edef
\currentMPformat
{
\MPinstanceparameter
\s!format
}
%
946
\meta_enable_include
947
\meta_process_graphic
{
#
2
}
%
948
\endgroup
}
949 950
\def
\meta_start_code_standard
#
1
#
2
\stopMPcode
951
{
\begingroup
952
\let
\currentMPinstance
\defaultMPinstance
953
\let
\currentMPgraphicname
\empty
954
\edef
\currentMPformat
{
\MPinstanceparameter
\s!format
}
%
955
\meta_process_graphic
{
#
2
}
%
956
\endgroup
}
957 958
\unexpanded
\def
\MPcode
959
{
\dodoublegroupempty
\meta_code
}
960 961
\def
\meta_code
962
{
\ifsecondargument
963
\expandafter
\meta_code_instance
964
\else
965
\expandafter
\meta_code_standard
966
\fi
}
967 968
\def
\meta_code_instance
#
1
#
2
%
969
{
\meta_begin_graphic_group
{
#
1
}
%
970
\meta_enable_include
971
\meta_process_graphic
{
#
2
}
%
972
\meta_end_graphic_group
}
973 974
\def
\meta_code_standard
#
1
#
2
%
975
{
\let
\currentMPinstance
\defaultMPinstance
976
\meta_enable_include
977
\meta_process_graphic
{
#
1
}}
978 979
% a bit nasty (also needed for compatibility:
980 981
% \startMPrun input mp-www.mp ; \stopMPrun
982
% \externalfigure[mprun.3][width=10cm,height=8cm]
983 984
% \startMPrun{mprun} input mp-www.mp ; \stopMPrun % instance
985
% \externalfigure[mprun.4][width=10cm,height=8cm]
986 987
\let
\MPruninstance
\defaultMPinstance
988 989
\unexpanded
\def
\useMPrun
#
1
#
2
% name n
990
{
\begingroup
991
\def
\MPaskedfigure
{
#
2
}
%
992
\doifelsenothing
{
#
1
}
993
{
\useMPgraphic
{
mprun
}
}
%
994
{
\useMPgraphic
{
#1
}
}
%
995
\endgroup
}
996 997
\unexpanded
\def
\startMPrun
998
{
\dosinglegroupempty
\meta_start_run
}
999 1000
\def
\meta_start_run
#
1
#
2
\stopMPrun
1001
{
\iffirstargument
1002
\startuseMPgraphic
{
#1
}
#
2
\stopuseMPgraphic
1003
\else
1004
\startuseMPgraphic
{
mprun
}
#
2
\stopuseMPgraphic
1005
\fi
}
1006 1007
\let
\stopMPrun
\relax
1008 1009
%D The \type {\resetMPenvironment} is a quick way to erase
1010
%D the token list.
1011
%D
1012
%D You should be aware of independencies. For instance, if you use a font
1013
%D in a graphic that is not used in the main document, you need to load the
1014
%D typescript at the outer level (either directly or by using the global
1015
%D option).
1016
%D
1017
%D \starttyping
1018
%D \usetypescript[palatino][texnansi]
1019
%D
1020
%D \startMPenvironment
1021
%D \usetypescript[palatino][texnansi]
1022
%D \enableregime[utf]
1023
%D \setupbodyfont[palatino]
1024
%D \stopMPenvironment
1025
%D
1026
%D \startMPpage
1027
%D draw btex aap‒noot coördinatie – één etex ;
1028
%D \stopMPpage
1029
%D \stoptyping
1030 1031
%D Loading specific \METAPOST\ related definitions is
1032
%D accomplished by:
1033 1034
\unexpanded
\def
\useMPlibrary
[#
1
]
{
\clf_useMPlibrary
{
#
1
}}
1035 1036
%D \macros
1037
%D {setMPtext, MPtext, MPstring, MPbetex}
1038
%D
1039
%D To be documented:
1040
%D
1041
%D \starttyping
1042
%D \setMPtext{identifier}{text}
1043
%D
1044
%D \MPtext {identifier}
1045
%D \MPstring{identifier}
1046
%D \MPbetex {identifier}
1047
%D \stoptyping
1048 1049
\installcorenamespace
{
mptext
}
1050 1051
\unexpanded
\def
\setMPtext
#
1
#
2
% todo : #1 must be made : safe
1052
{
\defconvertedargument
\ascii
{
#
2
}
%
1053
\dodoglobal\letvalue
{
\??mptext
#
1
}
\ascii
}
1054 1055
\def
\MPtext
#
1
{
\begincsname
\??mptext
#
1
\endcsname
\empty
}
1056
\def
\MPstring
#
1
{
"
\begincsname
\??mptext
#
1
\endcsname
\empty
"
}
1057
\def
\MPbetex
#
1
{
btex
\begincsname
\??mptext
#
1
\endcsname
\space
etex
}
1058 1059
%D In order to communicate conveniently with the \TEX\ engine, we introduce some
1060
%D typesetting variables.
1061 1062
% \setupcolors[state=stop,conversion=never] % quite tricky ... type mismatch
1063 1064
% \startMPextensions
1065
% color OverlayColor,OverlayLineColor;
1066
% \stopMPextensions
1067 1068
\startMPinitializations
1069
CurrentLayout
:
=
"
\currentlayout
"
;
1070
\stopMPinitializations
1071 1072
% \startMPinitializations
1073
% OverlayWidth:=\overlaywidth;
1074
% OverlayHeight:=\overlayheight;
1075
% OverlayDepth:=\overlaydepth;
1076
% OverlayLineWidth:=\overlaylinewidth;
1077
% OverlayOffset:=\overlayoffset;
1078
% \stopMPinitializations
1079 1080
%D A dirty trick, ** in colo-ini.lua (mpcolor). We cannot use a vardef, because
1081
%D that fails with spot colors.
1082 1083
\startMPinitializations
1084
def
OverlayLineColor
=
\ifempty
\overlaylinecolor
black
\else
\MPcolor
{
\overlaylinecolor
}
\fi
enddef
;
1085
def
OverlayColor
=
\ifempty
\overlaycolor
black
\else
\MPcolor
{
\overlaycolor
}
\fi
enddef
;
1086
\stopMPinitializations
1087 1088
% \newcount\c_overlay_colormodel
1089
% \newcount\c_overlay_color
1090
% \newcount\c_overlay_transparency
1091
% \newcount\c_overlay_linecolor
1092
% \newcount\c_overlay_linetransparency
1093 1094
% \appendtoks
1095
% \c_overlay_colormodel \c_attr_colormodel
1096
% \c_overlay_color \colo_helpers_inherited_current_ca\overlaycolor
1097
% \c_overlay_transparency \colo_helpers_inherited_current_ta\overlaycolor
1098
% \c_overlay_linecolor \colo_helpers_inherited_current_ca\overlaylinecolor
1099
% \c_overlay_linetransparency\colo_helpers_inherited_current_ta\overlaylinecolor
1100
% \to \everyMPgraphic
1101 1102
% \startMPinitializations
1103
% BaseLineSkip:=\the\baselineskip;
1104
% LineHeight:=\the\baselineskip;
1105
% BodyFontSize:=\the\bodyfontsize;
1106
% %
1107
% TopSkip:=\the\topskip;
1108
% StrutHeight:=\strutheight;
1109
% StrutDepth:=\strutdepth;
1110
% %
1111
% CurrentWidth:=\the\hsize;
1112
% CurrentHeight:=\the\vsize;
1113
% HSize:=\the\hsize ;
1114
% VSize:=\the\vsize ;
1115
% %
1116
% EmWidth:=\the\emwidth;
1117
% ExHeight:=\the\exheight;
1118
% \stopMPinitializations
1119 1120
\appendtoks
1121
\disablediscretionaries
1122
%\disablecompoundcharacters
1123
\to
\everyMPgraphic
1124 1125
% \appendtoks % before color, inefficient, replace by low level copy
1126
% \doregistercolor{currentcolor}\currentcolorname
1127
% \to \everyMPgraphic
1128 1129
% \color[green]{abc \startMPcode
1130
% fill fullcircle scaled 3cm withoutcolor;
1131
% fill fullcircle scaled 2cm withcolor \MPcolor{currentcolor} ;
1132
% fill fullcircle scaled 1cm withcolor \MPcolor{red} ;
1133
% \stopMPcode def}
1134 1135
\appendtoks
1136
\baselineskip
1
\baselineskip
1137
\lineheight
1
\lineheight
1138
\topskip
1
\topskip
1139
\to
\everyMPgraphic
1140 1141
\appendtoks
1142
\let
\#
\letterhash
1143
\let
\_
\letterunderscore
1144
\let
\&
\letterampersand
1145
\let
\{
\letteropenbrace
1146
\let
\}
\letterclosebrace
1147
\to
\everyMPgraphic
1148 1149
%D \macros
1150
%D {PDFMPformoffset}
1151
%D
1152
%D In \PDF, forms are clipped and therefore we have to take precautions to get this
1153
%D right. Since this is related to objects, we use the same offset as used there.
1154 1155
\def
\PDFMPformoffset
{
\objectoffset
}
1156 1157
\newtoks
\everyinsertMPfile
1158 1159
\startMPextensions
1160
def
initialize_form_numbers
=
1161
do_initialize_numbers
;
1162
enddef
;
1163
\stopMPextensions
1164 1165
\startMPextensions
1166
vardef
ForegroundBox
=
1167
unitsquare
xysized
(
HSize
,
VSize
)
1168
enddef
;
1169
\stopMPextensions
1170 1171
% \startMPextensions
1172
% PageFraction := 1 ;
1173
% \stopMPextensions
1174 1175
% \startMPinitializations
1176
% PageFraction := if \lastpage>1: (\realfolio-1)/(\lastpage-1) else: 1 fi ;
1177
% \stopMPinitializations
1178 1179
\startMPdefinitions
{
metapost
}
1180
if
unknown
context_bare
:
input
mp
-
bare
.
mpiv
;
fi
;
1181
\stopMPdefinitions
1182
\startMPdefinitions
{
binarypost
}
1183
if
unknown
context_bare
:
input
mp
-
bare
.
mpiv
;
fi
;
1184
\stopMPdefinitions
1185
\startMPdefinitions
{
decimalpost
}
1186
if
unknown
context_bare
:
input
mp
-
bare
.
mpiv
;
fi
;
1187
\stopMPdefinitions
1188
\startMPdefinitions
{
doublepost
}
1189
if
unknown
context_bare
:
input
mp
-
bare
.
mpiv
;
fi
;
1190
\stopMPdefinitions
1191 1192
% \startMPdefinitions {nofun}
1193
% if unknown context_bare : input mp-bare.mpiv ; fi ;
1194
% \stopMPdefinitions
1195 1196
%D And some more. These are not really needed since we don't use the normal figure
1197
%D inclusion macros any longer.
1198 1199
\appendtoks
1200
\externalfigurepostprocessors
\emptytoks
% safeguard
1201
\to
\everyinsertMPfile
1202 1203
%D We also take care of disabling fancy figure features, that can terribly interfere
1204
%D when dealing with symbols, background graphics and running (postponed) graphics.
1205
%D You won't believe me if I tell you what funny side effects can occur. One took me
1206
%D over a day to uncover when processing the screen version of the \METAFUN\ manual.
1207 1208
\def
\doifelseMPgraphic
#
1
%
1209
{
\ifcsname
\??mpgraphic
#
1
\endcsname\expandafter
\firstoftwoarguments
\orelse
1210
\ifcsname
\??mpgraphic
o
:
#
1
\endcsname\expandafter
\firstoftwoarguments
\orelse
1211
\ifcsname
\??mpgraphic
e
:
#
1
\endcsname\expandafter
\firstoftwoarguments
\else
1212
\expandafter
\secondoftwoarguments
\fi
}
1213 1214
\let
\doifMPgraphicelse\doifelseMPgraphic
1215 1216
%D New:
1217 1218
\definelayerpreset
% no dx,dy - else nasty non-mp placement
1219
[
mp
]
1220
[
\c!y
=
-
\MPury
,
1221
\c!x
=
\MPllx
,
1222
\c!method
=
\v!fit
]
1223 1224
\definelayer
1225
[
mp
]
1226
[
\c!preset
=
mp
]
1227 1228
%D Usage:
1229
%D
1230
%D \starttyping
1231
%D \defineviewerlayer[one][state=start]
1232
%D \defineviewerlayer[two][state=stop]
1233
%D
1234
%D \startuseMPgraphic{step-1}
1235
%D fill fullcircle scaled 10cm withcolor red ;
1236
%D \stopuseMPgraphic
1237
%D
1238
%D \startuseMPgraphic{step-2}
1239
%D fill fullcircle scaled 5cm withcolor green ;
1240
%D \stopuseMPgraphic
1241
%D
1242
%D \setlayer[mp]{\viewerlayer[one]{\useMPgraphic{step-1}}}
1243
%D \setlayer[mp]{\viewerlayer[two]{\useMPgraphic{step-2}}}
1244
%D
1245
%D \ruledhbox{\flushlayer[mp]}
1246
%D \stoptyping
1247
%D
1248
%D Reusing graphics is also possible (now):
1249
%D
1250
%D \starttyping
1251
%D \startreusableMPgraphic{axis}
1252
%D tickstep := 1cm ; ticklength := 2mm ;
1253
%D drawticks unitsquare xscaled 4cm yscaled 3cm shifted (-1cm,-1cm) ;
1254
%D tickstep := tickstep/2 ; ticklength := ticklength/2 ;
1255
%D drawticks unitsquare xscaled 4cm yscaled 3cm shifted (-1cm,-1cm) ;
1256
%D \stopreusableMPgraphic
1257
%D
1258
%D \startuseMPgraphic{demo}
1259
%D drawpoint "1cm,1.5cm" ;
1260
%D \stopuseMPgraphic
1261
%D
1262
%D \definelayer[mp][preset=mp]
1263
%D \setlayer[mp]{\reuseMPgraphic{axis}}
1264
%D \setlayer[mp]{\useMPgraphic{demo}}
1265
%D \ruledhbox{\flushlayer[mp]}
1266
%D \stoptyping
1267 1268
%D \macros
1269
%D {startstaticMPfigure,useMPstaticfigure}
1270
%D
1271
%D Static figures are processed only when there has been something changed. Here is
1272
%D Aditya Mahajan's testcase:
1273
%D
1274
%D \startbuffer
1275
%D \startstaticMPfigure{circle}
1276
%D fill fullcircle scaled 1cm withcolor blue;
1277
%D \stopstaticMPfigure
1278
%D
1279
%D \startstaticMPfigure{axis}
1280
%D drawarrow (0,0)--(2cm,0) ;
1281
%D drawarrow (0,0)--(0,2cm) ;
1282
%D label.llft(textext("(0,0)") ,origin) ;
1283
%D \stopstaticMPfigure
1284
%D \stopbuffer
1285
%D
1286
%D \typebuffer \getbuffer
1287 1288
\unexpanded
\def
\startstaticMPfigure
#
1
#
2
\stopstaticMPfigure
1289
{
\startreusableMPgraphic
{
\??mpstaticgraphic#1
}
#
2
\stopreusableMPgraphic
}
1290 1291
\unexpanded
\def
\startstaticMPgraphic
1292
{
\dodoublegroupempty
\meta_start_static_graphic
}
1293 1294
\def
\meta_start_static_graphic
#
1
#
2
#
3
\stopstaticMPgraphic
1295
{
\startreusableMPgraphic
{
\??mpstaticgraphic#1
}
{
#2
}
#
3
\stopreusableMPgraphic
}
1296 1297
\let
\stopstaticMPfigure
\relax
1298
\let
\stopstaticMPgraphic
\relax
1299 1300
\unexpanded
\def
\usestaticMPfigure
1301
{
\dodoubleempty
\meta_use_static_figure
}
1302 1303
\def
\meta_use_static_figure
[#
1
][#
2
]
%
1304
{
\ifsecondargument
1305
\scale
[#
2
]
{
\reuseMPgraphic
{
\??mpstaticgraphic#1
}
}
%
1306
\else
1307
\reuseMPgraphic
{
\??mpstaticgraphic#1
}
%
1308
\fi
}
1309 1310
%D Goody for preventing overflows:
1311 1312
%def\MPdivten[#1]{\withoutpt\the\dimexpr#1pt/10\relax}
1313
\def
\MPdivten
[#
1
]
{
\thewithoutunit\dimexpr
#
1
pt
/
1
0
\relax
}
1314 1315
%D There is no way to distinguish the black color that you get when you issue a
1316
%D \type {draw} without color specification from a color that has an explicit black
1317
%D specification unless you set the variable \type {defaultcolormodel} to 1.
1318
%D Hoewever, in that case you cannot distinguish that draw from one with a \type
1319
%D {withoutcolor} specification. This means that we have to provide multiple
1320
%D variants of inheritance.
1321
%D
1322
%D In any case we need to tell the converter what the inherited color is to start
1323
%D with. Case~3 is kind of unpredictable as it closely relates to the order in which
1324
%D paths are flushed. If you want to inherit automatically from the surrounding, you
1325
%D can best stick to variant 1. Variant 0 (an isolated graphic) is the default.
1326
%D
1327
%D \startbuffer
1328
%D \startuseMPgraphic{test}
1329
%D drawoptions(withpen pencircle scaled 1pt) ;
1330
%D def shift_cp = currentpicture := currentpicture shifted (-15pt,0) ; enddef ;
1331
%D draw fullcircle scaled 10pt withoutcolor ; shift_cp ;
1332
%D fill fullcircle scaled 10pt ; shift_cp ;
1333
%D draw fullcircle scaled 10pt withoutcolor ; shift_cp ;
1334
%D fill fullcircle scaled 10pt withcolor red ; shift_cp ;
1335
%D draw fullcircle scaled 10pt withoutcolor ; shift_cp ;
1336
%D fill fullcircle scaled 10pt ; shift_cp ;
1337
%D \stopuseMPgraphic
1338
%D
1339
%D \starttabulate
1340
%D \NC 0\quad \NC \MPcolormethod0 \green XX\quad \useMPgraphic{test}\quad XX \NC \NR
1341
%D \NC 1\quad \NC \MPcolormethod1 \green XX\quad \useMPgraphic{test}\quad XX \NC \NR
1342
%D \NC 2\quad \NC \MPcolormethod2 \green XX\quad \useMPgraphic{test}\quad XX \NC \NR
1343
%D \NC 3\quad \NC \MPcolormethod3 \green XX\quad \useMPgraphic{test}\quad XX \NC \NR
1344
%D \stoptabulate
1345
%D \stopbuffer
1346
%D
1347
%D \typebuffer \getbuffer
1348 1349
\newconstant
\MPcolormethod
1350 1351
\appendtoks
1352
\clf_mpsetoutercolor
1353
\MPcolormethod
\space
1354
\c_attr_colormodel
\space
1355
\c_attr_color
\space
1356
\dogetattribute
{
transparency
}
\relax
1357
\to
\everyMPgraphic
1358 1359
% \startMPinitializations
1360
% defaultcolormodel := \ifcase\MPcolormethod1\or1\or3\else3\fi;
1361
% \stopMPinitializations
1362 1363
%D macros
1364
%D {mprunvar,mpruntab,mprunset}
1365
%D
1366
%D \starttyping
1367
%D \startMPcode
1368
%D passvariable("version","1.0") ;
1369
%D passvariable("number",123) ;
1370
%D passvariable("string","whatever") ;
1371
%D passvariable("point",(1.5,2.8)) ;
1372
%D passvariable("triplet",(1/1,1/2,1/3)) ;
1373
%D passvariable("quad",(1.1,2.2,3.3,4.4)) ;
1374
%D passvariable("boolean",false) ;
1375
%D passvariable("path",fullcircle scaled 1cm) ;
1376
%D draw fullcircle scaled 20pt ;
1377
%D \stopMPcode
1378
%D
1379
%D \ctxlua{inspect(metapost.variables)}
1380
%D
1381
%D \MPrunvar{version} \MPruntab{quad}{3} (\MPrunset{triplet}{,})
1382
%D
1383
%D $(x,y) = (\MPruntab{point}{1},\MPruntab{point}{2})$
1384
%D $(x,y) = (\MPrunset{point}{,})$
1385
%D \stoptyping
1386 1387
\def
\MPrunvar
#
1
{
\clf_mprunvar
{
#
1
}}
\let
\mprunvar
\MPrunvar
1388
\def
\MPruntab
#
1
#
2
{
\clf_mpruntab
{
#
1
}
#
2
\relax
}
\let
\mpruntab
\MPruntab
% #2 is number
1389
\def
\MPrunset
#
1
#
2
{
\clf_mprunset
{
#
1
}{
#
2
}}
\let
\mprunset
\MPrunset
1390 1391
\prependtoks
\clf_mppushvariables
\to
\everybeforepagebody
1392
\appendtoks
\clf_mppopvariables
\to
\everyafterpagebody
1393 1394
\let
\MPpushvariables
\clf_mppushvariables
1395
\let
\MPpopvariables
\clf_mppopvariables
1396 1397
%D We also provide an outputless run:
1398 1399
\unexpanded
\def
\startMPcalculation
1400
{
\begingroup 1401 \setbox\nextbox\hpack\bgroup 1402 \dosinglegroupempty\meta_start_calculation
}
1403 1404
\let
\stopMPcalculation
\relax
1405 1406
\def
\meta_start_calculation
1407
{
\iffirstargument
1408
\expandafter
\meta_start_calculation_instance
1409
\else
1410
\expandafter
\meta_start_calculation_standard
1411
\fi
}
1412 1413
\def
\meta_start_calculation_instance
#
1
#
2
\stopMPcalculation
1414
{
\edef
\currentMPinstance
{
#
1
}
%
1415
\let
\currentMPgraphicname
\empty
1416
\edef
\currentMPformat
{
\MPinstanceparameter
\s!format
}
%
1417
\meta_enable_include
1418
\meta_process_graphic
{
#
2
;
draw
origin
}
%
1419
\egroup
1420
\endgroup
}
1421 1422
\def
\meta_start_calculation_standard
#
1
#
2
\stopMPcalculation
1423
{
\let
\currentMPinstance
\defaultMPinstance
1424
\let
\currentMPgraphicname
\empty
1425
\edef
\currentMPformat
{
\MPinstanceparameter
\s!format
}
%
1426
\meta_process_graphic
{
#
2
;
draw
origin
}
%
1427
\egroup
1428
\endgroup
}
1429 1430
%D \macros
1431
%D {setupMPgraphics}
1432
%D
1433
%D Here is a generic setup command:
1434 1435
\installcorenamespace
{
MPgraphics
}
1436 1437
\installsetuponlycommandhandler
\??MPgraphics
{
MPgraphics
}
1438 1439
%D Here we hook in the outer color. When \type {color} is set to \type {global} we
1440
%D get the outer color automatically. If you change this setting, you should do it
1441
%D grouped in order not to make other graphics behave in unexpected ways.
1442 1443
\appendtoks
1444
\doifelse
{
\directMPgraphicsparameter
\c!color
}
\v!global
{
\MPcolormethod
\plusone
}{
\MPcolormethod
\zerocount
}
%
1445
\to
\everysetupMPgraphics
1446 1447
\setupMPgraphics
1448
[
\c!color
=
\v!local
]
1449 1450
%D This can save some runtime: rename the mpy file from a first run (when stable) to
1451
%D another file and reuse it. One can also use the original filename, but a copy is
1452
%D often better.
1453
%D
1454
%D \starttyping
1455
%D \setupMPgraphics
1456
%D [mpy=\jobname.mpy]
1457
%D \stoptyping
1458 1459
\appendtoks
1460
\edef
\p_mpy
{
\directMPgraphicsparameter
{
mpy
}}
%
1461
\ifempty
\p_mpy
\else
1462
\let
\MPdataMPYfile
\p_mpy
1463
\clf_registermpyfile
{
\p_mpy
}
%
1464
\fi
1465
\to
\everysetupMPgraphics
1466 1467
%D Some more helpers (see \type {meta-grd.mkiv} for an example of usage):
1468 1469
\def
\MPdpar
#
1
#
2
{
\the\dimexpr
#
1
#
2
\relax
\empty
}
1470
\def
\MPnpar
#
1
#
2
{
\the\numexpr
#
1
#
2
\relax
\empty
}
1471
\def
\MPspar
#
1
#
2
{
"#
1
#
2
"
}
1472 1473
%D Done.
1474 1475
\protect
\endinput
1476