mlib-pps.mkiv /size: 7191 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=mlib-pps,
3
%D version=2008.03.25,
4
%D title=\METAPOST\ Integrated Graphics,
5
%D subtitle=Basics,
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
\registerctxluafile
{
mlib
-
pps
}{}
17 18
%D Todo: catch nested graphics like external figures with dummies.
19 20
% todo: figure out why this is shifted
21
%
22
% \setupbodyfont[palatino]
23
%
24
% \starttext
25
% \startMPpage
26
% draw textext("123") ;
27
% \stopMPpage
28
% \stoptext
29
%
30
% A slightly larger picture works ok so maybe there is some kind
31
% of interference with the page builder.
32 33
\newbox
\MPtextbox
34
\newtoks
\everyMPLIBsettext
% not used
35 36
\def
\doMPLIBflushenvironment
37
{
%\writestatus\m!metapost{flushing environment}%
38
\clf_mptexget
39
\let
\MPLIBflushenvironment
\relax
}
% MPenvironments are depricated}
40 41
\let
\MPLIBflushenvironment
\doMPLIBflushenvironment
42 43
\unexpanded
\def
\MPLIBsetNtext
#
1
% #2% box text
44
{
\MPLIBflushenvironment
45
\dowithnextbox
{
\clf_mpsettext
\nextbox
#
1
}
\hbox
\bgroup
% text
46
\meta_set_current_color
47
\let
\MPLIBflushenvironment
\doMPLIBflushenvironment
48
\let
\next
}
% gobble open brace
49 50
\unexpanded
\def
\MPLIBsetCtext
#
1
#
2
% #3% box colorspec text
51
{
\MPLIBflushenvironment
52
\dowithnextbox
{
\clf_mpsettext
\nextbox
#
1
}
\hbox
\bgroup
% text
53
\directcolored
[#
2
]
%
54
\meta_set_current_color
% so, textcolor wins !
55
\let
\MPLIBflushenvironment
\doMPLIBflushenvironment
56
\let
\next
}
% gobble open brace
57 58
\let
\MPLIBsettext
\MPLIBsetNtext
59 60
\unexpanded
\def
\MPLIBsetNtextX
#
1
% #2% box text
61
{
\MPLIBflushenvironment
62
\hbox
\bgroup
% text
63
\meta_set_current_color
64
\let
\MPLIBflushenvironment
\doMPLIBflushenvironment
65
\let
\next
}
66 67
\unexpanded
\def
\MPLIBsetCtextX
#
1
#
2
% #3% box colorspec text
68
{
\MPLIBflushenvironment
69
\hbox
\bgroup
% text
70
\directcolored
[#
2
]
%
71
\meta_set_current_color
% so, textcolor wins !
72
\let
\MPLIBflushenvironment
\doMPLIBflushenvironment
73
\let
\next
}
74 75
\let
\MPLIBsettextX
\MPLIBsetNtextX
76 77
\unexpanded
\def
\MPLIBgettextscaled
#
1
#
2
#
3
% why a copy .. can be used more often
78
{
\clf_mpgettext
\MPtextbox
#
1
%
79
\vpack
to
\zeropoint
{
\vss\hpack
to
\zeropoint
{
\scale
[
\c!sx
=#
2
,
\c!sy
=#
3
]
{
\raise\dp
\MPtextbox
\box
\MPtextbox
}
\forcecolorhack
\hss
}}}
80 81
% \unexpanded\def\MPLIBfigure#1#2%
82
% {\setbox\scratchbox\hpack{\externalfigure[#1][\c!mask=#2]}%
83
% \clf_mpsetsxsy\wd\scratchbox\ht\scratchbox\zeropoint
84
% \vpack to \zeropoint{\vss\hpack to \zeropoint{\scale[\c!sx=\sx,\c!sy=\sy]{\box\scratchbox}\hss}}}
85 86
\unexpanded
\def
\MPLIBfigure
#
1
#
2
%
87
{
\setbox
\scratchbox
\hpack
{
\externalfigure
[#
1
][
\c!mask
=#
2
]
}
%
88
\clf_mpsetsxsy
\wd
\scratchbox
\ht
\scratchbox
\zeropoint
89
\vpack
to
\zeropoint
{
\vss\hpack
to
\zeropoint
{
\fastsxsy
{
\sx
}{
\sy
}{
\box
\scratchbox
}
\hss
}}}
90 91
% horrible (we could inline scale and matrix code):
92 93
\unexpanded
\def
\MPLIBgettextscaledcm
#
1
#
2
#
3
#
4
#
5
#
6
#
7
#
8
#
9
% 2-7: sx,rx,ry,sy,tx,ty
94
{
\clf_mpgettext
\MPtextbox
#
1
%
95
\setbox
\MPbox
\hpack
\bgroup
96
\dotransformnextbox
{
#
2
}{
#
3
}{
#
4
}{
#
5
}{
#
6
}{
#
7
}
% does push pop ... will be changed to proper lua call (avoid small numbers)
97
\vpack
to
\zeropoint\bgroup
98
\vss
99
\hpack
to
\zeropoint
\bgroup
100
% \scale[\c!sx=#8,\c!sy=#9]{\raise\dp\MPtextbox\box\MPtextbox}%
101
% \scale[\c!sx=#8,\c!sy=#9,\c!depth=\v!no]{\box\MPtextbox}%
102
\fastsxsy
{
#
8
}{
#
9
}{
\raise\dp
\MPtextbox
\box
\MPtextbox
}
%
103
% This gives: LuaTeX warning: Misplaced \pdfrestore .. don't ask me why.
104
% but I'll retry it some day soon.
105
% \dostartscaling{#8}{#9}%
106
% \raise\dp\MPtextbox\box\MPtextbox
107
% \dostopscaling
108
\forcecolorhack
% can go away ... already in the scale macro
109
\hss
110
\egroup
111
\egroup
112
\egroup
113
\smashbox
\MPbox
114
\box
\MPbox
}
115 116
% \putnextboxincache{hans}{1}\hbox{foo}
117
%
118
% \startMPcode
119
% draw boundingbox rawtexbox("hans",1) ;
120
% draw rawtexbox("hans",1) ;
121
% \stopMPcode
122 123
\unexpanded
\def
\MPLIBgetboxscaledcm
#
1
#
2
%
124
{
\begingroup
125
\copyboxfromcache
{
#
1
}{
#
2
}
\MPtextbox
% can be \clf_
126
\MPLIBgetboxscaledcm_next
}
127 128
\unexpanded
\def
\MPLIBgetboxscaledcm_next
#
1
#
2
#
3
#
4
#
5
#
6
#
7
#
8
% 1-6: sx,rx,ry,sy,tx,ty
129
{
\setbox
\MPbox
\hpack
\bgroup
130
\dotransformnextbox
{
#
1
}{
#
2
}{
#
3
}{
#
4
}{
#
5
}{
#
6
}
%
131
\vpack
to
\zeropoint\bgroup
132
\vss
133
\hpack
to
\zeropoint
\bgroup
134
\fastsxsy
{
#
7
}{
#
8
}{
\raise\dp
\MPtextbox
\box
\MPtextbox
}
%
135
\hss
136
\egroup
137
\egroup
138
\egroup
139
\smashbox
\MPbox
140
\box
\MPbox
141
\endgroup
}
142 143
\unexpanded
\def
\MPLIBgraphictext
#
1
% use at mp end
144
{
\startTEXpage
[
\c!scale
=
1
0
0
0
0
]#
1
\stopTEXpage
}
145 146
%D \startbuffer
147
%D \definelayer[test]
148
%D
149
%D \setlayerframed
150
%D [test]
151
%D [x=\MPx{somepos-1},y=\MPy{somepos-1}]
152
%D [width=\MPw{somepos-1},height=\MPh{somepos-1}]
153
%D {Whatever we want here!}
154
%D
155
%D \setlayerframed
156
%D [test]
157
%D [x=\MPx{somepos-2},y=\MPy{somepos-2}]
158
%D [width=\MPw{somepos-2},height=\MPh{somepos-2}]
159
%D {Whatever we need there!}
160
%D
161
%D \startuseMPgraphic{oeps}
162
%D draw fullcircle scaled 6cm withcolor red ;
163
%D register ("somepos-1",5cm,1cm,center currentpicture) ;
164
%D register ("somepos-2",4cm,3cm,(-1cm,-2cm)) ;
165
%D \stopuseMPgraphic
166
%D
167
%D \framed[background=test,offset=overlay]{\useMPgraphic{oeps}}
168
%D \stopbuffer
169
%D
170
%D \typebuffer \startlinecorrection \getbuffer \stoplinecorrection
171 172
\unexpanded
\def
\MPLIBpositionwhd
#
1
#
2
#
3
#
4
#
5
% bp !
173
{
\dosavepositionwhd
{
#
1
}
\zerocount
{
#
2
\onebasepoint
}{
#
3
\onebasepoint
}{
#
4
\onebasepoint
}{
#
5
\onebasepoint
}
\zeropoint
}
174 175
% \def\MPLIBextrapass#1%
176
% {\ctxlua{metapost.graphic_extra_pass("#1")}}
177 178
%D Experiment
179 180
\def
\doMPLIBstopgroup
#
1
#
2
#
3
#
4
#
5
#
6
% some day this might happen elsewhere
181
{
\egroup
182
\setbox
\scratchbox
\hpack
{
\kern
\onebasepoint
\box
\scratchbox
}
% weird correction
183
\wd
\scratchbox
\dimexpr
#
5
\onebasepoint
-
#
3
\onebasepoint
+
2
\onebasepoint
\relax
184
\ht
\scratchbox
#
6
\onebasepoint
185
\dp
\scratchbox
-
#
4
\onebasepoint
186
\setbox
\scratchbox
\hpack
\bgroup
187
\kern
-
#
3
\onebasepoint
188
\box
\scratchbox
189
\egroup
190
\saveboxresource
191
attr
{
/
Group
<<
/
S
/
Transparency
/
I
\ifnum
#
1
=
1
true
\else
false
\fi
/
K
\ifnum
#
2
=
1
true
\else
false
\fi
>>
}
192
resources
{
\pdfbackendcurrentresources
}
193
\scratchbox
194
\setbox
\scratchbox
\hpack
\bgroup
195
\kern
#
3
\onebasepoint
196
\kern
-
\onebasepoint
197
\useboxresource
\lastsavedboxresourceindex
198
\egroup
199
\wd
\scratchbox
\zeropoint
200
\ht
\scratchbox
\zeropoint
201
\dp
\scratchbox
\zeropoint
202
\box
\scratchbox
203
\endgroup
}
204 205
\unexpanded
\def
\MPLIBstartgroup
#
1
#
2
#
3
#
4
#
5
#
6
% isolated 0/1, knockout 0/1 llx lly urx ury
206
{
\begingroup
207
\setbox
\scratchbox
\hpack
\bgroup
208
\unexpanded
\def
\MPLIBstopgroup
{
\doMPLIBstopgroup
{
#
1
}{
#
2
}{
#
3
}{
#
4
}{
#
5
}{
#
6
}}}
209 210
% For now here ... will be cleaned up:
211 212
\newtoks
\mptexttoks
213
\newbox
\mptextbox
214
\newtoks
\mpoutlinetoks
215
\newtoks
\mpgraphictexttoks
216 217
\mptexttoks
{
\global\setbox
\mptextbox
\hbox
{
\clf_mptexttoks
}}
218
\mpoutlinetoks
{
\global\setbox
\mptextbox
\vbox
{
\clf_mpoutlinetoks
}}
219
\mpgraphictexttoks
{
\global\setbox
\mptextbox
\vbox
{
\clf_mpgraphictexttoks
}}
220 221
\protect
\endinput
222