summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mlib-pdf.mkiv
blob: 8506b3b15e63f29a8f3ea96fb6929c86a0262b63 (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
%D \module
%D   [       file=mlib-pdf,
%D        version=2008.03.25,
%D          title=\METAPOST\ Integrated Graphics,
%D       subtitle=Conversion to PDF,
%D         author=Hans Hagen,
%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

\registerctxluafile{mlib-pdf}{1.001}

\def\MPLIBtoPDF#1{\ctxlua{metapost.flushliteral(#1)}}

\def\MPLIBboundingbox#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}}

\def\startMPLIBtoPDF#1#2#3#4% watch the transparency reset
  {\dostarttagged\t!mpgraphic\empty
   \naturalhbox attr \imageattribute 1 \bgroup
   \doactivatecolor\s!black\forcecolorhack
   \MPLIBboundingbox{#1}{#2}{#3}{#4}%
  %\forgetall % done already elsewhere
   \setbox\scratchbox\vbox\bgroup
   \noindent % this is really needed in order to force tex into proper cm's
   \startMPresources}

\def\stopMPLIBtoPDF % watch the transparency reset
  {%\dohandleMPresettransparency % not needed
   \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
   \dostoptagged}

% \def\MPLIBtextext#1#2#3#4#5%
%   {\begingroup
%    \def\MPtextdata{#3}% delegate the splitter to lua
%    \defconvertedcommand\MPtextdata\MPtextdata % no edef
%    \splitstring\MPtextdata\at::::\to\MPtexttag\and\MPtextnumber
%    \executeifdefined{handleMPtext\MPtexttag}
%      {\setbox\scratchbox\hbox
%         {\font\temp=#1\space at #2\onebasepoint
%          \let\c\char
%          \temp
%          \MPfshowcommand{#3}}%
%       \setbox\scratchbox\hbox
%         {\hskip#4\onebasepoint
%          \raise#5\onebasepoint
%          \box\scratchbox}%
%       \smashbox\scratchbox
%       \box\scratchbox}%
%    \endgroup}

\def\MPLIBtextext#1#2#3#4#5%
  {\begingroup
   \setbox\scratchbox\hbox
     {\font\temp=#1\space at #2\onebasepoint
      \let\c\char
      \temp
      #3}%
   \setbox\scratchbox\hbox
     {\hskip#4\onebasepoint
      \raise#5\onebasepoint
      \box\scratchbox}%
   \smashbox\scratchbox
   \box\scratchbox
   \endgroup}

\def\MPLIBflushreset
  {\ctxlua{metapost.flushreset()}}

\protect \endinput