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\writestatus{loading}{MetaPost Graphics Initializations}
62
63\registerctxluafile{metaini}{autosuffix}
64
65\unprotect
66
67\newtoks \everyMPgraphic
68
69\appendtoks
70 \setcatcodetable\ctxcatcodes
71
72 \restoreendofline
73\to \everyMPgraphic
74
75\mutable \def\MPruntimefile {mprun}
76\mutable \def\currentMPformat {metafun}
77\immutable\def\defaultMPinstance{metafun}
78
79\installcorenamespace{mpinstance}
80\installcorenamespace{mpinclusions}
81\installcorenamespace{mpdefinitions}
82\installcorenamespace{mpgraphic}
83\installcorenamespace{mpstaticgraphic}
84\installcorenamespace{mpclip}
85\installcorenamespace{mpcategory}
86
87\newtoks \t_meta_initializations
88
89\permanent\def\t_meta_inclusions {\csname\??mpinclusions \currentMPinstance\endcsname}
90\permanent\def\t_meta_definitions{\csname\??mpdefinitions\currentMPinstance\endcsname}
91
92
93
94
95
96\permanent\tolerant\protected\def\startMPdefinitions#=#:#2\stopMPdefinitions
97 {\let\m_meta_saved_instance\currentMPinstance
98 \cdef\currentMPinstance{#1}
99 \ifempty\currentMPinstance
100 \let\currentMPinstance\defaultMPinstance
101 \fi
102 \gtoksapp\t_meta_definitions{#2}
103 \let\currentMPinstance\m_meta_saved_instance}
104
105\permanent\protected\lettonothing\stopMPdefinitions
106
107\permanent\tolerant\protected\def\startMPextensions#=#:#2\stopMPextensions
108 {\clf_setmpextensions{#1}{#2}}
109
110\permanent\protected\lettonothing\stopMPextensions
111
112\permanent\protected\def\startMPinitializations#1\stopMPinitializations
113 {\gtoksapp\t_meta_initializations{#1}}
114
115\permanent\protected\lettonothing\stopMPinitializations
116
117\permanent\tolerant\protected\def\startMPinclusions[#1]##=#:#3\stopMPinclusions
118 {\let\m_meta_saved_instance\currentMPinstance
119 \cdef\currentMPinstance{#2}
120 \ifempty\currentMPinstance
121 \let\currentMPinstance\defaultMPinstance
122 \fi
123 \iftok{#1}{}\else
124 \global\t_meta_inclusions\emptytoks
125 \fi
126 \gtoksapp\t_meta_inclusions{#3}
127 \let\currentMPinstance\m_meta_saved_instance}
128
129\permanent\protected\lettonothing\stopMPinclusions
130
131
132
133\permanent\tolerant\protected\def\MPinclusions[#1]#:#*#=#:#*#=
134 {\let\m_meta_saved_instance\currentMPinstance
135 \iftok{#1}{}\else
136 \global\t_meta_inclusions\emptytoks
137 \fi
138 \ifparameter#3\or
139 \cdef\currentMPinstance{#2}
140 \ifempty\currentMPinstance
141 \let\currentMPinstance\defaultMPinstance
142 \fi
143 \gtoksapp\t_meta_inclusions{#3}
144 \else
145 \let\currentMPinstance\defaultMPinstance
146 \gtoksapp\t_meta_inclusions{#2}
147 \fi
148 \let\currentMPinstance\m_meta_saved_instance}
149
150
151
152\installcommandhandler \??mpinstance {MPinstance} \??mpinstance
153
154\setupMPinstance
155 [\s!format=metafun,
156 \s!extensions=\v!no,
157 \s!initializations=\v!no,
158 \c!method=\s!default,
159 \c!textstyle=,
160 \c!textcolor=]
161
162\appendtoks
163 \ifcsname\??mpdefinitions\currentMPinstance\endcsname \else
164 \expandafter\newtoks\csname\??mpdefinitions\currentMPinstance\endcsname
165 \fi
166 \ifcsname\??mpinclusions\currentMPinstance\endcsname \else
167 \expandafter\newtoks\csname\??mpinclusions\currentMPinstance\endcsname
168 \fi
169 \t_meta_definitions\emptytoks
170 \t_meta_inclusions \emptytoks
171\to \everydefineMPinstance
172
173
174
175
176\def\meta_analyze_graphicname[#1]
177 {\normalexpanded{\meta_analyze_graphicname_indeed[#1::::]}}
178
179\def\meta_show_properties_indeed
180 {\writestatus{metapost}{name: \currentMPgraphicname, instance: \currentMPinstance, format: \currentMPformat}}
181
182\let\meta_show_properties\donothing
183
184\installtextracker
185 {metapost.properties}
186 {\let\meta_show_properties\meta_show_properties_indeed}
187 {\let\meta_show_properties\donothing}
188
189\protected\def\meta_analyze_graphicname_indeed[#1::#2::#3]
190 {\cdef\currentMPgraphicname{#2}
191 \ifempty\currentMPgraphicname
192 \cdef\currentMPgraphicname{#1}
193 \let\currentMPinstance\defaultMPinstance
194 \orelse\ifcsname\??mpdefinitions#1\endcsname
195 \cdef\currentMPinstance{#1}
196 \else
197 \let\currentMPinstance\defaultMPinstance
198 \fi
199 \cdef\currentMPformat{\MPinstanceparameter\s!format}
200 \meta_show_properties}
201
202\mutable\def\currentMPgraphicname{\s!unknown}
203\mutable\def\currentMPinstance {\defaultMPinstance}
204\mutable\def\currentMPformat {\currentMPinstance}
205
206\defineMPinstance[metafun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!double]
207\defineMPinstance[minifun] [\s!format=minifun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!double]
208\defineMPinstance[extrafun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!double]
209\defineMPinstance[lessfun] [\s!format=metafun]
210\defineMPinstance[scaledfun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!scaled]
211\defineMPinstance[doublefun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!double]
212\defineMPinstance[binaryfun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!binary]
213\defineMPinstance[decimalfun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!decimal]
214\defineMPinstance[positfun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!posit]
215
216\defineMPinstance[mprun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
217
218\defineMPinstance[metapost] [\s!format=mpost]
219\defineMPinstance[nofun] [\s!format=mpost]
220\defineMPinstance[scaledpost] [\s!format=mpost,\c!method=\s!scaled]
221\defineMPinstance[doublepost] [\s!format=mpost,\c!method=\s!double]
222\defineMPinstance[binarypost] [\s!format=mpost,\c!method=\s!binary]
223\defineMPinstance[decimalpost][\s!format=mpost,\c!method=\s!decimal]
224
225\defineMPinstance[simplefun] [\s!format=metafun,\c!method=\s!double]
226
227
228
229\newconditional\c_meta_include_initializations
230
231\def\meta_begin_graphic_group#1
232 {\begingroup
233 \meta_analyze_graphicname[#1]}
234
235\def\meta_end_graphic_group
236 {\endgroup}
237
238\mutable\def\MPaskedfigure{false}
239
240\def\meta_flush_current_initializations
241 {\ifconditional\c_meta_include_initializations
242 \the\t_meta_initializations
243 \fi}
244
245\def\meta_flush_current_inclusions
246 {\the\t_meta_inclusions}
247
248\def\meta_flush_current_definitions
249 {\the\t_meta_definitions}
250
251\def\meta_start_current_graphic
252 {\begingroup
253 \meta_enable_include
254 \expand\everyMPgraphic
255 \edef\p_initializations{\MPinstanceparameter\s!initializations}
256 \ifx\p_initializations\v!yes
257 \c_meta_include_initializations\conditionaltrue
258 \else
259 \c_meta_include_initializations\conditionalfalse
260 \fi
261 \edef\p_setups{\MPinstanceparameter\c!setups}
262 \ifempty\p_setups \else
263 \setups[\p_setups]
264 \fi
265 \useMPinstancestyleparameter\c!textstyle}
266
267\def\meta_set_current_color
268 {\useMPinstancecolorparameter\c!textcolor}
269
270\def\meta_stop_current_graphic
271 {\global\t_meta_definitions\emptytoks
272 \global\t_meta_inclusions\emptytoks
273 \endgroup}
274
275\let\meta_relocate_graphic\relax
276
277\def\meta_process_graphic_start
278 {\pushMPboundingbox
279 \setbox\b_meta_graphic\hpack\bgroup}
280
281\def\meta_process_graphic_stop
282 {\egroup
283 \meta_place_graphic
284 \meta_relocate_graphic
285 \popMPboundingbox}
286
287\protected\def\meta_process_graphic_instance#1#2
288 {\cdef\currentMPinstance{#1}
289 \ifempty\currentMPinstance
290 \let\currentMPinstance\defaultMPinstance
291 \fi
292 \setmpcategoryparameter\c!stacking{#2}
293 \cdef\currentMPformat{\MPinstanceparameter\s!format}
294 \meta_process_graphic}
295
296\protected\def\meta_process_graphic#1
297 {\meta_start_current_graphic
298 \forgetall
299 \meta_process_graphic_start
300 \normalexpanded{\noexpand\clf_mpgraphic
301 instance {\currentMPinstance}
302 format {\currentMPformat}
303 data {#1;}
304 initializations {\meta_flush_current_initializations}
305 \ifcstok{\MPinstanceparameter\s!extensions}\v!yes
306 extensions {\clf_getmpextensions{\currentMPinstance}}
307 \fi
308 inclusions {\meta_flush_current_inclusions}
309 definitions {\meta_flush_current_definitions}
310 figure {\MPaskedfigure}
311 filtering {\mpcategoryparameter\c!stacking}
312 method {\MPinstanceparameter\c!method}
313 namespace {\??graphicvariable\currentmpcategory:}
314 \relax}
315 \meta_process_graphic_stop
316 \meta_stop_current_graphic}
317
318\let\meta_process_graphic_figure_start\relax
319\let\meta_process_graphic_figure_stop \relax
320
321\let\normal_meta_process_graphic_start\relax
322\let\normal_meta_process_graphic_stop \relax
323
324\permanent\protected\def\processMPfigurefile#1
325 {\begingroup
326 \let\normal_meta_process_graphic_start\meta_process_graphic_start
327 \let\normal_meta_process_graphic_stop \meta_process_graphic_stop
328 \let\meta_process_graphic_start\relax
329 \let\meta_process_graphic_stop \relax
330 \def\meta_process_graphic_figure_start{\startTEXpage[\c!offset=\v!overlay,\c!align=]\normal_meta_process_graphic_start}
331 \def\meta_process_graphic_figure_stop {\normal_meta_process_graphic_stop\stopTEXpage}
332 \def\MPaskedfigure{all}
333 \meta_process_graphic{input "#1" ;}
334 \endgroup}
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358\permanent\def\includeMPgraphic#1
359 {\ifcsname\??mpgraphic#1\endcsname
360 \doubleexpandafter\fourthoffourarguments\lastnamedcs ;
361 \fi}
362
363\let\meta_enable_include\relax
364
365
366
367\newif\ifMPdrawingdone \MPdrawingdonefalse
368
369\permanent\protected\def\finalizeMPdrawing
370 {\MPdrawingdonetrue}
371
372\mutable\lettonothing\MPdrawingdata
373
374\permanent\protected\def\resetMPdrawing
375 {\glettonothing\MPdrawingdata
376 \global\MPdrawingdonefalse}
377
378\permanent\protected\def\pushMPdrawing
379 {\globalpushmacro\MPdrawingdata
380 \glettonothing\MPdrawingdata}
381
382\permanent\protected\def\popMPdrawing
383 {\globalpopmacro\MPdrawingdata}
384
385\permanent\protected\def\getMPdrawing
386 {\ifMPdrawingdone
387 \expandafter\meta_process_graphic\expandafter{\MPdrawingdata}
388 \fi}
389
390\permanent\tolerant\def\startMPdrawing[#1]
391 {\meta_start_drawing{#1}}
392
393\def\meta_start_drawing#1#2\stopMPdrawing
394 {\relax
395 \bgroup
396 \meta_enable_include
397
398 \iftok{#1}{}
399 \xdef\MPdrawingdata{\MPdrawingdata\detokenize{#2}}
400 \else
401 \xdef\MPdrawingdata{\MPdrawingdata#2}
402 \fi
403 \egroup}
404
405\permanent\protected\lettonothing\stopMPdrawing
406
407\permanent\def\MPdrawing#1
408 {\relax
409 \bgroup
410 \meta_enable_include
411 \xdef\MPdrawingdata{\MPdrawingdata#1}
412 \egroup}
413
414\permanent\protected\def\startMPclip#1#2\stopMPclip
415 {\gdefcsname\??mpclip#1\endcsname{#2}}
416
417\permanent\protected\lettonothing\stopMPclip
418
419\mutable\def\width {0 }
420\mutable\def\height{0 }
421
422\mutable\lettonothing\currentMPclip
423
424\protected\def\meta_grab_clip_path#1#2#3
425 {\begingroup
426 \d_overlay_width #2\relax
427 \d_overlay_height#3\relax
428 \edef\width {\the\d_overlay_width \space}
429 \edef\height{\the\d_overlay_height\space}
430 \cdef\currentMPclip{#1}
431 \ifcsname\??mpclip\currentMPclip\endcsname
432 \meta_grab_clip_path_yes
433 \else
434 \meta_grab_clip_path_nop
435 \fi
436 \endgroup}
437
438\def\meta_grab_clip_path_yes
439 {\meta_start_current_graphic
440 \normalexpanded{\noexpand\clf_mpsetclippath
441 instance {\currentMPinstance}
442 format {\currentMPformat}
443 data {\begincsname\??mpclip\currentMPclip\endcsname}
444 initializations {\meta_flush_current_initializations}
445 useextensions {\MPinstanceparameter\s!extensions}
446 inclusions {\meta_flush_current_inclusions}
447 method {\MPinstanceparameter\c!method}
448 width \d_overlay_width
449 height \d_overlay_height
450 \relax}
451 \meta_stop_current_graphic}
452
453\def\meta_grab_clip_path_nop
454 {\clf_mpsetclippath
455 width \d_overlay_width
456 height \d_overlay_height
457 \relax}
458
459
460
461
462\permanent\protected\def\MPfontsizehskip#1
463 {\dontleavehmode
464 \begingroup
465 \definedfont[#1]
466 \hskip\clf_currentdesignsize\scaledpoint\relax
467 \endgroup}
468
469\definefontsynonym[MetafunDefault][Regular*default]
470
471\startMPinitializations
472 defaultfont:="\truefontname{MetafunDefault}";
473
474
475\stopMPinitializations
476
477
478
479\startMPextensions
480 string contextversion;contextversion:="\contextversion";
481\stopMPextensions
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503\lettonothing\m_meta_current_variable
504
505\installbasicnativeautosetuphandler \??mpcategory {mpcategory}
506
507\permanent\tolerant\protected\def\useMPvariables[#1]#*[#2]{}
508
509
510
511\aliased\let\setupMPvariables\setupmpcategory
512\aliased\let\setMPvariables \setupmpcategory
513
514\def\meta_mpvar_default{\MPcolor{black}\space}
515
516
517\permanent\def\MPvar#1
518 {\beginlocalcontrol
519 \edef\m_meta_current_variable{\mpcategoryparameter{#1}}
520 \endlocalcontrol
521 \ifempty\m_meta_current_variable
522 \meta_mpvar_default
523 \orelse\ifchkdimension\m_meta_current_variable\or
524 \todimension\lastchkdimension\space\space
525
526 \orunless\ifempty{\ifchknum\m_meta_current_variable\or\tointeger\m_meta_current_variable\fi}
527 \tointeger\m_meta_current_variable\space\space
528 \orelse\ifcsname\??colorattribute\currentcolorprefix\m_meta_current_variable\endcsname
529 \MPcolor\m_meta_current_variable\space
530 \orelse\ifcsname\??colorattribute\m_meta_current_variable\endcsname
531 \MPcolor\m_meta_current_variable\space
532 \else
533 \m_meta_current_variable
534 \fi}
535
536\permanent\def\MPrawvar#1#2
537 {\beginlocalcontrol
538 \edef\m_meta_current_variable{\namedmpcategoryparameter{#1}{#2}}
539 \endlocalcontrol
540 \ifempty\m_meta_current_variable
541 \meta_mpvar_default
542 \orelse\ifchkdim\m_meta_current_variable\or
543 \todimension\m_meta_current_variable\space\space
544
545 \orunless\ifempty{\ifchknum\m_meta_current_variable\or\tointeger\m_meta_current_variable\fi}
546 \tointeger\m_meta_current_variable\space\space
547 \orelse\ifcsname\??colorattribute\currentcolorprefix\m_meta_current_variable\endcsname
548 \MPcolor\m_meta_current_variable\space
549 \orelse\ifcsname\??colorattribute\m_meta_current_variable\endcsname
550 \MPcolor\m_meta_current_variable\space
551 \else
552 \m_meta_current_variable
553 \fi}
554
555\aliased\let\MPvariable\MPvar
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578\permanent\def\overlaystamp
579 {\the\d_overlay_width :
580 \the\d_overlay_height :
581 \the\d_overlay_depth :
582 \the\d_overlay_offset :
583 \the\d_overlay_linewidth:
584 \MPcolor\overlaycolor :
585 \MPcolor\overlaylinecolor}
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603\newinteger\c_meta_object_counter
604\newbox \b_meta_graphic
605
606
607
608\protected\def\meta_obey_box_depth
609 {\setbox\b_meta_graphic\hpack\bgroup
610 \raise\MPlly\box\b_meta_graphic
611 \egroup}
612
613\protected\def\meta_ignore_box_depth
614 {\normalexpanded
615 {\meta_obey_box_depth
616 \wd\b_meta_graphic\the\wd\b_meta_graphic
617 \ht\b_meta_graphic\the\ht\b_meta_graphic
618 \dp\b_meta_graphic\the\dp\b_meta_graphic}}
619
620\protected\def\meta_obey_box_origin
621 {\setbox\b_meta_graphic\hpack\bgroup
622 \kern\MPllx\raise\MPlly\box\b_meta_graphic
623 \egroup}
624
625\permanent\protected\def\obeyMPboxdepth {\let\meta_relocate_box\meta_obey_box_depth}
626\permanent\protected\def\ignoreMPboxdepth{\let\meta_relocate_box\meta_ignore_box_depth}
627\permanent\protected\def\obeyMPboxorigin {\let\meta_relocate_box\meta_obey_box_origin}
628\permanent\protected\def\normalMPboxdepth{\let\meta_relocate_box\relax}
629
630\let\meta_relocate_box\relax
631
632\protected\def\meta_place_graphic
633 {\meta_relocate_box
634 \box\b_meta_graphic}
635
636
637
638
639
640\protected\def\meta_reuse_box#1#2#3#4#5
641 {\MPllx#2\MPlly#3\MPurx#4\MPury#5
642 \hpack container{\getobject{MP}{#1}}}
643
644\protected\def\meta_use_box
645 {\setunreferencedobject{MP}}
646
647\def\meta_handle_unique_graphic#1#2#3
648 {\begingroup
649
650 \extendMPoverlaystamp{#2}
651 \ifcsname\??mpgraphic\overlaystamp:#1\endcsname
652 \lastnamedcs
653 \else
654 \meta_enable_include
655 \global\advanceby\c_meta_object_counter\plusone
656 \meta_use_box{\the\c_meta_object_counter}\hpack{\meta_process_graphic{#3}}
657 \xdefcsname\??mpgraphic\overlaystamp:#1\endcsname{\meta_reuse_box{\the\c_meta_object_counter}{\the\MPllx}{\the\MPlly}{\the\MPurx}{\the\MPury}}
658 \csname\??mpgraphic\overlaystamp:#1\endcsname\empty
659 \fi
660 \endgroup}
661
662
663
664\permanent\protected\def\startuniqueMPgraphic
665 {\dodoublegroupempty\meta_start_unique_graphic}
666
667\permanent\protected\lettonothing\stopuniqueMPgraphic
668
669\def\meta_start_unique_graphic#1
670 {\normalexpanded{\meta_start_unique_graphic_indeed{#1}}}
671
672\permanent\protected\def\meta_start_unique_graphic_indeed#1#2#3\stopuniqueMPgraphic
673 {\gdefcsname\??mpgraphic#1\endcsname{\meta_handle_unique_graphic{#1}{#2}{#3}}}
674
675
676
677
678
679
680
681
682
683\permanent\tolerant\protected\def\uniqueMPgraphic
684 {\futureexpandis[\meta_uniquempgraphic_yes\meta_uniquempgraphic_nop}
685
686\def\meta_uniquempgraphic_yes[#1]#*#=
687 {
688 \resetdummyparameter\c!instance
689 \getdummyparameters[#1]
690 \cdef\currentMPinstance{\dummyparameter\c!instance}
691
692 \meta_begin_graphic_group{\ifempty\currentMPinstance\else\currentMPinstance::\fi#1}
693 \checkmpcategoryparent
694 \let\currentmpcategory\currentMPgraphicname
695 \setupcurrentmpcategory[#1]
696 \begincsname\??mpgraphic#2\endcsname\empty
697 \meta_end_graphic_group}
698
699\tolerant\def\meta_uniquempgraphic_nop#=#*#=
700 {\meta_begin_graphic_group{#1}
701 \checkmpcategoryparent
702 \let\currentmpcategory\currentMPgraphicname
703 \setupcurrentmpcategory[#2]
704 \begincsname\??mpgraphic#1\endcsname\empty
705 \meta_end_graphic_group}
706
707\def\meta_handle_use_graphic#1#2#3
708 {\begingroup
709
710 \meta_enable_include
711 \meta_process_graphic{#3}
712 \endgroup}
713
714\permanent\protected\def\startuseMPgraphic
715 {\dodoublegroupempty\meta_start_use_graphic}
716
717\permanent\protected\lettonothing\stopuseMPgraphic
718
719\def\meta_start_use_graphic#1
720 {\normalexpanded{\meta_start_use_graphic_indeed{#1}}}
721
722\protected\def\meta_start_use_graphic_indeed#1#2#3\stopuseMPgraphic
723 {\gdefcsname\??mpgraphic#1\endcsname{\meta_handle_use_graphic{#1}{#2}{#3}}}
724
725\permanent\protected\def\startusableMPgraphic
726 {\dodoublegroupempty\meta_start_usable_graphic}
727
728\permanent\protected\lettonothing\stopusableMPgraphic
729
730\def\meta_start_usable_graphic#1
731 {\normalexpanded{\meta_start_usable_graphic_indeed{#1}}}
732
733\protected\def\meta_start_usable_graphic_indeed#1#2#3\stopusableMPgraphic
734 {\gdefcsname\??mpgraphic#1\endcsname{\meta_handle_use_graphic{#1}{#2}{#3}}}
735
736\def\meta_handle_reusable_graphic#1#2#3
737 {\begingroup
738
739 \meta_enable_include
740 \global\advanceby\c_meta_object_counter\plusone
741 \meta_use_box{\the\c_meta_object_counter}\hpack{\meta_process_graphic{#3}}
742 \xdefcsname\??mpgraphic#1\endcsname{\meta_reuse_box{\the\c_meta_object_counter}{\the\MPllx}{\the\MPlly}{\the\MPurx}{\the\MPury}}
743 \csname\??mpgraphic#1\endcsname\empty
744 \endgroup}
745
746\permanent\protected\def\startreusableMPgraphic
747 {\dodoublegroupempty\meta_start_reusable_graphic}
748
749\permanent\protected\lettonothing\stopreusableMPgraphic
750
751\def\meta_start_reusable_graphic#1
752 {\normalexpanded{\meta_start_reusable_graphic_indeed{#1}}}
753
754\protected\def\meta_start_reusable_graphic_indeed#1#2#3\stopreusableMPgraphic
755 {\gdefcsname\??mpgraphic#1\endcsname{\meta_handle_reusable_graphic{#1}{#2}{#3}}}
756
757\permanent\tolerant\protected\def\useMPgraphic
758 {\futureexpandis[\meta_usempgraphic_yes\meta_usempgraphic_nop}
759
760\def\meta_usempgraphic_yes[#1]#*#=
761 {
762 \resetdummyparameter\c!instance
763 \getdummyparameters[#1]
764 \cdef\currentMPinstance{\dummyparameter\c!instance}
765
766 \meta_begin_graphic_group{\ifempty\currentMPinstance\else\currentMPinstance::\fi#2}
767 \ifcsname\??mpgraphic#2\endcsname
768 \cdef\currentmpcategory{#2}
769 \orelse\ifcsname\??mpgraphic\currentMPgraphicname\endcsname
770 \let\currentmpcategory\currentMPgraphicname
771 \else
772 \lettonothing\currentmpcategory
773 \fi
774 \ifempty\currentmpcategory
775
776 \else
777 \checkmpcategoryparent
778 \setupcurrentmpcategory[#1]
779 \csname\??mpgraphic\currentmpcategory\endcsname
780 \fi
781 \meta_end_graphic_group}
782
783\tolerant\def\meta_usempgraphic_nop#=#*#=
784 {\meta_begin_graphic_group{#1}
785 \ifcsname\??mpgraphic#1\endcsname
786 \cdef\currentmpcategory{#1}
787 \orelse\ifcsname\??mpgraphic\currentMPgraphicname\endcsname
788 \let\currentmpcategory\currentMPgraphicname
789 \else
790 \lettonothing\currentmpcategory
791 \fi
792 \ifempty\currentmpcategory
793
794 \else
795 \checkmpcategoryparent
796 \ifempty{#2}\else
797 \setupcurrentmpcategory[#2]
798 \fi
799 \csname\??mpgraphic\currentmpcategory\endcsname
800 \fi
801 \meta_end_graphic_group}
802
803\aliased\let\reuseMPgraphic \useMPgraphic
804\aliased\let\reusableMPgraphic\reuseMPgraphic
805
806
807
808\permanent\protected\def\startoverlayMPgraphic
809 {\dodoublegroupempty\meta_start_overlay_graphic}
810
811\permanent\protected\lettonothing\stopoverlayMPgraphic
812
813\def\meta_start_overlay_graphic#1
814 {\normalexpanded{
815 \pack_overlay_define{#1}{\useMPgraphic{#1}}
816 \meta_start_overlay_graphic_indeed{#1}}
817 }
818
819\protected\def\meta_start_overlay_graphic_indeed#1#2#3\stopoverlayMPgraphic
820 {\gdefcsname\??mpgraphic#1\endcsname{\meta_handle_overlay_graphic{#1}{#2}{#3}}}
821
822\def\meta_handle_overlay_graphic#1#2#3
823 {\begingroup
824 \cdef\currentmpcategory{#1}
825 \meta_process_graphic{#3;BoundToOverlayBox;}
826 \endgroup}
827
828
829
830\newtoks\MPoverlaydata
831
832\permanent\protected\lettonothing\stopMPoverlaydata
833
834\permanent\protected\def\startMPoverlaydata
835 {\iftrialtypesetting
836 \expandafter\startMPoverlaydata_nop
837 \else
838 \expandafter\startMPoverlaydata_yes
839 \fi}
840
841\permanent\protected\def\startMPoverlaydata_nop#\stopMPoverlaydata
842 {}
843
844\permanent\protected\def\startMPoverlaydata_yes#1\stopMPoverlaydata
845 {\xtoksapp\MPoverlaydata{#1;}}
846
847\def\includeMPoverlaydata
848 {\the\MPoverlaydata
849 \resetMPoverlaydata}
850
851\def\resetMPoverlaydata
852 {\localcontrolled{\global\MPoverlaydata\emptytoks}}
853
854
855
856
857
858
859
860\def\m_meta_page_prefix{\doifelseoddpage oe}
861
862\permanent\def\overlaypagestamp
863 {\m_meta_page_prefix :
864 \the\d_overlay_width :
865 \the\d_overlay_height :
866 \the\d_overlay_depth :
867 \the\d_overlay_offset :
868 \the\d_overlay_linewidth:
869 \MPcolor\overlaycolor :
870 \MPcolor\overlaylinecolor}
871
872\permanent\tolerant\protected\def\startuniqueMPpagegraphic
873 {\dodoublegroupempty\meta_start_unique_page_graphic}
874
875\permanent\protected\lettonothing\stopuniqueMPpagegraphic
876
877\def\meta_start_unique_page_graphic#1
878 {\normalexpanded{\meta_start_unique_page_graphic_indeed{#1}}}
879
880\protected\def\meta_start_unique_page_graphic_indeed#1#2#3\stopuniqueMPpagegraphic
881 {\gdefcsname\??mpgraphic o:#1\endcsname{\meta_handle_unique_graphic{o:#1}{#2}{#3}}
882 \gdefcsname\??mpgraphic e:#1\endcsname{\meta_handle_unique_graphic{e:#1}{#2}{#3}}}
883
884\permanent\tolerant\protected\def\uniqueMPpagegraphic#=#=
885 {\meta_begin_graphic_group{#1}
886 \enforced\let\overlaystamp\overlaypagestamp
887 \setupmpcategory[\m_meta_page_prefix:#1][#2]
888 \csname\??mpgraphic\m_meta_page_prefix:#1\endcsname\empty
889 \meta_end_graphic_group}
890
891\permanent\protected\def\extendMPoverlaystamp#1
892 {\processcommalist[#1]\meta_extend_overlay_stamp}
893
894\def\meta_extend_overlay_stamp#1
895 {\enforced\permanent\edef\overlaystamp{\overlaystamp:\MPvariable{#1}}}
896
897
898
899
900
901
902
903
904
905\permanent\tolerant\protected\def\processMPbuffer[#1]
906 {\meta_begin_graphic_group{#1}
907 \meta_process_graphic{\clf_feedback{\currentMPgraphicname}}
908 \meta_end_graphic_group}
909
910\permanent\tolerant\protected\def\runMPbuffer[#1]
911 {\startnointerference\processMPbuffer[#1]\stopnointerference}
912
913
914
915
916
917
918
919\permanent\protected\def\startMPenvironment
920 {\begingroup
921 \catcode\endoflineasciicode\ignorecatcode
922 \meta_start_environment}
923
924\tolerant\def\meta_start_environment[#1]#:#2\stopMPenvironment
925 {\endgroup
926 \edef\m_meta_option{#1}
927 \ifx\m_meta_option\s!reset
928 \resetMPenvironment
929 \orelse\ifx\m_meta_option\v!global
930 #2
931 \orelse\ifx\m_meta_option\!!plustoken
932 #2
933 \fi
934 \clf_mptexset{\detokenize{#2}}}
935
936\permanent\protected\lettonothing\stopMPenvironment
937
938\permanent\protected\def\resetMPenvironment
939 {\clf_mptexreset}
940
941\permanent\protected\def\useMPenvironmentbuffer[#1]
942 {\clf_mptexsetfrombuffer{#1}}
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970\permanent\tolerant\protected\def\startMPcode
971 {\futureexpandis[\meta_start_mpcode_yes\meta_start_mpcode_nop}
972
973\tolerant\def\meta_start_mpcode_nop#:#=#:#2\stopMPcode
974 {\begingroup
975 \cdef\currentMPinstance{#1}
976 \ifempty\currentMPinstance
977 \let\currentMPinstance\defaultMPinstance
978 \fi
979 \lettonothing\currentMPgraphicname
980 \cdef\currentMPformat{\MPinstanceparameter\s!format}
981 \meta_enable_include
982 \meta_process_graphic{#2}
983 \endgroup}
984
985\def\meta_start_mpcode_yes[#1]#2\stopMPcode
986 {\begingroup
987 \resetdummyparameter\c!instance
988 \resetdummyparameter\c!stacking
989 \getdummyparameters[#1]
990 \cdef\currentMPinstance{\dummyparameter\c!instance}
991 \setmpcategoryparameter\c!stacking{\dummyparameter\c!stacking}
992 \ifempty\currentMPinstance
993 \let\currentMPinstance\defaultMPinstance
994 \fi
995 \lettonothing\currentMPgraphicname
996 \cdef\currentMPformat{\MPinstanceparameter\s!format}
997 \meta_enable_include
998 \meta_process_graphic{#2}
999 \endgroup}
1000
1001\permanent\protected\lettonothing\stopMPcode
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011\permanent\tolerant\protected\def\MPcode[#1]#:#2
1012 {\dontleavehmode
1013 \begingroup
1014 \obeyMPboxdepth
1015 \ifparameter#1\or
1016 \meta_begin_graphic_group{#1}
1017 \meta_enable_include
1018 \meta_process_graphic{#2}
1019 \meta_end_graphic_group
1020 \else
1021 \let\currentMPinstance\defaultMPinstance
1022 \meta_enable_include
1023 \meta_process_graphic{#2}
1024 \fi
1025 \endgroup}
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035\mutable\let\MPruninstance\defaultMPinstance
1036
1037\permanent\protected\def\useMPrun#1#2
1038 {\begingroup
1039 \def\MPaskedfigure{#2}
1040 \normalexpanded{\useMPgraphic{\ifempty{#1}mprun\else#1\fi}}
1041 \endgroup}
1042
1043\permanent\tolerant\protected\def\startMPrun#=#:#2\stopMPrun
1044 {\normalexpanded{\startuseMPgraphic{\ifempty{#1}mprun\else#1\fi}}#2\stopuseMPgraphic}
1045
1046\permanent\protected\lettonothing\stopMPrun
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084\installcorenamespace{mptext}
1085
1086\permanent\protected\def\setMPtext#1#2{\edefcsname\??mptext#1\endcsname{\detokenize{#2}}}
1087\permanent \def\MPtext #1{\begincsname\??mptext#1\endcsname\empty}
1088\permanent \def\MPstring #1{"\begincsname\??mptext#1\endcsname\empty"}
1089\permanent \def\MPbetex #1{btex \begincsname\??mptext#1\endcsname\space etex}
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108\appendtoks
1109 \disablediscretionaries
1110
1111
1112 \baselineskip1\baselineskip
1113 \lineheight 1\lineheight
1114 \topskip 1\topskip
1115
1116 \enforced\let\#\letterhash
1117 \enforced\let\_\letterunderscore
1118 \enforced\let\&\letterampersand
1119 \enforced\let\{\letteropenbrace
1120 \enforced\let\}\letterclosebrace
1121\to \everyMPgraphic
1122
1123\newtoks\everyinsertMPfile
1124
1125\startMPextensions
1126 def initialize_form_numbers =
1127 do_initialize_numbers;
1128 enddef;
1129\stopMPextensions
1130
1131\startMPextensions
1132 vardef ForegroundBox =
1133 unitsquare xysized(HSize,VSize)
1134 enddef ;
1135\stopMPextensions
1136
1137\startMPdefinitions {metapost}
1138 if unknown context_bare : input mpbare.mpiv ; fi ;
1139\stopMPdefinitions
1140\startMPdefinitions {binarypost}
1141 if unknown context_bare : input mpbare.mpiv ; fi ;
1142\stopMPdefinitions
1143\startMPdefinitions {decimalpost}
1144 if unknown context_bare : input mpbare.mpiv ; fi ;
1145\stopMPdefinitions
1146\startMPdefinitions {doublepost}
1147 if unknown context_bare : input mpbare.mpiv ; fi ;
1148\stopMPdefinitions
1149
1150
1151
1152
1153
1154
1155
1156
1157\appendtoks
1158 \externalfigurepostprocessors\emptytoks
1159\to \everyinsertMPfile
1160
1161
1162
1163
1164
1165
1166\permanent\def\doifelseMPgraphic#1
1167 {\ifcsname\??mpgraphic #1\endcsname\expandafter\firstoftwoarguments \orelse
1168 \ifcsname\??mpgraphic o:#1\endcsname\expandafter\firstoftwoarguments \orelse
1169 \ifcsname\??mpgraphic e:#1\endcsname\expandafter\firstoftwoarguments \else
1170 \expandafter\secondoftwoarguments\fi}
1171
1172\aliased\let\doifMPgraphicelse\doifelseMPgraphic
1173
1174
1175
1176\definelayerpreset
1177 [mp]
1178 [\c!y=\MPury,
1179 \c!x=\MPllx,
1180 \c!method=\v!fit]
1181
1182\definelayer
1183 [mp]
1184 [\c!preset=mp]
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246\permanent\protected\def\startstaticMPfigure#1#2\stopstaticMPfigure
1247 {\startreusableMPgraphic{\??mpstaticgraphic#1}#2\stopreusableMPgraphic}
1248
1249\permanent\tolerant\protected\def\startstaticMPgraphic#=#:#=#:#3\stopstaticMPgraphic
1250 {\startreusableMPgraphic{\??mpstaticgraphic#1}{#2}#3\stopreusableMPgraphic}
1251
1252\permanent\protected\lettonothing\stopstaticMPfigure
1253\permanent\protected\lettonothing\stopstaticMPgraphic
1254
1255\permanent\tolerant\protected\def\usestaticMPfigure[#1]#*[#2]
1256 {\ifarguments\or
1257 \reuseMPgraphic{\??mpstaticgraphic#1}
1258 \else
1259 \scale[#2]{\reuseMPgraphic{\??mpstaticgraphic#1}}
1260 \fi}
1261
1262
1263
1264
1265\permanent\def\MPdivten[#1]{\toscaled\dimexpr#1pt10\relax}
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301\newconstant\MPcolormethod
1302
1303\appendtoks
1304 \clf_mpsetoutercolor
1305 \MPcolormethod\space
1306 \c_attr_colormodel\space
1307 \c_attr_color\space
1308 \dogetattribute{transparency}\relax
1309\to \everyMPgraphic
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339\permanent\def\MPrunvar #1{\clf_mprunvar{#1}} \aliased\let\mprunvar\MPrunvar
1340\permanent\def\MPruntab#1#2{\clf_mpruntab{#1}#2\relax} \aliased\let\mpruntab\MPruntab
1341\permanent\def\MPrunset#1#2{\clf_mprunset{#1}{#2}} \aliased\let\mprunset\MPrunset
1342
1343
1344
1345
1346\tokspre\everybeforepagebody{\clf_mppushvariables}
1347\toksapp\everyafterpagebody {\clf_mppopvariables }
1348
1349\aliased\let\MPpushvariables\clf_mppushvariables
1350\aliased\let\MPpopvariables \clf_mppopvariables
1351
1352
1353
1354\permanent\tolerant\protected\def\startMPcalculation#=#:#2\stopMPcalculation
1355 {\begingroup
1356 \setbox\nextbox\hpack\bgroup
1357 \cdef\currentMPinstance{#1}
1358 \ifempty\currentMPinstance
1359 \let\currentMPinstance\defaultMPinstance
1360 \fi
1361 \lettonothing\currentMPgraphicname
1362 \cdef\currentMPformat{\MPinstanceparameter\s!format}
1363 \meta_enable_include
1364 \meta_process_graphic{#2;draw origin}
1365 \egroup
1366 \endgroup}
1367
1368\permanent\protected\lettonothing\stopMPcalculation
1369
1370
1371
1372
1373
1374
1375\installcorenamespace{MPgraphics}
1376
1377\installsetuponlycommandhandler \??MPgraphics {MPgraphics}
1378
1379
1380
1381
1382
1383\appendtoks
1384 \MPcolormethod\ifcstok{\directMPgraphicsparameter\c!color}\v!global\plusone\else\zerocount\fi
1385\to \everysetupMPgraphics
1386
1387\setupMPgraphics
1388 [\c!color=\v!local]
1389
1390
1391
1392\permanent\def\MPdpar#1#2{\todimension{#1#2}\relaxedspace}
1393\permanent\def\MPnpar#1#2{\todimension{#1#2}\relaxedspace}
1394\permanent\def\MPspar#1#2{"#1#2"}
1395
1396
1397
1398\protect \endinput
1399 |