summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-07-10 16:30:53 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-07-10 16:30:53 +0200
commitff693671b6540fa81d2ad7aecdbe786a4df97335 (patch)
tree979066b446d6d47fcec40fa7da9978c31a2bf802 /metapost
parentf58860178fcd1497d52acaa3cb2ceda7531e46ac (diff)
downloadcontext-ff693671b6540fa81d2ad7aecdbe786a4df97335.tar.gz
2018-07-10 16:00:00
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mpiv/mp-blob.mpiv22
-rw-r--r--metapost/context/base/mpiv/mp-grph.mpiv2
-rw-r--r--metapost/context/base/mpiv/mp-luas.mpiv77
-rw-r--r--metapost/context/base/mpiv/mp-mlib.mpiv83
-rw-r--r--metapost/context/base/mpiv/mp-page.mpiv2
-rw-r--r--metapost/context/base/mpiv/mp-tool.mpiv8
6 files changed, 122 insertions, 72 deletions
diff --git a/metapost/context/base/mpiv/mp-blob.mpiv b/metapost/context/base/mpiv/mp-blob.mpiv
index d6773db21..318c78f4f 100644
--- a/metapost/context/base/mpiv/mp-blob.mpiv
+++ b/metapost/context/base/mpiv/mp-blob.mpiv
@@ -32,13 +32,13 @@ if mfun_use_one_pass :
vardef mfun_inject_blob(expr n) =
mfun_blob_c := nullpicture ;
- mfun_blob_b := lua.mp.blob_dimensions(mfun_blob_n,n) ;
+ mfun_blob_b := lua.mp.mf_blob_dimensions(mfun_blob_n,n) ;
addto mfun_blob_c doublepath unitsquare
xscaled redpart mfun_blob_b
yscaled (greenpart mfun_blob_b + bluepart mfun_blob_b)
shifted (0,- bluepart mfun_blob_b)
withprescript "mf_object=texblob"
- withprescript "tb_blob=" & decimal lua.mp.blob_index(mfun_blob_n,n) ;
+ withprescript "tb_blob=" & decimal lua.mp.mf_blob_index(mfun_blob_n,n) ;
mfun_blob_c
enddef ;
@@ -46,14 +46,14 @@ else :
vardef mfun_inject_blob(expr n) =
mfun_blob_c := nullpicture ;
- mfun_blob_b := lua.mp.blob_dimensions(mfun_blob_n,n) ;
+ mfun_blob_b := lua.mp.mf_blob_dimensions(mfun_blob_n,n) ;
addto mfun_blob_c doublepath unitsquare
xscaled redpart mfun_blob_b
yscaled (greenpart mfun_blob_b + bluepart mfun_blob_b)
shifted (0,- bluepart mfun_blob_b)
withprescript "mf_object=texblob"
withprescript "tb_stage=inject"
- withprescript "tb_blob=" & decimal lua.mp.blob_index(mfun_blob_n,n) ;
+ withprescript "tb_blob=" & decimal lua.mp.mf_blob_index(mfun_blob_n,n) ;
mfun_blob_c
enddef ;
@@ -71,19 +71,19 @@ if mfun_use_one_pass :
vardef followtext(expr pth, txt) =
image (
mfun_blob_n := mfun_blob_n + 1 ;
- lua.mp.InjectBlobB(mfun_blob_n,txt);
+ lua.mp.mf_inject_blob(mfun_blob_n,txt);
save pat, al, at, pl, pc, wid, pos, ap, ad, pic, len, n, sc ;
path pat ; pat := pth ;
numeric al, at, pl, pc, wid, pos, len[], n, sc ;
pair ap, ad ;
picture pic[] ;
len[0] := 0 ;
- n := lua.mp.blob_size(mfun_blob_n) ;
+ n := lua.mp.mf_blob_size(mfun_blob_n) ;
sc := 0 ;
for i=1 upto n :
pic[i] := mfun_inject_blob(i) ;
pic[i] := pic[i] shifted - llcorner pic[i] ;
- len[i] := len[i-1] + lua.mp.blob_width(mfun_blob_n,i) ;
+ len[i] := len[i-1] + lua.mp.mf_blob_width(mfun_blob_n,i) ;
endfor ;
al := arclength pth ;
if al = 0 :
@@ -107,7 +107,7 @@ if mfun_use_one_pass :
draw pat withpen pencircle scaled 1pt withcolor blue ;
fi ;
for i=1 upto n :
- wid := lua.mp.blob_width(mfun_blob_n,i) ;
+ wid := lua.mp.mf_blob_width(mfun_blob_n,i) ;
pos := len[i]-wid/2 + (i-1)*pl + pc ;
at := arctime pos of pat ;
ap := point at of pat ;
@@ -150,12 +150,12 @@ else :
pair ap, ad ;
picture pic[] ;
len[0] := 0 ;
- n := lua.mp.blob_size(mfun_blob_n) ;
+ n := lua.mp.mf_blob_size(mfun_blob_n) ;
sc := 0 ;
for i=1 upto n :
pic[i] := mfun_inject_blob(i) ;
pic[i] := pic[i] shifted - llcorner pic[i] ;
- len[i] := len[i-1] + lua.mp.blob_width(mfun_blob_n,i) ;
+ len[i] := len[i-1] + lua.mp.mf_blob_width(mfun_blob_n,i) ;
endfor ;
al := arclength pth ;
if al = 0 :
@@ -179,7 +179,7 @@ else :
draw pat withpen pencircle scaled 1pt withcolor blue ;
fi ;
for i=1 upto n :
- wid := lua.mp.blob_width(mfun_blob_n,i) ;
+ wid := lua.mp.mf_blob_width(mfun_blob_n,i) ;
pos := len[i]-wid/2 + (i-1)*pl + pc ;
at := arctime pos of pat ;
ap := point at of pat ;
diff --git a/metapost/context/base/mpiv/mp-grph.mpiv b/metapost/context/base/mpiv/mp-grph.mpiv
index a2f710881..2133d0ee5 100644
--- a/metapost/context/base/mpiv/mp-grph.mpiv
+++ b/metapost/context/base/mpiv/mp-grph.mpiv
@@ -139,7 +139,7 @@ if mfun_use_one_pass :
save figurepicture ; picture figurepicture ;
figurepicture := currentpicture ; currentpicture := nullpicture ;
currentgraphictext := currentgraphictext + 1 ;
- lua.mp.GraphicText(currentgraphictext,t) ;
+ lua.mp.mf_graphic_text(currentgraphictext,t) ;
mfun_finish_graphic_text % picks up directives
enddef ;
diff --git a/metapost/context/base/mpiv/mp-luas.mpiv b/metapost/context/base/mpiv/mp-luas.mpiv
index bebe4c0ad..d5aeec158 100644
--- a/metapost/context/base/mpiv/mp-luas.mpiv
+++ b/metapost/context/base/mpiv/mp-luas.mpiv
@@ -75,32 +75,69 @@ vardef mlib_luas_luacall(text t) =
)
enddef ;
+% vardef mlib_luas_lualist(expr c)(text t) =
+% save b ; boolean b ; b := false ;
+% runscript(c & "(" for s = t :
+% if b :
+% & ","
+% else :
+% hide(b := true)
+% fi
+% if string s :
+% % & ditto & s & ditto
+% & mfun_lua_bs & s & mfun_lua_es
+% elseif numeric s :
+% & decimal s
+% elseif boolean s :
+% & if s : "true" else : "false" fi
+% elseif pair s :
+% & mfun_pair_to_table(s)
+% elseif path s :
+% & mfun_path_to_table(s)
+% elseif rgbcolor s :
+% & mfun_rgb_to_table(s)
+% elseif cmykcolor s :
+% & mfun_cmyk_to_table(s)
+% else :
+% & ditto & tostring(s) & ditto
+% fi endfor & ")"
+% )
+% enddef ;
+
+newinternal mfun_luas_b ;
+
+def mlib_luas_luadone =
+ exitif numeric begingroup mfun_luas_b := 1 ; endgroup ;
+enddef ;
+
vardef mlib_luas_lualist(expr c)(text t) =
- save b ; boolean b ; b := false ;
- runscript(c & "(" for s = t :
- if b :
- & ","
+ interim mfun_luas_b := 0 ;
+ runscript(c & for s = t :
+ if mfun_luas_b = 0 :
+ "("
+ % hide(mfun_luas_b := 1)
+ mlib_luas_luadone
else :
- hide(b := true)
+ ","
fi
+ &
if string s :
- % & ditto & s & ditto
- & mfun_lua_bs & s & mfun_lua_es
+ mfun_lua_bs & s & mfun_lua_es
elseif numeric s :
- & decimal s
+ decimal s
elseif boolean s :
- & if s : "true" else : "false" fi
+ if s : "true" else : "false" fi
elseif pair s :
- & mfun_pair_to_table(s)
+ mfun_pair_to_table(s)
elseif path s :
- & mfun_path_to_table(s)
+ mfun_path_to_table(s)
elseif rgbcolor s :
- & mfun_rgb_to_table(s)
+ mfun_rgb_to_table(s)
elseif cmykcolor s :
- & mfun_cmyk_to_table(s)
+ mfun_cmyk_to_table(s)
else :
- & ditto & tostring(s) & ditto
- fi endfor & ")"
+ ditto & tostring(s) & ditto
+ fi & endfor if mfun_luas_b = 0 : "()" else : ")" fi
)
enddef ;
@@ -188,11 +225,11 @@ vardef texstr(expr name) = lua.mp.texstr(name) enddef ;
% \stopMPcode
def inpath suffix p =
- = 1 step 1 until lua.mp.mfun_path_length(str p)
+ = 1 step 1 until lua.mp.mf_path_length(str p)
enddef ;
-vardef pointof primary i = lua.mp.mfun_path_point(i) enddef ;
-vardef leftof primary i = lua.mp.mfun_path_left (i) enddef ;
-vardef rightof primary i = lua.mp.mfun_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 ;
-extra_endfig := extra_endfig & " lua.mp.mfun_path_reset() ; " ;
+extra_endfig := extra_endfig & " lua.mp.mf_path_reset() ; " ;
diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv
index 6fcc75d50..019020d82 100644
--- a/metapost/context/base/mpiv/mp-mlib.mpiv
+++ b/metapost/context/base/mpiv/mp-mlib.mpiv
@@ -202,7 +202,7 @@ if mfun_use_one_pass :
mfun_tt_c := nullpicture ;
mfun_tt_o := nullpicture ;
addto mfun_tt_o doublepath origin _op_ ; % save drawoptions
- mfun_tt_r := lua.mp.SomeText(mfun_tt_n,s) ;
+ mfun_tt_r := lua.mp.mf_some_text(mfun_tt_n,s) ;
addto mfun_tt_c doublepath unitsquare
xscaled redpart mfun_tt_r
yscaled (greenpart mfun_tt_r + bluepart mfun_tt_r)
@@ -220,7 +220,7 @@ if mfun_use_one_pass :
mfun_tt_c := nullpicture ;
mfun_tt_o := nullpicture ;
addto mfun_tt_o doublepath origin _op_ ; % save drawoptions
- mfun_tt_r := lua.mp.MadeText(mfun_tt_n) ;
+ mfun_tt_r := lua.mp.mf_made_text(mfun_tt_n) ;
addto mfun_tt_c doublepath unitsquare
xscaled redpart mfun_tt_r
yscaled (greenpart mfun_tt_r + bluepart mfun_tt_r)
@@ -255,7 +255,7 @@ else :
withprescript "tx_global=yes" ;
fi ;
else :
- mfun_tt_b := lua.mp.tt_dimensions(mfun_tt_n) ;
+ mfun_tt_b := lua.mp.mf_tt_dimensions(mfun_tt_n) ;
addto mfun_tt_c doublepath unitsquare
xscaled redpart mfun_tt_b
yscaled (greenpart mfun_tt_b + bluepart mfun_tt_b)
@@ -286,7 +286,7 @@ enddef ;
vardef rawtexbox(expr category, name) =
mfun_tt_c := nullpicture ;
if validtexbox(category,name) :
- mfun_tt_b := lua.mp.tb_dimensions(category, name) ;
+ mfun_tt_b := lua.mp.mf_tb_dimensions(category, name) ;
addto mfun_tt_c doublepath unitsquare
xscaled redpart mfun_tt_b
yscaled (greenpart mfun_tt_b + bluepart mfun_tt_b)
@@ -468,7 +468,7 @@ if mfun_use_one_pass :
mfun_tt_c := nullpicture ;
mfun_tt_o := nullpicture ;
addto mfun_tt_o doublepath origin _op_ ; % save drawoptions
- mfun_tt_r := lua.mp.SomeFormattedText(mfun_tt_n,t) ;
+ mfun_tt_r := lua.mp.mf_formatted_text(mfun_tt_n,t) ;
addto mfun_tt_c doublepath unitsquare
xscaled redpart mfun_tt_r
yscaled (greenpart mfun_tt_r + bluepart mfun_tt_r)
@@ -513,7 +513,7 @@ else :
withprescript "tx_global=yes" ;
fi ;
else :
- mfun_tt_b := lua.mp.tt_dimensions(mfun_tt_n) ;
+ mfun_tt_b := lua.mp.mf_tt_dimensions(mfun_tt_n) ;
addto mfun_tt_c doublepath unitsquare
xscaled redpart mfun_tt_b
yscaled (greenpart mfun_tt_b + bluepart mfun_tt_b)
@@ -1075,19 +1075,38 @@ def withmask primary filename =
withprescript "fg_mask=" & filename
enddef ;
-def externalfigure primary filename =
- if false :
- rawtextext("\externalfigure[" & filename & "]")
- else :
- image (
- addto currentpicture doublepath unitsquare
- withprescript "fg_name=" & filename ;
- )
-% unitsquare
-% withpen pencircle scaled 0
-% withprescript "fg_name=" & filename
- fi
-enddef ;
+if mfun_use_one_pass :
+
+ vardef externalfigure primary filename =
+ mfun_tt_c := nullpicture ;
+ mfun_tt_r := lua.mp.mf_external_figure(filename) ;
+ addto mfun_tt_c doublepath unitsquare
+ xscaled redpart mfun_tt_r
+ yscaled greenpart mfun_tt_r
+ withprescript "mf_object=figure"
+ withprescript "fg_name=" & filename ;
+ ;
+ mfun_tt_c
+ enddef ;
+
+else :
+
+ def externalfigure primary filename =
+ if false :
+ rawtextext("\externalfigure[" & filename & "]")
+ else :
+ image (
+ addto currentpicture doublepath unitsquare
+ withprescript "mf_object=figure"
+ withprescript "fg_name=" & filename ;
+ )
+ % unitsquare
+ % withpen pencircle scaled 0
+ % withprescript "fg_name=" & filename
+ fi
+ enddef ;
+
+fi ;
def figure primary filename =
rawtextext("\externalfigure[" & filename & "]")
@@ -1247,7 +1266,7 @@ if mfun_use_one_pass :
def mfun_do_outline_options_r = enddef ;
image ( normaldraw image (
% lua.mp.report("set outline text",currentoutlinetext);
- lua.mp.OutlineText(currentoutlinetext,t,kind) ;
+ lua.mp.mf_outline_text(currentoutlinetext,t,kind) ;
% lua.mp.report("get outline text",currentoutlinetext);
if kind = "f" :
mfun_do_outline_text_set_f rest ;
@@ -1264,7 +1283,7 @@ if mfun_use_one_pass :
else :
mfun_do_outline_text_set_n rest ;
fi ;
- lua.mp.get_outline_text(currentoutlinetext) ;
+ lua.mp.mf_get_outline_text(currentoutlinetext) ;
) mfun_do_outline_options_r ; )
enddef ;
@@ -1302,7 +1321,7 @@ else :
else :
mfun_do_outline_text_set_n rest ;
fi ;
- lua.mp.get_outline_text(currentoutlinetext) ;
+ lua.mp.mf_get_outline_text(currentoutlinetext) ;
fi ;
) mfun_do_outline_options_r ; )
enddef ;
@@ -1757,23 +1776,15 @@ def nofill text t = fill t withpostscript "collect" enddef ;
% so we can do: withcolor "red"
-% vardef resolvedcolor primary s =
-% % lua.mp.namedcolor(s) % conflicts with macro namedcolor
-% % lua.mp.NamedColor(s) % okay but, can also be
-% % lua.mp("NamedColor",s) % which gives expansion mess
-% if string s :
-% runscript("mp.NamedColor('" & s & "')") % faster anyway
-% else :
-% s
-% fi
-% enddef ;
+% 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
- % lua.mp.namedcolor(s) % conflicts with macro namedcolor
- % lua.mp.NamedColor(s) % okay but, can also be
- % lua.mp("NamedColor",s) % which gives expansion mess
if string s :
- runscript("mp.NamedColor('" & s & "')") % faster anyway
+ runscript("mp.mf_named_color('" & s & "')") % faster anyway
else :
s
fi
diff --git a/metapost/context/base/mpiv/mp-page.mpiv b/metapost/context/base/mpiv/mp-page.mpiv
index 6e93bdaae..052bcbb23 100644
--- a/metapost/context/base/mpiv/mp-page.mpiv
+++ b/metapost/context/base/mpiv/mp-page.mpiv
@@ -188,6 +188,8 @@ fi ;
string CurrentLayout ; CurrentLayout := "default" ;
+% runscript("mp.PaperHeight()") % way faster of course
+
vardef PaperHeight = lua.mp.PaperHeight () enddef ;
vardef PaperWidth = lua.mp.PaperWidth () enddef ;
vardef PrintPaperHeight = lua.mp.PrintPaperHeight () enddef ;
diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv
index 566f71056..281767522 100644
--- a/metapost/context/base/mpiv/mp-tool.mpiv
+++ b/metapost/context/base/mpiv/mp-tool.mpiv
@@ -244,19 +244,19 @@ boolean savingdata ; savingdata := false ;
boolean savingdatadone ; savingdatadone := false ;
def savedata expr txt =
- lua.mp.save_data(txt);
+ lua.mp.mf_save_data(txt);
enddef ;
def startsavingdata =
- lua.mp.start_saving_data();
+ lua.mp.mf_start_saving_data();
enddef ;
def stopsavingdata =
- lua.mp.stop_saving_data() ;
+ lua.mp.mf_stop_saving_data() ;
enddef ;
def finishsavingdata =
- lua.mp.finish_saving_data() ;
+ lua.mp.mf_finish_saving_data() ;
enddef ;
%D Instead of a keystroke eating save and allocation