diff options
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mpiv/metafun.mpiv | 6 | ||||
-rw-r--r-- | metapost/context/base/mpiv/minifun.mpiv | 2 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-luas.mpiv | 121 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-mlib.mpiv | 16 |
4 files changed, 92 insertions, 53 deletions
diff --git a/metapost/context/base/mpiv/metafun.mpiv b/metapost/context/base/mpiv/metafun.mpiv index fa43d3460..5a47280c4 100644 --- a/metapost/context/base/mpiv/metafun.mpiv +++ b/metapost/context/base/mpiv/metafun.mpiv @@ -15,8 +15,10 @@ %D prevent dependency problems and in the end even may use a patched version, %D we prefer to use a copy. -prologues := 0 ; -mpprocset := 1 ; +boolean contextlmtxmode ; contextlmtxmode := if known fontmaking : false else: true fi; + +prologues := 0 ; % not used +mpprocset := 1 ; % not used input "mp-base.mpiv" ; input "mp-tool.mpiv" ; diff --git a/metapost/context/base/mpiv/minifun.mpiv b/metapost/context/base/mpiv/minifun.mpiv index 6d877fddb..ea4634c85 100644 --- a/metapost/context/base/mpiv/minifun.mpiv +++ b/metapost/context/base/mpiv/minifun.mpiv @@ -14,6 +14,8 @@ %D This is a minimal \METAFUN\ instance which can be handy for isolated %D subruns. +boolean contextlmtxmode ; contextlmtxmode := if known fontmaking : false else: true fi; + prologues := 0 ; mpprocset := 1 ; diff --git a/metapost/context/base/mpiv/mp-luas.mpiv b/metapost/context/base/mpiv/mp-luas.mpiv index 03f445014..1ba4a6dc9 100644 --- a/metapost/context/base/mpiv/mp-luas.mpiv +++ b/metapost/context/base/mpiv/mp-luas.mpiv @@ -24,6 +24,23 @@ if known context_luas : endinput ; fi ; boolean context_luas ; context_luas := true ; +% Experimental + +if contextlmtxmode : + + % not yet (timing issue) + + newinternal mfid_scriptindex ; + mfid_scriptindex := runscript("mp.mf_script_index('scriptindex')") ; + + def scriptindex = runscript mfid_scriptindex enddef ; + +% def scriptindex expr name = +% lua.mp.mf_script_index(name) +% enddef ; + +fi ; + % First variant: % % let lua = runscript ; @@ -110,7 +127,7 @@ def mlib_luas_luadone = exitif numeric begingroup mfun_luas_b := 1 ; endgroup ; enddef ; -vardef mlib_luas_lualist(expr c)(text t) = +vardef mlib_luas_lualist(expr c)(text t) = % we could use mlib_luas_s instead of c interim mfun_luas_b := 0 ; runscript(c & for s = t : if mfun_luas_b = 0 : @@ -164,6 +181,32 @@ def message expr t = lua.mp.report(tostring(t)) ; enddef ; +% Color: + +% We do a low level runscript: +% +% lua.mp.namedcolor(s) % conflicts with macro namedcolor +% lua.mp.mf_named_color(s) % okay but, can also be +% lua.mp("mf_named_color",s) % which gives expansion mess + +if contextlmtxmode : + + newinternal mfid_resolvedcolor ; mfid_resolvedcolor := scriptindex "namedcolor" ; + + def resolvedcolor = runscript mfid_resolvedcolor enddef ; + +else : + + def resolvedcolor primary s = % no vardef + if string s : + runscript("mp.mf_named_color('" & s & "')") % faster anyway + else : + s + fi + enddef ; + +fi ; + % Modes: vardef texmode (expr s) = lua.mp("mode", s) enddef ; @@ -214,45 +257,53 @@ vardef texstr(expr name) = lua.mp.texstr(name) enddef ; %D New experimental feature for Alan-The-Number-Cruncher: -% \startMPcode{doublefun} -% path p ; p := ( -% for i=1 upto 20000 : -% origin randomized 10000 .. -% endfor cycle -% ) xysized (TextWidth,TextHeight) ; -% draw for i inpath p: -% pointof i .. controls (leftof i) and (rightof i) .. -% endfor cycle ; -% \stopMPcode - -% def inpath suffix p = -% = 1 step 1 until lua.mp.mf_path_length(str p) -% enddef ; +if contextlmtxmode : -% def inpath suffix p = -% % = 1 step 1 until lua.mp.mf_path_length(str p) -% = 1 step 1 until (begingroup save n ; n := lua.mp.mf_path_length(str p) ; if n = 0 : 1 else : n fi endgroup) -% enddef ; + newinternal mfid_path_lengthof ; mfid_path_lengthof := scriptindex "pathlengthof" ; + newinternal mfid_path_pointof ; mfid_path_pointof := scriptindex "pathpointof" ; + newinternal mfid_path_leftof ; mfid_path_leftof := scriptindex "pathleftof" ; + newinternal mfid_path_rightof ; mfid_path_rightof := scriptindex "pathrightof" ; + newinternal mfid_path_reset ; mfid_path_reset := scriptindex "pathreset" ; -def inpath suffix p = % permits p[0] - = 1 step 1 until - begingroup - save mfun_inpath_r,mfun_inpath_n ; path mfun_inpath_r ; - mfun_inpath_r = p ; - mfun_inpath_n := lua.mp.mf_path_length(str mfun_inpath_r) ; - if mfun_inpath_n = 0 : 1 else : mfun_inpath_n fi - endgroup -enddef ; + % 25 pct gain + + def inpath = = 1 step 1 until runscript mfid_path_lengthof enddef ; + vardef pointof primary i = runscript mfid_path_pointof i enddef ; + vardef leftof primary i = runscript mfid_path_leftof i enddef ; + vardef rightof primary i = runscript mfid_path_rightof i enddef ; + + % another 10 pct gain + + % def inpath = = 1 step 1 until runscript mfid_path_lengthof enddef ; + % def pointof = runscript mfid_path_pointof enddef ; + % def leftof = runscript mfid_path_leftof enddef ; + % def rightof = runscript mfid_path_rightof enddef ; + + extra_endfig := extra_endfig & " runscript mfid_path_reset ; " ; + +else : + + def inpath suffix p = % permits p[0] + = 1 step 1 until + begingroup + save mfun_inpath_r,mfun_inpath_n ; path mfun_inpath_r ; + mfun_inpath_r = p ; + mfun_inpath_n := lua.mp.mf_path_length(str mfun_inpath_r) ; + if mfun_inpath_n = 0 : 1 else : mfun_inpath_n fi + endgroup + enddef ; + + % vardef pointof primary i = lua.mp.mf_path_point(i) enddef ; + % vardef leftof primary i = lua.mp.mf_path_left (i) enddef ; + % vardef rightof primary i = lua.mp.mf_path_right(i) enddef ; -% vardef pointof primary i = lua.mp.mf_path_point(i) enddef ; -% vardef leftof primary i = lua.mp.mf_path_left (i) enddef ; -% vardef rightof primary i = lua.mp.mf_path_right(i) enddef ; + vardef pointof primary i = runscript("mp.mf_path_point(" & decimal i & ")") enddef ; + vardef leftof primary i = runscript("mp.mf_path_left(" & decimal i & ")") enddef ; + vardef rightof primary i = runscript("mp.mf_path_right(" & decimal i & ")") enddef ; -vardef pointof primary i = runscript("mp.mf_path_point(" & decimal i & ")") enddef ; -vardef leftof primary i = runscript("mp.mf_path_left(" & decimal i & ")") enddef ; -vardef rightof primary i = runscript("mp.mf_path_right(" & decimal i & ")") enddef ; + extra_endfig := extra_endfig & " lua.mp.mf_path_reset() ; " ; -extra_endfig := extra_endfig & " lua.mp.mf_path_reset() ; " ; +fi ; vardef utflen(expr s) = lua.mp.utflen(s) enddef ; vardef utfsub(expr s,f,t) = lua.mp.utfsub(s,f,t) enddef ; diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index a6ac3db3f..430c2e493 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -1681,22 +1681,6 @@ def nofill text t = fill t withpostscript "collect" enddef ; % if (t = "even-odd") or (t = "evenodd") : withpostscript "evenodd" fi % enddef ; -% so we can do: withcolor "red" - -% We do a low level runscript: -% -% lua.mp.namedcolor(s) % conflicts with macro namedcolor -% lua.mp.mf_named_color(s) % okay but, can also be -% lua.mp("mf_named_color",s) % which gives expansion mess - -def resolvedcolor primary s = % no vardef - if string s : - runscript("mp.mf_named_color('" & s & "')") % faster anyway - else : - s - fi -enddef ; - % A comment will end up on top of the graphic in the output. This can be handy for % locating a graphic: comment("test graphic"). |