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\def\setmplibformat#1{\def\mplibformat{#1}}
32\def\setmplibmode #1{\def\mplibmode {#1}}
33
34\def\setupmplibcatcodes
35 {\catcode\{=12
36 \catcode\}=12
37 \catcode\#=12
38 \catcode\^=12
39 \catcode\~=12
40 \catcode\_=12
41 \catcode\%=12
42 \catcode\&=12
43 \catcode\$=12
44 \obeylines}
45
46\def\mplibcode
47 {\bgroup
48 \setupmplibcatcodes
49 \domplibcode}
50
51\long\def\domplibcode#1\endmplibcode
52 {\egroup
53 \directlua{metapost.process('\mplibformat',[[#1]],'\mplibmode')}}
54
55
56
57\def\mplibformat{plain}
58\def\mplibmode {scaled}
59
60
61
62\ifx\mplibscratchbox\undefined \newbox\mplibscratchbox \fi
63
64
65
66\directlua{dofile(kpse.find_file('luatex-mplib.lua'))}
67
68
69
70
71\def\startMPLIBtoPDF#1#2#3#4
72 {\hbox\bgroup
73 \xdef\MPllx{#1}\xdef\MPlly{#2}
74 \xdef\MPurx{#3}\xdef\MPury{#4}
75 \xdef\MPwidth{\the\dimexpr#3bp#1bp\relax}
76 \xdef\MPheight{\the\dimexpr#4bp#2bp\relax}
77 \parskip0pt
78 \leftskip0pt
79 \parindent0pt
80 \everypar{}
81 \setbox\mplibscratchbox\vbox\bgroup
82 \noindent}
83
84\def\stopMPLIBtoPDF
85 {\egroup
86 \setbox\mplibscratchbox\hbox
87 {\hskip\MPllx bp
88 \raise\MPlly bp
89 \box\mplibscratchbox}
90 \setbox\mplibscratchbox\vbox to \MPheight
91 {\vfill
92 \hsize\MPwidth
93 \wd\mplibscratchbox0pt
94 \ht\mplibscratchbox0pt
95 \dp\mplibscratchbox0pt
96 \box\mplibscratchbox}
97 \wd\mplibscratchbox\MPwidth
98 \ht\mplibscratchbox\MPheight
99 \box\mplibscratchbox
100 \egroup}
101
102
103
104\ifnum\pdfoutput>0
105 \let\MPLIBtoPDF\pdfliteral
106\else
107 \def\MPLIBtoPDF#1{\special{pdf:literal direct #1}}
108\fi
109
110
111
112\def\MPLIBtextext#1#2#3#4
113 {\begingroup
114 \setbox\mplibscratchbox\hbox
115 {\font\temp=#1 at #2bp
116 \temp
117 #3}
118 \setbox\mplibscratchbox\hbox
119 {\raise#4sp
120 \box\mplibscratchbox}
121 \wd\mplibscratchbox0pt
122 \ht\mplibscratchbox0pt
123 \dp\mplibscratchbox0pt
124 \box\mplibscratchbox
125 \endgroup}
126
127\def\MPLIBpdftext#1#2
128 {\ifcsname mplib::#1\endcsname
129
130 \message{<reusing mplib: #1>}
131 \else
132 \message{<embedding mplib: #1>}
133 \immediate\pdfximage{#1}
134 \expandafter\edef\csname mplib::#1\endcsname{\the\pdflastximage}
135 \fi
136 \setbox\mplibscratchbox\hbox
137 {\raise#2sp\hbox{\pdfrefximage\csname mplib::#1\endcsname}}
138 \wd\mplibscratchbox0pt
139 \ht\mplibscratchbox0pt
140 \dp\mplibscratchbox0pt
141 \box\mplibscratchbox}
142
143\endinput
144 |