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