meta-pdf.mkxl /size: 3860 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=meta-pdf,
3%D        version=2006.06.07,
4%D          title=\METAPOST\ Graphics,
5%D       subtitle=Conversion to \PDF,
6%D         author=Hans Hagen \& others (see text),
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\registerctxluafile{meta-pdf}{}
15
16\writestatus{loading}{MetaPost Graphics / MPS to PDF}
17
18\unprotect
19
20%D \macros
21%D   {convertMPtoPDF}
22%D
23%D The next set of macros implements \METAPOST\ to \PDF\ conversion. The traditional
24%D method is in the MkII files and the older \MKIV\ method is kept in meta-pdh
25%D files. The main conversion command is still the same but the scale parameters are
26%D ignored in \MKIV:
27%D
28%D \starttyping
29%D \convertMPtoPDF {filename} {x scale} {y scale}
30%D \stoptyping
31%D
32%D Much code has gone due to the fact that we now use pre and post scripts and no
33%D specials. This also means that you should use a modern \METAPOST\ or reprocess
34%D graphics. The color control flags are also gone as we now integrate into the
35%D regular colorspace handling (i.e.\ no longer independent configurations.)
36
37\mutable\lettonothing\MPfilename
38
39\permanent\protected\def\convertMPtoPDF#1#2#3% scaling no longer supported at this level (so #2 & #3 are ignored)
40  {\dostarttagged\t!mpgraphic\empty
41   \naturalvpack attr \imageattribute 1 \bgroup
42     \message{[MP to PDF]}%
43     \xdef\MPfilename{#1}%
44     \resetMPboundingbox
45     \forgetall
46     \offinterlineskip
47     \setbox\MPbox\vpack\bgroup
48       \clf_convertmpstopdf{\MPfilename}%
49       \removeunwantedspaces % not that needed
50     \egroup
51     \finalizeMPbox
52     \box\MPbox
53   \egroup
54   \dostoptagged}
55
56\protect \endinput
57
58%D Test code:
59%D
60%D \startbuffer
61%D \startMPcode
62%D     fill fullcircle scaled 3cm withcolor red ;
63%D     fill fullcircle scaled 2cm withcolor green ;
64%D     fill fullcircle scaled 1cm withcolor blue ;
65%D     currentpicture := currentpicture shifted (-4cm,0) ;
66%D     fill fullcircle scaled 3cm withcolor cmyk(0,0,1,0) ;
67%D     fill fullcircle scaled 2cm withcolor cmyk(0,1,0,0) ;
68%D     fill fullcircle scaled 1cm withcolor cmyk(0,0,1,0) ;
69%D     currentpicture := currentpicture shifted (-4cm,0) ;
70%D     draw fullcircle scaled 3cm dashed evenly ;
71%D     draw fullcircle scaled 2cm dashed withdots  ;
72%D     draw origin withpen pencircle scaled 3mm;
73%D     currentpicture := currentpicture shifted (-4cm,0) ;
74%D     fill fullcircle scaled 2cm shifted (-.5cm,+.5cm) withcolor transparent(1,.5,red);
75%D     fill fullcircle scaled 2cm shifted (-.5cm,-.5cm) withcolor transparent(1,.5,red);
76%D     fill fullcircle scaled 2cm shifted (+.5cm,+.5cm) withcolor transparent(1,.5,green);
77%D     fill fullcircle scaled 2cm shifted (+.5cm,-.5cm) withcolor transparent(1,.5,cmyk(1,0,1,.5));
78%D     currentpicture := currentpicture shifted (12cm,-4cm) ;
79%D     draw "o e p s" infont defaultfont scaled 2 shifted (-1cm,0) ;
80%D     currentpicture := currentpicture shifted (-4cm,0) ;
81%D     % bug: shift
82%D     draw fullcircle scaled 3cm withpen pencircle yscaled 3mm xscaled 2mm rotated 30  ;
83%D     draw fullcircle scaled 2cm withpen pencircle yscaled 3mm xscaled 2mm rotated 20 withcolor red ;
84%D     filldraw fullcircle scaled 1cm withpen pencircle yscaled 3mm xscaled 2mm rotated 10 withcolor green ;
85%D     currentpicture := currentpicture shifted (-4cm,0) ;
86%D     % shade cannot handle shift
87%D     circular_shade(fullcircle scaled 3cm,0,.2red,.9green) ;
88%D     circular_shade(fullcircle scaled 3cm shifted(+4cm,0),0,cmyk(1,0,0,0),cmyk(0,1,0,0)) ;
89%D     filldraw boundingbox currentpicture enlarged -3cm withpen pencircle scaled 1pt withcolor .5white ;
90%D \stopMPcode
91%D \stopbuffer
92%D
93%D \typebuffer \startlinecorrection \getbuffer \stoplinecorrection
94