summaryrefslogtreecommitdiff
path: root/tex/context/base/meta-pdf.mkiv
blob: dadf760a6ca94ee16706d7e770192a85e6045471 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
%D \module
%D   [       file=meta-pdf,
%D        version=2006.29.09,
%D          title=\CONTEXT\ Support Macros,
%D       subtitle=\METAPOST\ to \PDF\ conversion,
%D         author=Hans Hagen \& others (see text),
%D           date=\currentdate,
%D      copyright=\PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\unprotect

% Using test case at end of meta-pdf.tex:
%
% \useMPgraphic{1}
% \testfeatureonce{250}{\setbox0\hbox{\convertMPtoPDF{test-mps-mpgraph.1}{1}{1}}}
%
%  8.4 : mkii, direct parsing by tex
% 11.8 : mkiv, dirty conversion (10.8 with dirty tricks)
% 14.5 : mkiv, clean conversion
%  7.4 : mkiv, simulated clean direct lua from mp
%  0.3 : time taken by tex to handle converted code

% Maybe delayed load, only at first call of the converter.

\registerctxluafile{meta-pdf}{1.003}

%D Plugin.

\def\mkconvertMPtoPDF
  {\vbox\bgroup
     \forgetall
     \offinterlineskip
    %\ifcase\blackoutMPgraphic\or\PDFcode{0 g 0 G}\fi % fixed in mp
     \setbox\scratchbox\vbox\bgroup
        \setnormalcatcodes % we can be in verbatim or so
        \message{[MP to PDF]}%
        \startMPresources
        \PDFcomment{mps begin}%
        \PDFcode{q 1 0 0 1 0 0 cm}%
        \ctxlua{mptopdf.convertmpstopdf("\MPfilename")}\removeunwantedspaces
        \PDFcode{Q}%
        \PDFcomment{mps end}%
        \stopMPresources
     \egroup
     \setbox\scratchbox\hbox\bgroup
        \hskip-\MPllx\onebasepoint
        \raise-\MPlly\onebasepoint
        \box\scratchbox
     \egroup
     \setbox\scratchbox\vbox to \MPheight\bgroup
       \vfill
       \hsize\MPwidth
       \smashbox\scratchbox
       \box\scratchbox
     \egroup
     \wd\scratchbox\MPwidth
     \ht\scratchbox\MPheight
     \dopackageMPgraphic\scratchbox
   \egroup}

\let\mkprocessMPtoPDFfile\mkconvertMPtoPDF

% \def\TEXcode#1#2#3#4#5%
%   {\setbox\scratchbox\hbox
%      {\font\temp=#1\space at #2\onebasepoint
%       \temp
%       \MPfshowcommand{#3}}%
%    \setbox\scratchbox\hbox
%      {\hskip#4\onebasepoint
%       \raise#5\onebasepoint
%       \box\scratchbox}%
%    \smashbox\scratchbox
%    \box\scratchbox}

% will be done better

\def\MPStextext#1#2#3#4#5% if we clean up this plugin model, we can
  {\def\MPtextdata{#3}%   % delegate the splitter to lua
   \def\MPtextsize{#2}%
   \def\lastMPmoveX{#4}%
   \def\lastMPmoveY{#5}%
   \convertcommand\MPtextdata\to\MPtextdata
   \splitstring\MPtextdata\at::::\to\MPtexttag\and\MPtextnumber
   \executeifdefined{handleMPtext\MPtexttag}
     {\setbox\scratchbox\hbox
        {\font\temp=#1\space at #2\onebasepoint
         \temp
         \MPfshowcommand{#3}}%
      \setbox\scratchbox\hbox
        {\hskip#4\onebasepoint
         \raise#5\onebasepoint
         \box\scratchbox}%
      \smashbox\scratchbox
      \box\scratchbox}}

%D We save the special variables on a stack. It's not that
%D fast, but it make implementing the special more convenient.

\def\MPSbegin
  {\nofMParguments\zerocount}

\def\MPSend
  {\csname\MPspecial\endcsname}

\def\MPSset
  {\advance\nofMParguments\plusone
   \expandafter\def\csname\@@MP\number\nofMParguments\endcsname}

\def\gMPs#1{\csname\@@MP\number#1\endcsname}

%D The boundingbox.

\def\MPSboundingbox#1#2#3#4%
  {\xdef\MPllx{#1}
   \xdef\MPlly{#2}
   \xdef\MPurx{#3}
   \xdef\MPury{#4}
   \xdef\MPwidth {\the\dimexpr#3\onebasepoint-#1\onebasepoint\relax}
   \xdef\MPheight{\the\dimexpr#4\onebasepoint-#2\onebasepoint\relax}}

\MPSboundingbox0000

\def\MPSspecial#1#2%
  {\csname\@@MPSK#2\endcsname}

%D A path is (in most cases) just a sequence of \PDF\ commands.

% \newcontitional\ignoreMPpath

\def\MPSpath
  {\PDFcode}

\def\MPScode % hack, will be improved
  {\ifconditional\ignoreMPpath
     \PDFcode{h W n}%
     \ifx\extraMPpathcode\empty\else
       \PDFcode{\extraMPpathcode}%
       \let\extraMPpathcode\empty
     \fi
     \setfalse\ignoreMPpath
     \expandafter\gobbleoneargument
   \else
     \expandafter\PDFcode
   \fi}

\let\MPSrgb \dohandleMPrgb
\let\MPScmyk\dohandleMPcmyk
\let\MPSgray\dohandleMPgray
\let\MPSspot\dohandleMPspot

\protect \endinput