summaryrefslogtreecommitdiff
path: root/tex/context/base/mlib-pps.mkiv
blob: 0dbdd3f6e6d640965ba0acc65dbfb06bc4d084a5 (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
%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 ADE \& \CONTEXT\ Development Team}]
%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%
  {\setbox\scratchbox\hbox{\externalfigure[#1][\c!mask=#2]}%
   \ctxlua{metapost.edefsxsy(\number\wd\scratchbox,\number\ht\scratchbox,0)}%
   \vbox to \zeropoint{\vss\hbox to \zeropoint{\scale[\c!sx=\sx,\c!sy=\sy]{\box\scratchbox}\hss}}}

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

\def\MPLIBgettextscaled#1#2#3%  why a copy .. can be used more often
  {\ctxlua{metapost.gettext(\number\MPtextbox,#1)}%
   \vbox to \zeropoint{\vss\hbox to \zeropoint{\scale[\c!sx=#2,\c!sy=#3]{\raise\dp\MPtextbox\box\MPtextbox}\forcecolorhack\hss}}}

% horrible:

\def\MPLIBgettextscaledcm#1#2#3#4#5#6#7#8#9% 2-7: sx,rx,ry,sy,tx,ty
  {\ctxlua{metapost.gettext(\number\MPtextbox,#1)}%
   \setbox\scratchbox\hbox
     {\dotransformnextbox{#2}{#3}{#4}{#5}{#6}{#7}% does push pop
        \vbox to \zeropoint
          {\vss
           \hbox to \zeropoint
             {\scale[\c!sx=#8,\c!sy=#9]{\raise\dp\MPtextbox\box\MPtextbox}%
              \forcecolorhack
              \hss}}}%
   \smashbox\scratchbox
   \box\scratchbox}

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

%D \startbuffer
%D \definelayer[test]
%D
%D \setlayerframed
%D   [test]
%D   [x=\MPx{somepos-1},y=\MPy{somepos-1}]
%D   [width=\MPw{somepos-1},height=\MPh{somepos-1}]
%D   {Whatever we want here!}
%D
%D \setlayerframed
%D   [test]
%D   [x=\MPx{somepos-2},y=\MPy{somepos-2}]
%D   [width=\MPw{somepos-2},height=\MPh{somepos-2}]
%D   {Whatever we need there!}
%D
%D \startuseMPgraphic{oeps}
%D     draw fullcircle scaled 6cm withcolor red ;
%D     register ("somepos-1",5cm,1cm,center currentpicture) ;
%D     register ("somepos-2",4cm,3cm,(-1cm,-2cm)) ;
%D \stopuseMPgraphic
%D
%D \framed[background=test,offset=overlay]{\useMPgraphic{oeps}}
%D \stopbuffer
%D
%D \typebuffer \startlinecorrection \getbuffer \stoplinecorrection

\def\MPLIBpositionwhd#1#2#3#4#5% bp !
  {\dosavepositionwhd{#1}{0}{#2bp}{#3bp}{#4bp}{#5bp}{0bp}}

\def\MPLIBextrapass#1%
  {\ctxlua{metapost.graphic_extra_pass("#1")}}

\def\MPLIBresettexts
  {\ctxlua{metapost.resettextexts()}}

\protect \endinput