summaryrefslogtreecommitdiff
path: root/tex/context/base/supp-mps.tex
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>1999-12-30 00:00:00 +0100
committerHans Hagen <pragma@wxs.nl>1999-12-30 00:00:00 +0100
commitdd50c74f0702bff05e96d5d3994316405414663e (patch)
tree1afbfa61cdd0721fa4eea8892972a6a183b05610 /tex/context/base/supp-mps.tex
parentb386eada290e225dc25484133c2bc5697024a822 (diff)
downloadcontext-dd50c74f0702bff05e96d5d3994316405414663e.tar.gz
stable 1999.12.30
Diffstat (limited to 'tex/context/base/supp-mps.tex')
-rw-r--r--tex/context/base/supp-mps.tex165
1 files changed, 139 insertions, 26 deletions
diff --git a/tex/context/base/supp-mps.tex b/tex/context/base/supp-mps.tex
index c7c920e21..51ea39dea 100644
--- a/tex/context/base/supp-mps.tex
+++ b/tex/context/base/supp-mps.tex
@@ -8,7 +8,7 @@
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
% E-tex : a primitive that tells us that \write18 works
@@ -154,7 +154,11 @@
%D process the \METAPOST\ file \type{mpgraph} between two
%D succesive \TEX\ runs.
-\def\MPgraphicfile{mp\ifMPrun run\else graph\fi}
+\ifx\MPgraphicfile\undefined
+
+ \def\MPgraphicfile{mp\ifMPrun run\else graph\fi}
+
+\fi
%D \macros
%D {MPgraphic}
@@ -182,23 +186,30 @@
%D implement both schemes.
%D \macros
-%D {MPinclusions, startMPinclusions}
+%D {MPinclusions, startMPinclusions, MPinitializations}
%D
%D One can include for instance common input commands by
%D passing them to \type{\MPinclusions}:
%D
%D \starttypen
-%D \MPinclusions{input tools}
+%D \MPinclusions{input mp-mine}
%D \stoptypen
+%D
+%D The token register type {\MPinitializations} is expanded
+%D before all other inclusions.
-\let\theMPinclusions=\empty
+\newtoks \MPinitializations
\long\def\startMPinclusions#1\stopMPinclusions%
- {\long\def\theMPinclusions{\writeMPgraphic{#1}}}
+ {\long\def\theMPinclusions%
+ {\@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPinitializations;}}%
+ \writeMPgraphic{#1}}}
\long\def\MPinclusions#1%
{\startMPinclusions#1\stopMPinclusions}
+\startMPinclusions \stopMPinclusions
+
%D \macros
%D {iflongMPlines}
%D
@@ -211,8 +222,15 @@
\newif\iflongMPlines
+\ifx \overlaywidth \undefined \def \overlaywidth {4cm} \fi
+\ifx \overlayheight \undefined \def \overlayheight {3cm} \fi
+\ifx \overlaylinewidth \undefined \def \overlaylinewidth {0pt} \fi
+
\long\def\writeMPgraphic#1%
{\bgroup
+ \edef\overlaywidth {\overlaywidth \space}%
+ \edef\overlayheight {\overlayheight \space}%
+ \edef\overlaylinewidth {\overlaylinewidth\space}%
\iflongMPlines
\let\par=\empty
\long\def\flush##1##2\par%
@@ -224,20 +242,22 @@
\else
\long\def\flush##1##2;%
{\ifx##1\relax \else
- \dowriteMPgraphicline##1##2btex\relax etex\MPend
+ \dowriteMPgraphicline##1##2tex \relax etex\MPend
\expandafter\flush
\fi}%
\flush#1\empty;\relax;%
\fi
\egroup}
-%D The \type{;} aware method (the \type{\else} branch) also
-%D takes care of \type{btex}||\type{etex} bound data.
+%D The \type {;} aware method (the \type {\else} branch) also
+%D takes care of \type {btex}||\type {etex}, \type
+%D {verbatimtex}||\type {etex}. The space after \type {tex}
+%D is essential, since it protects \type {text}.
\def\dowriteMPgraphicline%
{\futurelet\next\dodowriteMPgraphicline}
-\long\def\dodowriteMPgraphicline#1btex#2#3etex#4\MPend%
+\long\def\dodowriteMPgraphicline#1tex #2#3etex#4\MPend%
{\ifx\next\empty\else\ifx\next\relax\else
\bgroup
\let\par=\empty
@@ -246,9 +266,9 @@
\egroup
\else
\convertargument#2#3\to\ascii
- \immediate\write\MPwrite{#1btex \ascii etex;}%
+ \immediate\write\MPwrite{#1tex \ascii etex}%
\egroup
- \dowriteMPgraphicline#4btex\relax etex\MPend
+ \dowriteMPgraphicline#4tex \relax etex\MPend
\fi
\fi\fi}
@@ -257,22 +277,37 @@
%D can handle this and users may consider it being a sort
%D of error prevention bonus.
+%D \macros
+%D {everyMPgraphic}
+%D
+%D Because some graphics interact with \TEX\ (i.e.\ \CONTEXT), we
+%D provide a hook for additional actions: \type {\everyMPgraphic}.
+
+\bgroup
+\catcode`\%=12\gdef\percentletter{%}
+\egroup
+
+\newtoks\everyMPgraphic
+
\def\writeMPgraph%
{\immediate\write\MPwrite{mpgraph:=\the\currentMPgraphic;}}
\def\startwritingMPgraphic%
{\ifMPrun \else
- \global\advance\currentMPgraphic by 1
+ \allocateMPslot\currentMPgraphic
\fi
\ifrunMPgraphics
+ \the\everyMPgraphic
\xdef\MPgraphic{\the\currentMPgraphic}%
\immediate\openout\MPwrite=\MPgraphicfile.mp
+ \immediate\write\MPwrite{\percentletter\space runtime generated graphic}%
\writeMPgraph
\setMPrandomseed
\theMPinclusions
\else
\xdef\MPgraphic{\the\currentMPgraphic}%
\ifnum\currentMPgraphic=1
+ \the\everyMPgraphic
\immediate\openout\MPwrite=\MPgraphicfile.mp
\writeMPgraph
\setMPrandomseed
@@ -311,6 +346,11 @@
\let\stopwritingMPgraphic=\relax
\let\flushMPgraphics =\relax
+%D By default each graphic gets its own slot (number):
+
+\def \allocateMPslot#1{\global\advance#1 by 1 }
+\def\deallocateMPslot#1{}
+
%D \macros
%D {setMPrandomseed}
%D
@@ -394,6 +434,7 @@
\vbox
{\forgetall
\loadMPgraphic{\MPgraphicfile.\the\currentMPgraphic}{}%
+ \deallocateMPslot\currentMPgraphic
\placeMPgraphic}%
\setgvalue{#1}%
{\getobject{MP}{#1}}}
@@ -418,17 +459,30 @@
% \nouseMPbox{MP:#1}%
% \fi}}
+%\long\def\startreusableMPgraphic#1#2\stopreusableMPgraphic%
+% {\doifundefined{MP:#1}
+% {\long\setgvalue{MP:#1}%
+% {\startMPgraphic#2\stopMPgraphic
+% \doifobjectssupportedelse{}{\useMPboxfalse}%
+% \ifuseMPbox
+% \douseMPbox{MP:#1}%
+% \else
+% \nouseMPbox{MP:#1}%
+% \fi
+% \getvalue{MP:#1}}}}
+
\long\def\startreusableMPgraphic#1#2\stopreusableMPgraphic%
- {\doifundefined{MP:#1}
- {\setgvalue{MP:#1}%
- {\startMPgraphic#2\stopMPgraphic
- \doifobjectssupportedelse{}{\useMPboxfalse}%
- \ifuseMPbox
- \douseMPbox{MP:#1}%
- \else
- \nouseMPbox{MP:#1}%
- \fi
- \getvalue{MP:#1}}}}
+ {\ifundefined{MP:#1}%
+ \long\setgvalue{MP:#1}%
+ {\startMPgraphic#2\stopMPgraphic
+ \doifobjectssupportedelse{}{\useMPboxfalse}%
+ \ifuseMPbox
+ \douseMPbox{MP:#1}%
+ \else
+ \nouseMPbox{MP:#1}%
+ \fi
+ \getvalue{MP:#1}}%
+ \fi}
\def\reuseMPgraphic#1%
{\getvalue{MP:#1}}
@@ -443,7 +497,8 @@
{%\reuseMPgraphicstrue
\long\setgvalue{MP:#1}%
{\startMPgraphic#2\stopMPgraphic
- \loadcurrentMPgraphic{}%
+ \loadMPgraphic{\MPgraphicfile.\the\currentMPgraphic}{}%
+ \deallocateMPslot\currentMPgraphic
\placeMPgraphic}}
\let\useMPgraphic=\reuseMPgraphic
@@ -796,7 +851,7 @@
%D because MP can generate them anew.
\def\convertMPcolorpath{}
-\def\convertMPcolorfile{metacmyk.eps}
+\def\convertMPcolorfile{metacmyk.tmp}
\def\convertMPcolors#1%
{\bgroup
@@ -1038,7 +1093,8 @@
\setbox0=\hbox
{\expandafter\startMPgraphic\MPdrawingdata\stopMPgraphic
\loadcurrentMPgraphic\empty
- \placeMPgraphic}%
+%\deallocateMPslot\currentMPgraphic
+ \placeMPgraphic}%
\ifMPshiftdrawing
\dimen0=\MPllx bp
\dimen2=\MPlly bp
@@ -1075,6 +1131,63 @@
\def\dodoMPdivtenE #1#2{#1.#2}
\def\dodoMPdivtenF #1{.#1}
+%D \macros
+%D {startMPclip,grabMPclippath}
+%D
+%D We can use \METAPOST\ to calculate arbitrary clipping
+%D paths. Such a path is defined by (for instance):
+%D
+%D \starttypen
+%D \startMPclip{window}
+%D clip currentpicture to fullcircle xscaled \width yscaled \height ;
+%D \stopMPclip
+%D \stoptypen
+%D
+%D Such a path can be extracted (processed) by:
+%D
+%D \starttypen
+%D \grabMPpath{window}{method}{width}{height}{default path}
+%D \stoptypen
+%D
+%D Currently only method 1 makes sense; it produces \PDF\
+%D code. This macro only makes sense when hooked into a
+%D special routine.
+
+\long\def\startMPclip#1#2\stopMPclip%
+ {\long\setgvalue{MPC:#1}%
+ {\startMPgraphic#2\stopMPgraphic\dograbMPclippath}}
+
+\def\grabMPclippath#1#2#3#4#5%
+ {\bgroup
+ \edef\width {#3\space}\let\overlaywidth \width
+ \edef\height{#4\space}\let\overlayheight\height
+ \doifdefinedelse{MPC:#1}
+ {\getvalue{MPC:#1}%
+ \setxvalue{MPC:#1}{\noexpand\xdef\noexpand\MPclippath{\MPclippath}}}%
+ {\xdef\MPclippath{#5}}%
+ \ifcase#2\else
+ \doglobal\stripcharacter urveto\from\MPclippath\to\MPclippath
+ \doglobal\stripcharacter oveto\from\MPclippath\to\MPclippath
+ \doglobal\stripcharacter ineto\from\MPclippath\to\MPclippath
+ \fi
+ \egroup}
+
+%D We pose some restrictions to the \METAPOST\ code and pickup
+%D the last path in the file.
+
+\bgroup
+\catcode`\%=\@@active
+\catcode`\/=\@@comment
+\gdef\dograbMPclippath/ / the slash is now comment
+ {\setbox\scratchbox=\hbox\bgroup/ / the box grabs spaces
+ \catcode`\%=\@@active / the % token is a trigger
+ \obeylines\let\obeyedline\space / lines are ignores
+ \def%##1newpath##2closepath##3showpage/ we only need the path
+ {\xdef\MPclippath{##2}\endinput}/ / and can ignore the rest
+ \readfile{\MPgraphicfile.\the\currentMPgraphic}{}{}/
+ \egroup}
+\egroup
+
\protect
\endinput