summaryrefslogtreecommitdiff
path: root/tex/context/base/meta-ini.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/meta-ini.mkiv')
-rw-r--r--tex/context/base/meta-ini.mkiv346
1 files changed, 217 insertions, 129 deletions
diff --git a/tex/context/base/meta-ini.mkiv b/tex/context/base/meta-ini.mkiv
index 28ba9e901..299f37cef 100644
--- a/tex/context/base/meta-ini.mkiv
+++ b/tex/context/base/meta-ini.mkiv
@@ -106,7 +106,7 @@
{\dosinglegroupempty\meta_start_extensions}
\def\meta_start_extensions#1#2\stopMPextensions % we could use buffers instead
- {\ctxlua{metapost.setextensions("#1",\!!bs#2\!!es)}}
+ {\clf_setmpextensions{#1}{#2}}
\let\stopMPextensions\relax
@@ -155,12 +155,12 @@
\global\t_meta_inclusions\expandafter{\the\t_meta_inclusions#2}%
\let\currentMPinstance\m_meta_saved_instance}
-\def\meta_preset_definitions
- {\edef\overlaywidth {\overlaywidth \space}%
- \edef\overlayheight {\overlayheight \space}%
- \edef\overlaylinewidth{\overlaylinewidth\space}%
- \edef\currentwidth {\the\hsize \space}%
- \edef\currentheight {\the\vsize \space}}
+% \def\meta_preset_definitions
+% {\edef\overlaywidth {\overlaywidth \space}%
+% \edef\overlayheight {\overlayheight \space}%
+% \edef\overlaylinewidth{\overlaylinewidth\space}}
+
+\let\meta_preset_definitions\relax
\installcommandhandler \??mpinstance {MPinstance} \??mpinstance
@@ -217,13 +217,22 @@
\def\currentMPinstance {\defaultMPinstance}
\def\currentMPformat {\currentMPinstance}
-\defineMPinstance[metafun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
-\defineMPinstance[extrafun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
-\defineMPinstance[doublefun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!double]
-\defineMPinstance[decimalfun][\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!decimal]
-\defineMPinstance[mprun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
-\defineMPinstance[metapost] [\s!format=mpost]
-\defineMPinstance[nofun] [\s!format=mpost]
+\defineMPinstance[metafun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
+\defineMPinstance[extrafun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
+\defineMPinstance[lessfun] [\s!format=metafun]
+\defineMPinstance[doublefun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!double]
+\defineMPinstance[binaryfun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!binary]
+\defineMPinstance[decimalfun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!decimal]
+
+\defineMPinstance[mprun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
+
+\defineMPinstance[metapost] [\s!format=mpost]
+\defineMPinstance[nofun] [\s!format=mpost]
+\defineMPinstance[doublepost] [\s!format=mpost,\c!method=\s!double]
+\defineMPinstance[binarypost] [\s!format=mpost,\c!method=\s!binary]
+\defineMPinstance[decimalpost][\s!format=mpost,\c!method=\s!decimal]
+
+%defineMPinstance[megapost] [\s!format=mpost,\c!method=\s!decimal]
\newconditional\c_meta_include_initializations
@@ -264,7 +273,10 @@
\ifx\p_setups\empty \else
\setups[\p_setups]%
\fi
- \useMPinstancestyleandcolor\c!textstyle\c!textcolor}
+ \useMPinstancestyleparameter\c!textstyle}
+
+\def\meta_set_current_color
+ {\useMPinstancecolorparameter\c!textcolor}
\def\meta_stop_current_graphic
{\global\t_meta_definitions\emptytoks
@@ -291,20 +303,19 @@
\forgetall
\edef\p_extensions{\MPinstanceparameter\s!extensions}%
\meta_process_graphic_start
- \normalexpanded{\noexpand\ctxlua{metapost.graphic {
- instance = "\currentMPinstance",
- format = "\currentMPformat",
- data = \!!bs#1;\!!es,
- initializations = \!!bs\meta_flush_current_initializations\!!es,
-% useextensions = "\MPinstanceparameter\s!extensions",
-\ifx\p_extensions\v!yes
- extensions = \!!bs\ctxcommand{getmpextensions("\currentMPinstance")}\!!es,
-\fi
- inclusions = \!!bs\meta_flush_current_inclusions\!!es,
- definitions = \!!bs\meta_flush_current_definitions\!!es,
- figure = "\MPaskedfigure",
- method = "\MPinstanceparameter\c!method",
- }}}%
+ \normalexpanded{\noexpand\clf_mpgraphic
+ instance {\currentMPinstance}%
+ format {\currentMPformat}%
+ data {#1;}%
+ initializations {\meta_flush_current_initializations}%
+ \ifx\p_extensions\v!yes
+ extensions {\clf_getmpextensions{\currentMPinstance}}% goes through tex again
+ \fi
+ inclusions {\meta_flush_current_inclusions}%
+ definitions {\meta_flush_current_definitions}%
+ figure {\MPaskedfigure}%
+ method {\MPinstanceparameter\c!method}%
+ \relax}%
\meta_process_graphic_stop
\meta_stop_current_graphic}
@@ -325,23 +336,43 @@
\newif\ifsetMPrandomseed \setMPrandomseedtrue % false by default
+\let\theMPrandomseed\empty
+
\def\setMPrandomseed
- {\let\theMPrandomseed\empty
- \ifsetMPrandomseed \ifx\getrandomnumber\undefined \else
- \getrandomnumber\localMPseed\zerocount{4095}%
- \def\theMPrandomseed{randomseed:=\localMPseed}%
- \fi\fi}
+ {\ifsetMPrandomseed
+ \def\theMPrandomseed{randomseed:=\mprandomnumber;}%
+ \else
+ \let\theMPrandomseed\empty
+ \fi}
%D Calling up previously defined graphics.
+% \def\includeMPgraphic#1% gets expanded !
+% {\ifcsname\??mpgraphic#1\endcsname
+% \csname\??mpgraphic#1\endcsname ; % ; is safeguard
+% \fi}
+%
+% \unexpanded\def\meta_enable_include % public
+% {\let\meta_handle_use_graphic \thirdofthreearguments
+% \let\meta_handle_reusable_graphic\thirdofthreearguments}
+%
+% but ... we want this too:
+%
+% \startuseMPgraphic{x}
+% draw textext("\externalfigure[foo.pdf]") ;
+% \stopuseMPgraphic
+%
+% \useMPgraphic{x}
+%
+% so we cannot overload unless we let back to the original meanings
+% each graphic ... a better solution is:
+
\def\includeMPgraphic#1% gets expanded !
{\ifcsname\??mpgraphic#1\endcsname
- \csname\??mpgraphic#1\endcsname ; % ; is safeguard
+ \doubleexpandafter\fourthoffourarguments\csname\??mpgraphic#1\endcsname ; % ; is safeguard
\fi}
-\unexpanded\def\meta_enable_include % public
- {\let\meta_handle_use_graphic \thirdofthreearguments
- \let\meta_handle_reusable_graphic\thirdofthreearguments}
+\let\meta_enable_include\relax
%D Drawings (stepwise built):
@@ -397,20 +428,13 @@
\unexpanded\def\meta_grab_clip_path#1#2#3#4% #4 is alternative (called in backend code)
{\begingroup
- \edef\width {#2\space}\let\overlaywidth \width
- \edef\height{#3\space}\let\overlayheight\height
- \ifcsname\??mpclip#1\endcsname
- \meta_start_current_graphic
- \xdef\MPclippath{\normalexpanded{\noexpand\ctxlua{metapost.theclippath {
- instance = "\currentMPinstance",
- format = "\currentMPformat",
- data = \!!bs\getvalue{\??mpclip#1}\!!es,
- initializations = \!!bs\meta_flush_current_initializations\!!es,
- useextensions = "\MPinstanceparameter\s!extensions",
- inclusions = \!!bs\meta_flush_current_inclusions\!!es,
- method = "\MPinstanceparameter\c!method",
- }}}}%
- \meta_stop_current_graphic
+ \edef\width {#2}% \let\overlaywidth \width
+ \edef\height{#3}% \let\overlayheight\height
+ \d_overlay_width #2\onebasepoint
+ \d_overlay_height#3\onebasepoint
+ \edef\currentMPclip{#1}%
+ \ifcsname\??mpclip\currentMPclip\endcsname
+ \meta_grab_clip_path_indeed
\ifx\MPclippath\empty
\xdef\MPclippath{#4}%
\fi
@@ -419,6 +443,19 @@
\fi
\endgroup}
+\def\meta_grab_clip_path_indeed
+ {\meta_start_current_graphic
+ \normalexpanded{\noexpand\clf_mpsetclippath
+ instance {\currentMPinstance}%
+ format {\currentMPformat}%
+ data {\csname\??mpclip\currentMPclip\endcsname}%
+ initializations {\meta_flush_current_initializations}%
+ useextensions {\MPinstanceparameter\s!extensions}%
+ inclusions {\meta_flush_current_inclusions}%
+ method {\MPinstanceparameter\c!method}%
+ \relax}%
+ \meta_stop_current_graphic}
+
%D Since we want lables to follow the document settings, we
%D also set the font related variables.
@@ -426,7 +463,7 @@
{\dontleavehmode
\begingroup
\definedfont[#1]%
- \hskip\cldcontext{fonts.hashes.parameters[font.current()].designsize}sp\relax
+ \hskip\clf_currentdesignsize\scaledpoint\relax
\endgroup}
\definefontsynonym[MetafunDefault][Regular*default]
@@ -434,7 +471,7 @@
\startMPinitializations % scale is not yet ok
defaultfont:="\truefontname{MetafunDefault}";
% defaultscale:=\the\bodyfontsize/10pt; % only when hard coded 10pt
- defaultscale:=1;
+ % defaultscale:=1;
\stopMPinitializations
% watch out, this is a type1 font because mp can only handle 8 bit fonts
@@ -567,7 +604,7 @@
\def\meta_prepare_variable_yes
{\defconvertedcommand\ascii\m_meta_current_variable % otherwise problems
- \doifcolorelse \ascii % with 2\bodyfontsize
+ \doifelsecolor \ascii % with 2\bodyfontsize
{\meta_prepare_variable_color}
{\begingroup
\setbox\b_meta_variable_box\hbox{\scratchdimen\m_meta_current_variable sp}%
@@ -596,7 +633,13 @@
%D \stoptyping
\def\overlaystamp % watch the \MPcolor, since colors can be redefined
- {\overlaywidth:\overlayheight:\overlaydepth:\overlayoffset:\overlaylinewidth:\MPcolor\overlaycolor:\MPcolor\overlaylinecolor}
+ {\the\d_overlay_width :%
+ \the\d_overlay_height :%
+ \the\d_overlay_depth :%
+ \the\d_overlay_offset :%
+ \the\d_overlay_linewidth:%
+ \MPcolor\overlaycolor :% % todo, expand once \m_overlaycolor
+ \MPcolor\overlaylinecolor} % todo, expand once \m_overlaylinecolor
%D A better approach is to let additional variables play a role
%D in determining the uniqueness. In the next macro, the
@@ -779,19 +822,25 @@
\let\reuseMPgraphic \useMPgraphic % we can save a setup here if needed
\let\reusableMPgraphic\reuseMPgraphic % we can save a setup here if needed
-\unexpanded\def\meta_enable_include
- {\let\meta_handle_use_graphic \thirdofthreearguments
- \let\meta_handle_reusable_graphic\thirdofthreearguments}
-
%D \macros
%D {startuniqueMPpagegraphic,uniqueMPpagegraphic}
%D
%D Experimental.
-\def\m_meta_page_prefix{\doifoddpageelse oe}
+\def\m_meta_page_prefix{\doifelseoddpage oe}
+
+% \def\overlaypagestamp
+% {\m_meta_page_prefix:\overlaywidth:\overlayheight:\overlaydepth:\MPcolor\overlaycolor:\MPcolor\overlaylinecolor}
\def\overlaypagestamp
- {\m_meta_page_prefix:\overlaywidth:\overlayheight:\overlaydepth:\MPcolor\overlaycolor:\MPcolor\overlaylinecolor}
+ {\m_meta_page_prefix :%
+ \the\d_overlay_width :%
+ \the\d_overlay_height :%
+ \the\d_overlay_depth :%
+ \the\d_overlay_offset :%
+ \the\d_overlay_linewidth:%
+ \MPcolor\overlaycolor :%
+ \MPcolor\overlaylinecolor}
\unexpanded\def\startuniqueMPpagegraphic
{\dodoublegroupempty\meta_start_unique_page_graphic}
@@ -855,12 +904,21 @@
% makempy.registerfile(filename)
-\startMPinitializations
- boolean collapse_data; collapse_data:=true;
- def data_mpd_file = "\MPdataMPDfile" enddef ;
- def data_mpo_file = "\MPdataMPOfile" enddef ;
- def data_mpy_file = "\MPdataMPYfile" enddef ;
-\stopMPinitializations
+% % hm. extensions get expanded so the wrong names then end up in format
+%
+% \startMPinitializations
+% boolean collapse_data; collapse_data:=true ; % will be obsolete
+% def data_mpd_file = "\MPdataMPDfile" enddef ; % will go via lua
+% def data_mpo_file = "\MPdataMPOfile" enddef ;
+% def data_mpy_file = "\MPdataMPYfile" enddef ;
+% \stopMPinitializations
+
+\startMPextensions
+ boolean collapse_data; collapse_data:=true ; % will be obsolete
+ def data_mpd_file = "\noexpand\MPdataMPDfile" enddef ; % will go via lua
+ def data_mpo_file = "\noexpand\MPdataMPOfile" enddef ;
+ def data_mpy_file = "\noexpand\MPdataMPYfile" enddef ;
+\stopMPextensions
\unexpanded\def\getMPdata
{\let\MPdata\secondoftwoarguments
@@ -880,7 +938,7 @@
\def\meta_process_buffer[#1]%
{\meta_begin_graphic_group{#1}%
- \meta_process_graphic{\ctxcommand{feedback("\currentMPgraphicname")}}%
+ \meta_process_graphic{\clf_feedback{\currentMPgraphicname}}%
\meta_end_graphic_group}
\unexpanded\def\runMPbuffer
@@ -924,15 +982,15 @@
\else\ifx\m_meta_option\!!plustoken
#2% % use in main doc too
\fi\fi\fi
- \ctxlua{metapost.tex.set(\!!bs\detokenize{#2}\!!es)}}
+ \clf_mptexset{\detokenize{#2}}}
\let\stopMPenvironment\relax
\unexpanded\def\resetMPenvironment
- {\ctxlua{metapost.tex.reset()}}
+ {\clf_mptexreset}
\unexpanded\def\useMPenvironmentbuffer[#1]%
- {\ctxlua{metapost.tex.set(buffers.content("#1"))}}
+ {\clf_mpsetfrombuffer{#1}}
%D This command takes \type {[reset]} as optional
%D argument.
@@ -1054,7 +1112,7 @@
%D Loading specific \METAPOST\ related definitions is
%D accomplished by:
-\unexpanded\def\useMPlibrary[#1]{\ctxcommand{useMPlibrary(\!!bs#1\!!es)}}
+\unexpanded\def\useMPlibrary[#1]{\clf_useMPlibrary{#1}}
%D \macros
%D {setMPtext, MPtext, MPstring, MPbetex}
@@ -1084,46 +1142,62 @@
% \setupcolors[state=stop,conversion=never] % quite tricky ... type mismatch
-% A dirty trick, ** in colo-ini.lua (mpcolor).
+% \startMPextensions
+% color OverlayColor,OverlayLineColor;
+% \stopMPextensions
-\def\m_meta_colo_initializations{% no vardef, goes wrong with spot colors
- def OverlayLineColor=\MPcolor{\overlaylinecolor} enddef;
- def OverlayColor=\MPcolor{\overlaycolor} enddef;
-}
+\startMPinitializations
+ CurrentLayout:="\currentlayout";
+\stopMPinitializations
-\startMPextensions
- color OverlayColor,OverlayLineColor;
-\stopMPextensions
+% \startMPinitializations
+% OverlayWidth:=\overlaywidth;
+% OverlayHeight:=\overlayheight;
+% OverlayDepth:=\overlaydepth;
+% OverlayLineWidth:=\overlaylinewidth;
+% OverlayOffset:=\overlayoffset;
+% \stopMPinitializations
+
+% A dirty trick, ** in colo-ini.lua (mpcolor). We cannot use a vardef, because
+% that fails with spot colors.
\startMPinitializations
- CurrentLayout:="\currentlayout";
- OverlayWidth:=\overlaywidth;
- OverlayHeight:=\overlayheight;
- OverlayDepth:=\overlaydepth;
- OverlayLineWidth:=\overlaylinewidth;
- OverlayOffset:=\overlayoffset;
- %
- \m_meta_colo_initializations
- %
- BaseLineSkip:=\the\baselineskip;
- LineHeight:=\the\baselineskip;
- BodyFontSize:=\the\bodyfontsize;
- %
- TopSkip:=\the\topskip;
- StrutHeight:=\strutheight;
- StrutDepth:=\strutdepth;
- %
- CurrentWidth:=\the\hsize;
- CurrentHeight:=\the\vsize;
- %
- EmWidth:=\the\emwidth;
- ExHeight:=\the\exheight;
- %
- PageNumber:=\the\pageno;
- RealPageNumber:=\the\realpageno;
- LastPageNumber:= \lastpage;
+ def OverlayLineColor=\ifx\overlaylinecolor\empty black \else\MPcolor{\overlaylinecolor} \fi enddef;
+ def OverlayColor =\ifx\overlaycolor \empty black \else\MPcolor{\overlaycolor} \fi enddef;
\stopMPinitializations
+% \newcount\c_overlay_colormodel
+% \newcount\c_overlay_color
+% \newcount\c_overlay_transparency
+% \newcount\c_overlay_linecolor
+% \newcount\c_overlay_linetransparency
+
+% \appendtoks
+% \c_overlay_colormodel \attribute\colormodelattribute
+% \c_overlay_color \colo_helpers_inherited_current_ca\overlaycolor
+% \c_overlay_transparency \colo_helpers_inherited_current_ta\overlaycolor
+% \c_overlay_linecolor \colo_helpers_inherited_current_ca\overlaylinecolor
+% \c_overlay_linetransparency\colo_helpers_inherited_current_ta\overlaylinecolor
+% \to \everyMPgraphic
+
+% \startMPinitializations
+% BaseLineSkip:=\the\baselineskip;
+% LineHeight:=\the\baselineskip;
+% BodyFontSize:=\the\bodyfontsize;
+% %
+% TopSkip:=\the\topskip;
+% StrutHeight:=\strutheight;
+% StrutDepth:=\strutdepth;
+% %
+% CurrentWidth:=\the\hsize;
+% CurrentHeight:=\the\vsize;
+% HSize:=\the\hsize ;
+% VSize:=\the\vsize ;
+% %
+% EmWidth:=\the\emwidth;
+% ExHeight:=\the\exheight;
+% \stopMPinitializations
+
\appendtoks
\disablediscretionaries
\disablecompoundcharacters
@@ -1153,11 +1227,6 @@
\let \} \letterclosebrace
\to \everyMPgraphic
-\startMPinitializations
- prologues:=0;
- mpprocset:=1;
-\stopMPinitializations
-
%D \macros
%D {PDFMPformoffset}
%D
@@ -1184,21 +1253,36 @@
enddef;
\stopMPextensions
-\startMPinitializations
- HSize:=\the\hsize ;
- VSize:=\the\vsize ;
-\stopMPinitializations
-
\startMPextensions
vardef ForegroundBox =
unitsquare xysized(HSize,VSize)
enddef ;
- PageFraction := 1 ;
\stopMPextensions
-\startMPinitializations
- PageFraction := if \lastpage>1: (\realfolio-1)/(\lastpage-1) else: 1 fi ;
-\stopMPinitializations
+% \startMPextensions
+% PageFraction := 1 ;
+% \stopMPextensions
+
+% \startMPinitializations
+% PageFraction := if \lastpage>1: (\realfolio-1)/(\lastpage-1) else: 1 fi ;
+% \stopMPinitializations
+
+\startMPdefinitions {metapost}
+ if unknown context_bare : input mp-bare.mpiv ; fi ;
+\stopMPdefinitions
+\startMPdefinitions {binarypost}
+ if unknown context_bare : input mp-bare.mpiv ; fi ;
+\stopMPdefinitions
+\startMPdefinitions {decimalpost}
+ if unknown context_bare : input mp-bare.mpiv ; fi ;
+\stopMPdefinitions
+\startMPdefinitions {doublepost}
+ if unknown context_bare : input mp-bare.mpiv ; fi ;
+\stopMPdefinitions
+
+% \startMPdefinitions {nofun}
+% if unknown context_bare : input mp-bare.mpiv ; fi ;
+% \stopMPdefinitions
%D And some more. These are not really needed since we
%D don't use the normal figure inclusion macros any longer.
@@ -1359,12 +1443,16 @@
\newconstant\MPcolormethod
\appendtoks
- \ctxlua{metapost.setoutercolor(\number\MPcolormethod,\number\attribute\colormodelattribute,\number\attribute\colorattribute,\number\dogetattribute{transparency})}%
+ \clf_mpsetoutercolor
+ \MPcolormethod\space
+ \attribute\colormodelattribute\space
+ \attribute\colorattribute\space
+ \dogetattribute{transparency}\relax
\to \everyMPgraphic
-\startMPinitializations
- defaultcolormodel := \ifcase\MPcolormethod1\or1\or3\else3\fi;
-\stopMPinitializations
+% \startMPinitializations
+% defaultcolormodel := \ifcase\MPcolormethod1\or1\or3\else3\fi;
+% \stopMPinitializations
%D macros
%D {mprunvar,mpruntab,mprunset}
@@ -1390,9 +1478,9 @@
%D $(x,y) = (\MPrunset{point}{,})$
%D \stoptyping
-\def\MPrunvar #1{\ctxcommand{mprunvar("#1")}} \let\mprunvar\MPrunvar
-\def\MPruntab#1#2{\ctxcommand{mprunvar("#1",\number#2)}} \let\mpruntab\MPruntab
-\def\MPrunset#1#2{\ctxcommand{mprunvar("#1","#2")}} \let\mprunset\MPrunset
+\def\MPrunvar #1{\clf_mprunvar{#1}} \let\mprunvar\MPrunvar
+\def\MPruntab#1#2{\clf_mpruntab{#1}#2\relax} \let\mpruntab\MPruntab % #2 is number
+\def\MPrunset#1#2{\clf_mprunset{#1}{#2}} \let\mprunset\MPrunset
%D We also provide an outputless run:
@@ -1461,7 +1549,7 @@
\edef\p_mpy{\directMPgraphicsparameter{mpy}}%
\ifx\p_mpy\empty \else
\let\MPdataMPYfile\p_mpy
- \ctxlua{metapost.makempy.registerfile("\p_mpy")}%
+ \clf_registermpyfile{\p_mpy}%
\fi
\to \everysetupMPgraphics