mlib-pdf.mkxl /size: 4878 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=mlib-pdf,
3
%D version=2008.03.25,
4
%D title=\METAPOST\ Integrated Graphics,
5
%D subtitle=Conversion to PDF,
6
%D author=Hans Hagen,
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
\unprotect
15 16
%D We use bit more code that needed because we want to limit the amount of boxing.
17 18
\registerctxluafile
{
mlib
-
pdf
}{}
19 20
%D Some code is shared between MPLIB and MPS. The following variables are also
21
%D available for introspection and other purposes.
22 23
\ifdefined
\MPwidth
\else
\newdimen
\MPwidth
\fi
24
\ifdefined
\MPheight
\else
\newdimen
\MPheight
\fi
25 26
\ifdefined
\MPllx
\else
\newdimen
\MPllx
\fi
27
\ifdefined
\MPlly
\else
\newdimen
\MPlly
\fi
28
\ifdefined
\MPurx
\else
\newdimen
\MPurx
\fi
29
\ifdefined
\MPury
\else
\newdimen
\MPury
\fi
30 31
\ifdefined
\MPbox
\else
\newbox
\MPbox
\fi
32 33
\unexpanded
\def
\setMPboundingbox
#
1
#
2
#
3
#
4
% at some point we might pass them as base or scaled points
34
{
\global
\MPllx
#
1
\onebasepoint
35
\global
\MPlly
#
2
\onebasepoint
36
\global
\MPurx
#
3
\onebasepoint
37
\global
\MPury
#
4
\onebasepoint
38
\global
\MPwidth
\dimexpr
\MPurx
-
\MPllx
\relax
39
\global
\MPheight
\dimexpr
\MPury
-
\MPlly
\relax
}
40 41
\unexpanded
\def
\resetMPboundingbox
42
{
\global
\MPwidth
\zeropoint
43
\global
\MPheight
\zeropoint
44
\global
\MPllx
\zeropoint
45
\global
\MPlly
\zeropoint
46
\global
\MPurx
\zeropoint
47
\global
\MPury
\zeropoint
}
48 49
\let
\popMPboundingbox
\relax
50 51
\unexpanded
\def
\pushMPboundingbox
52
{
\edef
\popMPboundingbox
53
{
\global
\MPwidth
\the
\MPwidth
54
\global
\MPheight
\the
\MPheight
55
\global
\MPllx
\the
\MPllx
56
\global
\MPlly
\the
\MPlly
57
\global
\MPurx
\the
\MPurx
58
\global
\MPury
\the
\MPury
59
\relax
}}
60 61
% we need to combine these
62 63
\unexpanded
\def
\repositionMPboxindeed
64
{
\setbox
\MPbox
\hpack
\bgroup
65
\kern
-
\MPllx
66
\raise
-
\MPlly
67
\box
\MPbox
68
\egroup
}
69 70
\unexpanded
\def
\repositionMPbox
71
{
\ifzeropt
\MPllx
72
\ifzeropt
\MPlly
73
% okay
74
\else
75
\repositionMPboxindeed
76
\fi
77
\else
78
\repositionMPboxindeed
79
\fi
}
80 81
\unexpanded
\def
\finalizeMPbox
82
{
\repositionMPbox
83
\setbox
\MPbox
\vpack
to
\MPheight
\bgroup
84
\vfill
85
\hsize
\MPwidth
86
\smashbox
\MPbox
87
\box
\MPbox
88
\egroup
89
\wd
\MPbox
\MPwidth
90
\ht
\MPbox
\MPheight
}
91 92
% combined
93 94
\unexpanded
\def
\finalizeMPbox
95
{
\boxxoffset
\MPbox
-
\MPllx
\relax
96
\boxyoffset
\MPbox
\dimexpr\boxyoffset
\MPbox
-
\MPheight
-
\MPlly
\relax
97
\wd
\MPbox
\MPwidth
98
\ht
\MPbox
\MPheight
}
99 100
% MPLIB specific:
101 102
\def
\MPLIBtoPDF
{
\clf_mpflushliteral
}
% expanded
103 104
\unexpanded
\def
\startMPLIBtoPDF
#
1
#
2
#
3
#
4
%
105
{
\meta_process_graphic_figure_start
106
\dostarttagged
\t!mpgraphic
\empty
107
\naturalhpack
attr
\imageattribute
\plusone
\bgroup
108
\dousecolorparameter
\s!black
\forcecolorhack
109
\setMPboundingbox
{
#
1
}{
#
2
}{
#
3
}{
#
4
}
%
110
\setbox
\MPbox
\vpack
\bgroup
111
% \forgetall % already done elsewhere
112
\noindent
}
% forces the proper cm in the backend
113 114
\unexpanded
\def
\stopMPLIBtoPDF
115
{
\egroup
116
\finalizeMPbox
117
\box
\MPbox
118
\egroup
119
\dostoptagged
120
\meta_process_graphic_figure_stop
}
121 122
\def
\MPLIBflushreset
% This can (will) move to the Lua end.
123
{
\clf_mpflushreset
}
124 125
%D Kind of special:
126
%
127
% test.mp:
128
%
129
% beginfig(1) fill fullcircle scaled 10cm withcolor red ; endfig ;
130
% beginfig(2) draw fullcircle scaled 5cm withcolor blue ; endfig ;
131
% beginfig(3) draw textext("just some text") ; endfig ;
132
%
133
% standalone pages:
134
%
135
% \starttext
136
% \directMPgraphic{input "test.mp" ;}
137
% \stoptext
138 139
\let
\normalstartMPLIBtoPDF
\startMPLIBtoPDF
140
\let
\normalstopMPLIBtoPDF
\stopMPLIBtoPDF
141 142
\unexpanded
\def
\directstartMPLIBtoPDF
{
\startTEXpage
\normalstartMPLIBtoPDF
}
143
\unexpanded
\def
\directstopMPLIBtoPDF
{
\normalstopMPLIBtoPDF
\stopTEXpage
}
144 145
\unexpanded
\def
\directMPgraphic
146
{
\dodoublegroupempty
\mlib_direct_graphic
}
147 148
\def
\mlib_direct_graphic
#
1
#
2
% makes pages (todo: make boxes)
149
{
\meta_begin_graphic_group
{
#
1
}
%
150
\let
\startMPLIBtoPDF
\directstartMPLIBtoPDF
151
\let
\stopMPLIBtoPDF
\directstopMPLIBtoPDF
152
\meta_start_current_graphic
153
\forgetall
154
\edef
\p_extensions
{
\MPinstanceparameter
\s!extensions
}
%
155
\normalexpanded
{
\noexpand
\clf_mpgraphic
156
instance
{
\currentMPinstance
}
%
157
format
{
\currentMPformat
}
%
158
data
{
#
2
;
}
%
159
initializations
{
\meta_flush_current_initializations
}
%
160
\ifx
\p_extensions
\v!yes
161
extensions
{
\clf_getmpextensions
{
\currentMPinstance
}}
%
162
\fi
163
inclusions
{
\meta_flush_current_inclusions
}
%
164
definitions
{
\meta_flush_current_definitions
}
%
165
figure
{
all
}
%
166
method
{
\MPinstanceparameter
\c!method
}
%
167
\relax
}
%
168
\meta_stop_current_graphic
169
\meta_end_graphic_group
}
170 171
\protect
\endinput
172