meta-pdf.mkiv /size: 3918 b    last modification: 2020-07-01 14:35
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
24%D traditional method is in the MkII files and the older \MKIV\ method is
25%D kept in meta-pdh files. The main conversion command is still the same
26%D but the scale parameters are 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
33%D and no specials. This also means that you should use a modern \METAPOST\
34%D or reprocess graphics. The color control flags are also gone as we now
35%D integrate into the regular colorspace handling (i.e.\ no longer independent
36%D configurations.)
37
38\def\PDFMPformoffset{\ifdefined\objectoffset\objectoffset\else\zeropoint\fi} % obsolete, will go
39
40\unexpanded\def\convertMPtoPDF#1#2#3% scaling no longer supported at this level (so #2 & #3 are ignored)
41  {\dostarttagged\t!mpgraphic\empty
42   \naturalvpack attr \imageattribute 1 \bgroup
43     \message{[MP to PDF]}%
44     \xdef\MPfilename{#1}%
45     \resetMPboundingbox
46     \forgetall
47     \offinterlineskip
48     \setbox\MPbox\vpack\bgroup
49       \clf_convertmpstopdf{\MPfilename}%
50       \removeunwantedspaces % not that needed
51     \egroup
52     \finalizeMPbox
53     \box\MPbox
54   \egroup
55   \dostoptagged}
56
57\protect \endinput
58
59%D Test code:
60%D
61%D \startbuffer
62%D \startMPcode
63%D     fill fullcircle scaled 3cm withcolor red ;
64%D     fill fullcircle scaled 2cm withcolor green ;
65%D     fill fullcircle scaled 1cm withcolor blue ;
66%D     currentpicture := currentpicture shifted (-4cm,0) ;
67%D     fill fullcircle scaled 3cm withcolor cmyk(0,0,1,0) ;
68%D     fill fullcircle scaled 2cm withcolor cmyk(0,1,0,0) ;
69%D     fill fullcircle scaled 1cm withcolor cmyk(0,0,1,0) ;
70%D     currentpicture := currentpicture shifted (-4cm,0) ;
71%D     draw fullcircle scaled 3cm dashed evenly ;
72%D     draw fullcircle scaled 2cm dashed withdots  ;
73%D     draw origin withpen pencircle scaled 3mm;
74%D     currentpicture := currentpicture shifted (-4cm,0) ;
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,red);
77%D     fill fullcircle scaled 2cm shifted (+.5cm,+.5cm) withcolor transparent(1,.5,green);
78%D     fill fullcircle scaled 2cm shifted (+.5cm,-.5cm) withcolor transparent(1,.5,cmyk(1,0,1,.5));
79%D     currentpicture := currentpicture shifted (12cm,-4cm) ;
80%D     draw "o e p s" infont defaultfont scaled 2 shifted (-1cm,0) ;
81%D     currentpicture := currentpicture shifted (-4cm,0) ;
82%D     % bug: shift
83%D     draw fullcircle scaled 3cm withpen pencircle yscaled 3mm xscaled 2mm rotated 30  ;
84%D     draw fullcircle scaled 2cm withpen pencircle yscaled 3mm xscaled 2mm rotated 20 withcolor red ;
85%D     filldraw fullcircle scaled 1cm withpen pencircle yscaled 3mm xscaled 2mm rotated 10 withcolor green ;
86%D     currentpicture := currentpicture shifted (-4cm,0) ;
87%D     % shade cannot handle shift
88%D     circular_shade(fullcircle scaled 3cm,0,.2red,.9green) ;
89%D     circular_shade(fullcircle scaled 3cm shifted(+4cm,0),0,cmyk(1,0,0,0),cmyk(0,1,0,0)) ;
90%D     filldraw boundingbox currentpicture enlarged -3cm withpen pencircle scaled 1pt withcolor .5white ;
91%D \stopMPcode
92%D \stopbuffer
93%D
94%D \typebuffer \startlinecorrection \getbuffer \stoplinecorrection
95