summaryrefslogtreecommitdiff
path: root/tex/context/base/mlib-pps.mkiv
blob: a27eb56df7d74119615e1587813705d738fb422a (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
%D \module
%D   [       file=mlib-pps,
%D        version=2008.03.25,
%D          title=\METAPOST\ Integrated Graphics,
%D       subtitle=Basics,
%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-pps}{1.001}

%D Todo: catch nested graphics like external figures with dummies.

% \newtoks\everyMPLIBtext % not yet used

% \appendtoks
%     \let\handleuseMPgraphic     \thirdofthreearguments
%     \let\handlereusableMPgraphic\thirdofthreearguments
% \to \everyMPLIBtext

% this will move !

% Instead of preallocated boxes we now use a table of lists so that we
% have no limitation. Typically an example of a next version solution
% due to \LUATEX\ evolving.

\newbox \MPtextbox
\newtoks\everyMPLIBsettext

\def\MPLIBfigure#1#2#3#4#5#6#7% todo: move Q q to lua
  {\setbox\scratchbox\hbox{\externalfigure[#7]}%
   \ctxlua{metapost.edefsxsy(\number\wd\scratchbox,\number\ht\scratchbox,0)}%
   \pdfliteral direct{q #1 #2 #3 #4 #5 #6 cm}% no direct
   \vbox to \zeropoint{\vss\hbox to \zeropoint{\scale[sx=\sx,sy=\sy]{\box\scratchbox}\hss}}%
   \pdfliteral direct{Q}}

\def\MPLIBsettext#1% #2%
  {\dowithnextbox{\ctxlua{metapost.settext(\number\nextbox,#1)}}\hbox}

% \def\MPLIBgettextscaled#1#2#3%  why a copy
%   {\ctxlua{metapost.gettext(\number\MPtextbox,#1)}% \black has no use here (applied to box)
%    \vbox to \zeropoint{\vss\hbox to \zeropoint{\black\scale[sx=#2,sy=#3]{\raise\dp\MPtextbox\box\MPtextbox}\hss}}}

\def\MPLIBgettextscaled#1#2#3%  why a copy
  {\ctxlua{metapost.gettext(\number\MPtextbox,#1)}% we need the colorhack or else the color backend does not sync
   \vbox to \zeropoint{\vss\hbox to \zeropoint{\scale[\c!sx=#2,\c!sy=#3]{\raise\dp\MPtextbox\box\MPtextbox}\forcecolorhack\hss}}}

\def\MPLIBgraphictext#1%
  {\startTEXpage[\c!scale=10000]#1\stopTEXpage}

\protect \endinput

% \def\MPLIBsettext#1% #2% we could as well store in hlists at the lua end i.e. just one box
% {\global\setbox#1\hbox}
%
% \def\MPLIBfreetext#1%
%   {\global\setbox#1\emptybox}
%
% \def\MPLIBgettextscaled#1#2#3%  why a copy
%   {\vbox to \zeropoint{\vss\hbox to \zeropoint{\black\scale[sx=#2,sy=#3]{\raise\dp#1\copy#1}\hss}}}
%
% \def\MPLIBallocate#1%
%   {\newbox\MPLIBfirst
%    \dorecurse{\numexpr#1-1\relax}{\let\MPLIBlast\relax\newbox\MPLIBlast}%
%    \MPLIBregister}
%
% \def\MPLIBregister % after allocate!
%   {\ctxlua{metapost.first_box, metapost.last_box = \number\MPLIBfirst, \number\MPLIBlast}}