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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
%D \module
%D [ file=meta-pdf,
%D version=2006.06.07,
%D title=\METAPOST\ Graphics,
%D subtitle=Conversion to \PDF,
%D author=Hans Hagen \& others (see text),
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\registerctxluafile{meta-pdf}{1.003}
\writestatus{loading}{MetaPost Graphics / MPS to PDF}
\unprotect
%D \macros
%D {convertMPtoPDF}
%D
%D The next set of macros implements \METAPOST\ to \PDF\ conversion. The
%D traditional method is in the MkII files and the older \MKIV\ method is
%D kept in meta-pdh files. The main conversion command is still the same
%D but the scale parameters are ignored in \MKIV:
%D
%D \starttyping
%D \convertMPtoPDF {filename} {x scale} {y scale}
%D \stoptyping
%D
%D Much code has gone due to the fact that we now use pre and post scripts
%D and no specials. This also means that you should use a modern \METAPOST\
%D or reprocess graphics. The color control flags are also gone as we now
%D integrate into the regular colorspace handling (i.e.\ no longer independent
%D configurations.)
\def\PDFMPformoffset{\ifdefined\objectoffset\objectoffset\else\zeropoint\fi} % obsolete, will go
\unexpanded\def\convertMPtoPDF#1#2#3% scaling no longer supported at this level (so #2 & #3 are ignored)
{\dostarttagged\t!mpgraphic\empty
\naturalvbox attr \imageattribute 1 \bgroup
\message{[MP to PDF]}%
\xdef\MPfilename{#1}%
\resetMPboundingbox
\forgetall
\offinterlineskip
\setbox\MPbox\vbox\bgroup
\ctxlua{metapost.mptopdf.convertmpstopdf("\MPfilename")}%
\removeunwantedspaces % not that needed
\egroup
\finalizeMPbox
\box\MPbox
\egroup
\dostoptagged}
\protect \endinput
%D Test code:
%D
%D \startbuffer
%D \startMPcode
%D fill fullcircle scaled 3cm withcolor red ;
%D fill fullcircle scaled 2cm withcolor green ;
%D fill fullcircle scaled 1cm withcolor blue ;
%D currentpicture := currentpicture shifted (-4cm,0) ;
%D fill fullcircle scaled 3cm withcolor cmyk(0,0,1,0) ;
%D fill fullcircle scaled 2cm withcolor cmyk(0,1,0,0) ;
%D fill fullcircle scaled 1cm withcolor cmyk(0,0,1,0) ;
%D currentpicture := currentpicture shifted (-4cm,0) ;
%D draw fullcircle scaled 3cm dashed evenly ;
%D draw fullcircle scaled 2cm dashed withdots ;
%D draw origin withpen pencircle scaled 3mm;
%D currentpicture := currentpicture shifted (-4cm,0) ;
%D fill fullcircle scaled 2cm shifted (-.5cm,+.5cm) withcolor transparent(1,.5,red);
%D fill fullcircle scaled 2cm shifted (-.5cm,-.5cm) withcolor transparent(1,.5,red);
%D fill fullcircle scaled 2cm shifted (+.5cm,+.5cm) withcolor transparent(1,.5,green);
%D fill fullcircle scaled 2cm shifted (+.5cm,-.5cm) withcolor transparent(1,.5,cmyk(1,0,1,.5));
%D currentpicture := currentpicture shifted (12cm,-4cm) ;
%D draw "o e p s" infont defaultfont scaled 2 shifted (-1cm,0) ;
%D currentpicture := currentpicture shifted (-4cm,0) ;
%D % bug: shift
%D draw fullcircle scaled 3cm withpen pencircle yscaled 3mm xscaled 2mm rotated 30 ;
%D draw fullcircle scaled 2cm withpen pencircle yscaled 3mm xscaled 2mm rotated 20 withcolor red ;
%D filldraw fullcircle scaled 1cm withpen pencircle yscaled 3mm xscaled 2mm rotated 10 withcolor green ;
%D currentpicture := currentpicture shifted (-4cm,0) ;
%D % shade cannot handle shift
%D circular_shade(fullcircle scaled 3cm,0,.2red,.9green) ;
%D circular_shade(fullcircle scaled 3cm shifted(+4cm,0),0,cmyk(1,0,0,0),cmyk(0,1,0,0)) ;
%D filldraw boundingbox currentpicture enlarged -3cm withpen pencircle scaled 1pt withcolor .5white ;
%D \stopMPcode
%D \stopbuffer
%D
%D \typebuffer \startlinecorrection \getbuffer \stoplinecorrection
|