From 823bd4a7d8ff32c05807b02e650ecbd60b43e95d Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Thu, 17 Jan 2019 23:06:17 +0100 Subject: 2019-01-17 22:18:00 --- metapost/context/base/mpiv/mp-bare.mpiv | 132 ++++--------- metapost/context/base/mpiv/mp-blob.mpiv | 241 +++++++----------------- metapost/context/base/mpiv/mp-grph.mpiv | 165 +--------------- metapost/context/base/mpiv/mp-mlib.mpiv | 323 ++++++++------------------------ metapost/context/base/mpiv/mp-tool.mpiv | 8 + 5 files changed, 199 insertions(+), 670 deletions(-) (limited to 'metapost') diff --git a/metapost/context/base/mpiv/mp-bare.mpiv b/metapost/context/base/mpiv/mp-bare.mpiv index e995556c1..8f517b268 100644 --- a/metapost/context/base/mpiv/mp-bare.mpiv +++ b/metapost/context/base/mpiv/mp-bare.mpiv @@ -14,8 +14,6 @@ if known context_bare : endinput ; fi ; boolean context_bare ; context_bare := true ; -boolean mfun_use_one_pass ; mfun_use_one_pass := runscript("mp.print(metapost.use_one_pass)") ; - vardef colordecimals primary c = if cmykcolor c : decimal cyanpart c & ":" & decimal magentapart c & ":" & decimal yellowpart c & ":" & decimal blackpart c @@ -26,49 +24,29 @@ vardef colordecimals primary c = fi enddef ; -if mfun_use_one_pass : - - rgbcolor mfun_tt_r ; - numeric mfun_tt_n ; mfun_tt_n := 0 ; - picture mfun_tt_o ; mfun_tt_o := nullpicture ; - picture mfun_tt_c ; mfun_tt_c := nullpicture ; +rgbcolor mfun_tt_r ; +numeric mfun_tt_n ; mfun_tt_n := 0 ; +picture mfun_tt_o ; mfun_tt_o := nullpicture ; +picture mfun_tt_c ; mfun_tt_c := nullpicture ; - def mfun_reset_tex_texts = - mfun_tt_n := 0 ; - mfun_tt_o := nullpicture ; % redundant - mfun_tt_c := nullpicture ; % redundant - enddef ; - - def mfun_flush_tex_texts = - enddef ; +def mfun_reset_tex_texts = + mfun_tt_n := 0 ; + mfun_tt_o := nullpicture ; % redundant + mfun_tt_c := nullpicture ; % redundant +enddef ; - vardef rawtextext(expr s) = - if s = "" : - nullpicture - else : - mfun_tt_n := mfun_tt_n + 1 ; - mfun_tt_c := nullpicture ; - mfun_tt_o := nullpicture ; - addto mfun_tt_o doublepath origin _op_ ; % save drawoptions - mfun_tt_r := runscript("mp.SomeText(" & decimal mfun_tt_n & "," & ditto & s & ditto & ")") ; - addto mfun_tt_c doublepath unitsquare - xscaled redpart mfun_tt_r - yscaled (greenpart mfun_tt_r + bluepart mfun_tt_r) - shifted (0,-bluepart mfun_tt_r) - withprescript "mf_object=text" - withprescript "tx_index=" & decimal mfun_tt_n - withprescript "tx_color=" & colordecimals colorpart mfun_tt_o - ; - mfun_tt_c - fi - enddef ; +def mfun_flush_tex_texts = +enddef ; - vardef rawmadetext = +vardef rawtextext(expr s) = + if s = "" : + nullpicture + else : mfun_tt_n := mfun_tt_n + 1 ; mfun_tt_c := nullpicture ; mfun_tt_o := nullpicture ; addto mfun_tt_o doublepath origin _op_ ; % save drawoptions - mfun_tt_r := runscript("mp.MadeText(" & decimal mfun_tt_n & ")") ; + mfun_tt_r := runscript("mp.SomeText(" & decimal mfun_tt_n & "," & ditto & s & ditto & ")") ; addto mfun_tt_c doublepath unitsquare xscaled redpart mfun_tt_r yscaled (greenpart mfun_tt_r + bluepart mfun_tt_r) @@ -78,67 +56,25 @@ if mfun_use_one_pass : withprescript "tx_color=" & colordecimals colorpart mfun_tt_o ; mfun_tt_c - enddef ; - -else : - - numeric mfun_tt_w[], mfun_tt_h[], mfun_tt_d[] ; - numeric mfun_tt_n ; mfun_tt_n := 0 ; - picture mfun_tt_p ; mfun_tt_p := nullpicture ; - picture mfun_tt_o ; mfun_tt_o := nullpicture ; - picture mfun_tt_c ; mfun_tt_c := nullpicture ; - - if unknown mfun_trial_run : - boolean mfun_trial_run ; - mfun_trial_run := false ; - fi ; - - if unknown mfun_first_run : - boolean mfun_first_run ; - mfun_first_run := true ; - fi ; - - def mfun_reset_tex_texts = - mfun_tt_n := 0 ; - mfun_tt_p := nullpicture ; - mfun_tt_o := nullpicture ; % redundant - mfun_tt_c := nullpicture ; % redundant - enddef ; - - def mfun_flush_tex_texts = - addto currentpicture also mfun_tt_p - enddef ; - - vardef rawtextext(expr str) = % todo: avoid currentpicture - if str = "" : - nullpicture - else : - mfun_tt_n := mfun_tt_n + 1 ; - mfun_tt_c := nullpicture ; - if mfun_trial_run : - mfun_tt_o := nullpicture ; - addto mfun_tt_o doublepath origin _op_ ; % save drawoptions - addto mfun_tt_c doublepath unitsquare - withprescript "tx_number=" & decimal mfun_tt_n - withprescript "tx_stage=trial" - withprescript "tx_color=" & colordecimals colorpart mfun_tt_o - withpostscript str ; - addto mfun_tt_p also mfun_tt_c ; - elseif known mfun_tt_d[mfun_tt_n] : - addto mfun_tt_c doublepath unitsquare - xscaled mfun_tt_w[mfun_tt_n] - yscaled (mfun_tt_h[mfun_tt_n] + mfun_tt_d[mfun_tt_n]) - shifted (0,-mfun_tt_d[mfun_tt_n]) - withprescript "tx_number=" & decimal mfun_tt_n - withprescript "tx_stage=final" ; - else : - addto mfun_tt_c doublepath unitsquare ; % unitpicture - fi ; - mfun_tt_c - fi - enddef ; + fi +enddef ; -fi ; +vardef rawmadetext = + mfun_tt_n := mfun_tt_n + 1 ; + mfun_tt_c := nullpicture ; + mfun_tt_o := nullpicture ; + addto mfun_tt_o doublepath origin _op_ ; % save drawoptions + mfun_tt_r := runscript("mp.MadeText(" & decimal mfun_tt_n & ")") ; + addto mfun_tt_c doublepath unitsquare + xscaled redpart mfun_tt_r + yscaled (greenpart mfun_tt_r + bluepart mfun_tt_r) + shifted (0,-bluepart mfun_tt_r) + withprescript "mf_object=text" + withprescript "tx_index=" & decimal mfun_tt_n + withprescript "tx_color=" & colordecimals colorpart mfun_tt_o + ; + mfun_tt_c +enddef ; extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ; extra_endfig := "mfun_flush_tex_texts ; mfun_reset_tex_texts ; " & extra_endfig ; diff --git a/metapost/context/base/mpiv/mp-blob.mpiv b/metapost/context/base/mpiv/mp-blob.mpiv index 318c78f4f..d1fc7357b 100644 --- a/metapost/context/base/mpiv/mp-blob.mpiv +++ b/metapost/context/base/mpiv/mp-blob.mpiv @@ -28,36 +28,17 @@ enddef ; extra_endfig := extra_endfig & "mfun_reset_tex_blobs ; " ; -if mfun_use_one_pass : - - vardef mfun_inject_blob(expr n) = - mfun_blob_c := nullpicture ; - 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.mf_blob_index(mfun_blob_n,n) ; - mfun_blob_c - enddef ; - -else : - - vardef mfun_inject_blob(expr n) = - mfun_blob_c := nullpicture ; - 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.mf_blob_index(mfun_blob_n,n) ; - mfun_blob_c - enddef ; - -fi ; +vardef mfun_inject_blob(expr n) = + mfun_blob_c := nullpicture ; + 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.mf_blob_index(mfun_blob_n,n) ; + mfun_blob_c +enddef ; % An example of usage: @@ -66,144 +47,66 @@ newinternal tracingfollowtext ; tracingfollowtext := 0 ; newinternal autoscaleupfollowtext ; autoscaleupfollowtext := 2 ; newinternal autoscaledownfollowtext ; autoscaledownfollowtext := 0 ; -if mfun_use_one_pass : - - vardef followtext(expr pth, txt) = - image ( - mfun_blob_n := mfun_blob_n + 1 ; - 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.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.mf_blob_width(mfun_blob_n,i) ; - endfor ; - al := arclength pth ; - if al = 0 : - al := len[n] ; - pat := origin -- (al,0) ; - fi ; - if ((al < len[n]) and (autoscaleupfollowtext > 0)) or - ((al > len[n]) and (autoscaledownfollowtext > 0)) : - sc := len[n] /al ; - pat := pat scaled sc ; - al := arclength pat ; - fi ; - if followtextalternative = 1 : - pl := (al-len[n])/(if n>1 : (n-1) else : 1 fi) ; - pc := 0 ; - else : % centered / MP - pl := 0 ; - pc := arclength pat/2 - len[n]/2 ; - fi ; +vardef followtext(expr pth, txt) = + image ( + mfun_blob_n := mfun_blob_n + 1 ; + 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.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.mf_blob_width(mfun_blob_n,i) ; + endfor ; + al := arclength pth ; + if al = 0 : + al := len[n] ; + pat := origin -- (al,0) ; + fi ; + if ((al < len[n]) and (autoscaleupfollowtext > 0)) or + ((al > len[n]) and (autoscaledownfollowtext > 0)) : + sc := len[n] /al ; + pat := pat scaled sc ; + al := arclength pat ; + fi ; + if followtextalternative = 1 : + pl := (al-len[n])/(if n>1 : (n-1) else : 1 fi) ; + pc := 0 ; + else : % centered / MP + pl := 0 ; + pc := arclength pat/2 - len[n]/2 ; + fi ; + if tracingfollowtext = 1 : + draw pat withpen pencircle scaled 1pt withcolor blue ; + fi ; + for i=1 upto n : + 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 ; + ad := direction at of pat ; + pic[i] := pic[i] shifted (-wid/2,0) rotated(angle(ad)) shifted ap ; + draw pic[i] ; if tracingfollowtext = 1 : - draw pat withpen pencircle scaled 1pt withcolor blue ; - fi ; - for i=1 upto n : - 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 ; - ad := direction at of pat ; - pic[i] := pic[i] shifted (-wid/2,0) rotated(angle(ad)) shifted ap ; - draw pic[i] ; - if tracingfollowtext = 1 : - draw boundingbox pic[i] withpen pencircle scaled .25pt withcolor red ; - draw ap withpen pencircle scaled .50pt withcolor green ; - fi ; - endfor ; - if ((autoscaleupfollowtext = 2) or (autoscaledownfollowtext = 2)) and - (sc <> 0) and (sc <> 1): - currentpicture := currentpicture scaled (1/sc) ; + draw boundingbox pic[i] withpen pencircle scaled .25pt withcolor red ; + draw ap withpen pencircle scaled .50pt withcolor green ; fi ; - if tracingfollowtext = 1 : - draw boundingbox currentpicture withpen pencircle scaled .25pt withcolor blue ; - fi ; - draw fullcircle scaled 100bp - withprescript "mf_object=followtext" - withprescript "ft_category=" & decimal mfun_blob_n ; - ) - enddef ; - -else : - - vardef followtext(expr pth, txt) = - image ( - mfun_blob_n := mfun_blob_n + 1 ; - if mfun_trial_run : - draw fullcircle scaled 100bp - withprescript "mf_object=followtext" - withprescript "ft_stage=trial" - withprescript "ft_category=" & decimal mfun_blob_n - withpostscript txt ; - else : - 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.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.mf_blob_width(mfun_blob_n,i) ; - endfor ; - al := arclength pth ; - if al = 0 : - al := len[n] ; - pat := origin -- (al,0) ; - fi ; - if ((al < len[n]) and (autoscaleupfollowtext > 0)) or - ((al > len[n]) and (autoscaledownfollowtext > 0)) : - sc := len[n] /al ; - pat := pat scaled sc ; - al := arclength pat ; - fi ; - if followtextalternative = 1 : - pl := (al-len[n])/(if n>1 : (n-1) else : 1 fi) ; - pc := 0 ; - else : % centered / MP - pl := 0 ; - pc := arclength pat/2 - len[n]/2 ; - fi ; - if tracingfollowtext = 1 : - draw pat withpen pencircle scaled 1pt withcolor blue ; - fi ; - for i=1 upto n : - 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 ; - ad := direction at of pat ; - pic[i] := pic[i] shifted (-wid/2,0) rotated(angle(ad)) shifted ap ; - draw pic[i] ; - if tracingfollowtext = 1 : - draw boundingbox pic[i] withpen pencircle scaled .25pt withcolor red ; - draw ap withpen pencircle scaled .50pt withcolor green ; - fi ; - endfor ; - if ((autoscaleupfollowtext = 2) or (autoscaledownfollowtext = 2)) and - (sc <> 0) and (sc <> 1): - currentpicture := currentpicture scaled (1/sc) ; - fi ; - if tracingfollowtext = 1 : - draw boundingbox currentpicture withpen pencircle scaled .25pt withcolor blue ; - fi ; - draw fullcircle scaled 100bp - withprescript "mf_object=followtext" - withprescript "ft_stage=final" - withprescript "ft_category=" & decimal mfun_blob_n ; - fi ; - ) - enddef ; - -fi ; + endfor ; + if ((autoscaleupfollowtext = 2) or (autoscaledownfollowtext = 2)) and + (sc <> 0) and (sc <> 1): + currentpicture := currentpicture scaled (1/sc) ; + fi ; + if tracingfollowtext = 1 : + draw boundingbox currentpicture withpen pencircle scaled .25pt withcolor blue ; + fi ; + draw fullcircle scaled 100bp + withprescript "mf_object=followtext" + withprescript "ft_category=" & decimal mfun_blob_n ; + ) +enddef ; diff --git a/metapost/context/base/mpiv/mp-grph.mpiv b/metapost/context/base/mpiv/mp-grph.mpiv index 2133d0ee5..3c042f83c 100644 --- a/metapost/context/base/mpiv/mp-grph.mpiv +++ b/metapost/context/base/mpiv/mp-grph.mpiv @@ -65,8 +65,6 @@ enddef ; numeric currentgraphictext ; currentgraphictext := 0 ; -def data_mpy_file = job_name & "-mpgraph.mpy" enddef ; - def begingraphictextfig (expr n) = foundpicture := n ; scratchpicture := nullpicture ; @@ -117,7 +115,7 @@ def mfun_load_figure (expr filename) text figureattributes = endgroup ; enddef ; -% shared between old and new +% We only use the new method now. boolean mfun_gt_color_fill ; boolean mfun_gt_color_draw ; @@ -126,168 +124,12 @@ boolean mfun_gt_reverse_fill ; boolean mfun_gt_outline_fill ; picture mfun_gt_picture ; -% this is the old version: - -if mfun_use_one_pass : - - def old_graphictext primary t = - mfun_do_graphic_text(t) - enddef ; - - def mfun_do_graphic_text (expr t) = - begingroup ; - save figurepicture ; picture figurepicture ; - figurepicture := currentpicture ; currentpicture := nullpicture ; - currentgraphictext := currentgraphictext + 1 ; - lua.mp.mf_graphic_text(currentgraphictext,t) ; - mfun_finish_graphic_text % picks up directives - enddef ; - -else : - - def old_graphictext primary t = - hide ( - if mfun_trial_run : - let mfun_graphic_text = mfun_no_graphic_text ; - else : - let mfun_graphic_text = mfun_do_graphic_text ; - fi - ) - mfun_graphic_text(t) - enddef ; - - def mfun_do_graphic_text (expr t) = - % withprescript "gt_stage=final" - begingroup ; - save figurepicture ; picture figurepicture ; - figurepicture := currentpicture ; currentpicture := nullpicture ; - currentgraphictext := currentgraphictext + 1 ; - mfun_finish_graphic_text % picks up directives - enddef ; - - def mfun_no_graphic_text (expr t) text rest = - currentgraphictext := currentgraphictext + 1 ; - draw unitsquare - withprescript "mf_object=graphictext" - withprescript "gt_stage=trial" - withprescript "gt_index=" & decimal currentgraphictext - withpostscript t - enddef ; - -fi ; - -def mfun_finish_graphic_text text rest = - protectgraphicmacros ; % resets currentpicture - interim linecap := butt ; % normally rounded - interim linejoin := mitered ; % normally rounded - interim miterlimit := 10 ; % todo - let normalwithshade = withshade ; - save foundpicture, scratchpicture, str ; - save fill, draw, withshade, reversefill, outlinefill ; - save withfillcolor, withdrawcolor ; % quite important - numeric foundpicture ; picture scratchpicture ; string str ; - def draw expr p = - % the first, naive implementation was: - % addto scratchpicture doublepath p withpen currentpen ; - % but it is better to turn lines into fills - addto scratchpicture contour boundingbox - image (addto currentpicture doublepath p withpen currentpen) ; - enddef ; - def fill expr p = - addto scratchpicture contour p withpen currentpen ; - enddef ; - def mfun_gt_fill = enddef ; boolean mfun_gt_color_fill ; mfun_gt_color_fill := false ; - def mfun_gt_draw = enddef ; boolean mfun_gt_color_draw ; mfun_gt_color_draw := false ; - def mfun_gt_shade = enddef ; boolean mfun_gt_shade_fill ; mfun_gt_shade_fill := false ; - boolean mfun_gt_reverse_fill ; mfun_gt_reverse_fill := false ; - boolean mfun_gt_outline_fill ; mfun_gt_outline_fill := false ; - def reversefill = - hide(mfun_gt_reverse_fill := true ) - enddef ; - def outlinefill = - hide(mfun_gt_outline_fill := true ) - enddef ; - def withshade primary c = - hide(def mfun_gt_shade = normalwithshade c enddef ; mfun_gt_shade_fill := true ) - enddef ; - def withfillcolor primary c = - hide(def mfun_gt_fill = withcolor c enddef ; mfun_gt_color_fill := true ) - enddef ; - def withdrawcolor primary c = - hide(def mfun_gt_draw = withcolor c enddef ; mfun_gt_color_draw := true ) - enddef ; - scratchpicture := nullpicture ; - addto scratchpicture doublepath origin rest ; % pre-roll - for i within scratchpicture : % Below here is a dirty tricky test! - if (urcorner dashpart i) = origin : - mfun_gt_outline_fill := false ; - fi ; - endfor ; - scratchpicture := nullpicture ; - readfile(data_mpy_file) ; - scratchpicture := (scratchpicture shifted -llcorner scratchpicture) scaled (1/10) ; - if not mfun_gt_color_draw and not mfun_gt_color_fill : - mfun_gt_color_draw := true ; - fi - if mfun_gt_shade_fill : - mfun_gt_color_draw := false ; - mfun_gt_color_fill := false ; - fi ; - currentpicture := figurepicture ; - if mfun_gt_shade_fill : - for i within scratchpicture : - if filled i : - addto currentpicture contour pathpart i _op_ rest mfun_gt_shade ; - fi ; - endfor ; - else : - if mfun_gt_color_draw and not mfun_gt_reverse_fill : - for i within scratchpicture : - if mfun_gt_color_fill and mfun_gt_outline_fill : - addto currentpicture doublepath pathpart i _op_ rest mfun_gt_fill dashed nullpicture ; - fi ; - if filled i : - addto currentpicture doublepath pathpart i _op_ rest mfun_gt_draw ; - fi ; - endfor ; - fi ; - if mfun_gt_color_fill : - for i within scratchpicture : - if filled i : - addto currentpicture contour pathpart i _op_ rest mfun_gt_fill withpen pencircle scaled 0 ; - fi ; - endfor ; - fi ; - if mfun_gt_color_draw and mfun_gt_reverse_fill : - for i within scratchpicture : - if filled i : - addto currentpicture doublepath pathpart i _op_ rest mfun_gt_draw ; - fi ; - endfor ; - fi ; - for i within scratchpicture : - if stroked i : - addto currentpicture doublepath pathpart i _op_ rest mfun_gt_draw ; - fi ; - endfor ; - fi ; - endgroup ; -enddef ; - -% and this is the new one: - -% boolean mfun_gt_color_fill ; -% boolean mfun_gt_color_draw ; -% boolean mfun_gt_shade_fill ; -% boolean mfun_gt_reverse_fill ; -% picture mfun_gt_picture ; - def mfun_gt_default = % somewhat compatible scaled 11.5 withpen pencircle scaled .1 enddef ; -def new_graphictext primary t = % use outlinetext instead +def graphictext primary t = % use outlinetext instead begingroup ; mfun_graphic_text_indeed(t) enddef ; @@ -345,9 +187,6 @@ def mfun_graphic_text_indeed(expr t) text rest = endgroup ; enddef ; -let graphictext = old_graphictext ; -%%% graphictext = new_graphictext ; % more than 10 times faster - % example % % beginfig (1) ; diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index f9f5e3877..131796757 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -18,8 +18,6 @@ boolean context_mlib ; context_mlib := true ; numeric LUATEXFUNCTIONALITY ; LUATEXFUNCTIONALITY := runscript("mp.print(LUATEXFUNCTIONALITY)") ; -boolean mfun_use_one_pass ; mfun_use_one_pass := runscript("mp.print(metapost.use_one_pass)") ; - %D Objects: vardef isobject expr p = @@ -194,39 +192,19 @@ boolean mfun_onetime_textext ; mfun_onetime_textext := false ; def notcached = withprescript "tx_cache=no" enddef ; -if mfun_use_one_pass : - - % todo: onetime - - rgbcolor mfun_tt_r ; +% todo: onetime - vardef rawtextext(expr s) = - if s = "" : - nullpicture - else : - mfun_tt_n := mfun_tt_n + 1 ; - mfun_tt_c := nullpicture ; - mfun_tt_o := nullpicture ; - addto mfun_tt_o doublepath origin _op_ ; % save drawoptions - mfun_tt_r := lua.mp.mf_some_text(mfun_tt_n,s) ; - addto mfun_tt_c doublepath unitsquare - xscaled wdpart mfun_tt_r - yscaled (htpart mfun_tt_r + dppart mfun_tt_r) - shifted (0,-dppart mfun_tt_r) - withprescript "mf_object=text" - withprescript "tx_index=" & decimal mfun_tt_n - withprescript "tx_color=" & colordecimals colorpart mfun_tt_o - ; - mfun_tt_c - fi - enddef ; +rgbcolor mfun_tt_r ; - vardef rawmadetext = +vardef rawtextext(expr s) = + if s = "" : + nullpicture + else : mfun_tt_n := mfun_tt_n + 1 ; mfun_tt_c := nullpicture ; mfun_tt_o := nullpicture ; addto mfun_tt_o doublepath origin _op_ ; % save drawoptions - mfun_tt_r := lua.mp.mf_made_text(mfun_tt_n) ; + mfun_tt_r := lua.mp.mf_some_text(mfun_tt_n,s) ; addto mfun_tt_c doublepath unitsquare xscaled wdpart mfun_tt_r yscaled (htpart mfun_tt_r + dppart mfun_tt_r) @@ -236,46 +214,25 @@ if mfun_use_one_pass : withprescript "tx_color=" & colordecimals colorpart mfun_tt_o ; mfun_tt_c - enddef ; - -else : - - vardef rawtextext(expr s) = % todo: avoid currentpicture - if s = "" : - mfun_onetime_textext := false ; - nullpicture - else : - mfun_tt_n := mfun_tt_n + 1 ; - mfun_tt_c := nullpicture ; - if mfun_trial_run : - mfun_tt_o := nullpicture ; - addto mfun_tt_o doublepath origin _op_ ; % save drawoptions - addto mfun_tt_c doublepath unitsquare - withprescript "mf_object=text" - withprescript "tx_number=" & decimal mfun_tt_n - withprescript "tx_stage=trial" - withprescript "tx_color=" & colordecimals colorpart mfun_tt_o - withpostscript s ; - if not mfun_onetime_textext : - addto mfun_tt_p also mfun_tt_c - withprescript "tx_global=yes" ; - fi ; - else : - mfun_tt_b := lua.mp.mf_tt_dimensions(mfun_tt_n) ; - addto mfun_tt_c doublepath unitsquare - xscaled wdpart mfun_tt_b - yscaled (htpart mfun_tt_b + dppart mfun_tt_b) - shifted (0,- dppart mfun_tt_b) - withprescript "mf_object=text" - withprescript "tx_number=" & decimal mfun_tt_n - withprescript "tx_stage=final" ; - fi ; - mfun_onetime_textext := false ; - mfun_tt_c - fi - enddef ; + fi +enddef ; -fi ; +vardef rawmadetext = + mfun_tt_n := mfun_tt_n + 1 ; + mfun_tt_c := nullpicture ; + mfun_tt_o := nullpicture ; + addto mfun_tt_o doublepath origin _op_ ; % save drawoptions + mfun_tt_r := lua.mp.mf_made_text(mfun_tt_n) ; + addto mfun_tt_c doublepath unitsquare + xscaled wdpart mfun_tt_r + yscaled (htpart mfun_tt_r + dppart mfun_tt_r) + shifted (0,-dppart mfun_tt_r) + withprescript "mf_object=text" + withprescript "tx_index=" & decimal mfun_tt_n + withprescript "tx_color=" & colordecimals colorpart mfun_tt_o + ; + mfun_tt_c +enddef ; vardef validtexbox(expr category, name) = if category == "" : @@ -504,75 +461,25 @@ enddef ; pair mfun_tt_z ; -if mfun_use_one_pass : - - vardef rawfmttext(text t) = - mfun_tt_n := mfun_tt_n + 1 ; - mfun_tt_c := nullpicture ; - mfun_tt_o := nullpicture ; - addto mfun_tt_o doublepath origin _op_ ; % save drawoptions - mfun_tt_r := lua.mp.mf_formatted_text(mfun_tt_n,t) ; - addto mfun_tt_c doublepath unitsquare - xscaled wdpart mfun_tt_r - yscaled (htpart mfun_tt_r + dppart mfun_tt_r) - shifted (0,-dppart mfun_tt_r) - withprescript "mf_object=text" - withprescript "tx_index=" & decimal mfun_tt_n - withprescript "tx_color=" & colordecimals colorpart mfun_tt_o - ; - for s = t : - if pair s : mfun_tt_z := s ; fi - endfor ; - mfun_tt_c - enddef ; - -else : - - vardef rawfmttext(text t) = % todo: avoid currentpicture - mfun_tt_n := mfun_tt_n + 1 ; - mfun_tt_c := nullpicture ; - if mfun_trial_run : - mfun_tt_o := nullpicture ; - addto mfun_tt_o doublepath origin _op_ ; % save drawoptions - addto mfun_tt_c doublepath unitsquare - withprescript "mf_object=text" - withprescript "tx_number=" & decimal mfun_tt_n - withprescript "tx_stage=trial" - withprescript "tx_color=" & colordecimals colorpart mfun_tt_o - % begin of fmt specific - withprescript "tx_type=format" - for s = t : - if string s : withpostscript "s:" & s - elseif numeric s : withpostscript "n:" & decimal s - elseif boolean s : withpostscript "b:" & if s : "true" else : "false" fi - elseif pair s : hide(mfun_tt_z := s ; ) - fi - endfor ; - % end of fmt specific - if not mfun_onetime_textext : - addto mfun_tt_p also mfun_tt_c - withprescript "tx_global=yes" ; - fi ; - else : - mfun_tt_b := lua.mp.mf_tt_dimensions(mfun_tt_n) ; - addto mfun_tt_c doublepath unitsquare - xscaled wdpart mfun_tt_b - yscaled (htpart mfun_tt_b + dppart mfun_tt_b) - shifted (0,- dppart mfun_tt_b) - withprescript "mf_object=text" - withprescript "tx_number=" & decimal mfun_tt_n - withprescript "tx_stage=final" ; - % begin of fmt specific - for s = t : - if pair s : mfun_tt_z := s ; fi - endfor ; - % end of fmt specific - fi ; - mfun_onetime_textext := false ; - mfun_tt_c - enddef ; - -fi ; +vardef rawfmttext(text t) = + mfun_tt_n := mfun_tt_n + 1 ; + mfun_tt_c := nullpicture ; + mfun_tt_o := nullpicture ; + addto mfun_tt_o doublepath origin _op_ ; % save drawoptions + mfun_tt_r := lua.mp.mf_formatted_text(mfun_tt_n,t) ; + addto mfun_tt_c doublepath unitsquare + xscaled wdpart mfun_tt_r + yscaled (htpart mfun_tt_r + dppart mfun_tt_r) + shifted (0,-dppart mfun_tt_r) + withprescript "mf_object=text" + withprescript "tx_index=" & decimal mfun_tt_n + withprescript "tx_color=" & colordecimals colorpart mfun_tt_o + ; + for s = t : + if pair s : mfun_tt_z := s ; fi + endfor ; + mfun_tt_c +enddef ; vardef thefmttext@#(text t) = mfun_tt_z := origin ; % initialization @@ -1113,38 +1020,17 @@ def withmask primary filename = withprescript "fg_mask=" & filename 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 wdpart mfun_tt_r - yscaled htpart 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 ; +vardef externalfigure primary filename = + mfun_tt_c := nullpicture ; + mfun_tt_r := lua.mp.mf_external_figure(filename) ; + addto mfun_tt_c doublepath unitsquare + xscaled wdpart mfun_tt_r + yscaled htpart mfun_tt_r + withprescript "mf_object=figure" + withprescript "fg_name=" & filename ; + ; + mfun_tt_c +enddef ; def figure primary filename = rawtextext("\externalfigure[" & filename & "]") @@ -1311,77 +1197,34 @@ def drawoutlinetext(expr o) = ) enddef ; -if mfun_use_one_pass : - - vardef outlinetext@# (expr t) text rest = - save kind ; string kind ; kind := str @# ; - currentoutlinetext := currentoutlinetext + 1 ; - def mfun_do_outline_options_d = enddef ; - def mfun_do_outline_options_f = enddef ; - def mfun_do_outline_options_r = enddef ; - image ( normaldraw image ( - % lua.mp.report("set outline text",currentoutlinetext); - 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 ; - elseif kind = "d" : - mfun_do_outline_text_set_d rest ; - elseif kind = "b" : - mfun_do_outline_text_set_b rest ; - elseif kind = "u" : - mfun_do_outline_text_set_f rest ; - elseif kind = "r" : - mfun_do_outline_text_set_r rest ; - elseif kind = "p" : - mfun_do_outline_text_set_p ; - else : - mfun_do_outline_text_set_n rest ; - fi ; - lua.mp.mf_get_outline_text(currentoutlinetext) ; - ) mfun_do_outline_options_r ; ) - enddef ; - -else : - - vardef outlinetext@# (expr t) text rest = - save kind ; string kind ; kind := str @# ; - currentoutlinetext := currentoutlinetext + 1 ; - def mfun_do_outline_options_d = enddef ; - def mfun_do_outline_options_f = enddef ; - def mfun_do_outline_options_r = enddef ; - image ( normaldraw image ( - if mfun_trial_run : - % lua.mp.report("set outline text",currentoutlinetext); - normaldraw unitsquare - withprescript "mf_object=outline" - withprescript "ot_stage=trial" - withprescript "ot_index=" & decimal currentoutlinetext - withprescript "ot_kind=" & kind - withpostscript t ; - else : - % lua.mp.report("get outline text",currentoutlinetext); - if kind = "f" : - mfun_do_outline_text_set_f rest ; - elseif kind = "d" : - mfun_do_outline_text_set_d rest ; - elseif kind = "b" : - mfun_do_outline_text_set_b rest ; - elseif kind = "u" : - mfun_do_outline_text_set_f rest ; - elseif kind = "r" : - mfun_do_outline_text_set_r rest ; - elseif kind = "p" : - mfun_do_outline_text_set_p ; - else : - mfun_do_outline_text_set_n rest ; - fi ; - lua.mp.mf_get_outline_text(currentoutlinetext) ; - fi ; - ) mfun_do_outline_options_r ; ) - enddef ; - -fi ; +vardef outlinetext@# (expr t) text rest = + save kind ; string kind ; kind := str @# ; + currentoutlinetext := currentoutlinetext + 1 ; + def mfun_do_outline_options_d = enddef ; + def mfun_do_outline_options_f = enddef ; + def mfun_do_outline_options_r = enddef ; + image ( normaldraw image ( + % lua.mp.report("set outline text",currentoutlinetext); + 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 ; + elseif kind = "d" : + mfun_do_outline_text_set_d rest ; + elseif kind = "b" : + mfun_do_outline_text_set_b rest ; + elseif kind = "u" : + mfun_do_outline_text_set_f rest ; + elseif kind = "r" : + mfun_do_outline_text_set_r rest ; + elseif kind = "p" : + mfun_do_outline_text_set_p ; + else : + mfun_do_outline_text_set_n rest ; + fi ; + lua.mp.mf_get_outline_text(currentoutlinetext) ; + ) mfun_do_outline_options_r ; ) +enddef ; % A few helpers: diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv index 01ea2521b..2cdb5fb39 100644 --- a/metapost/context/base/mpiv/mp-tool.mpiv +++ b/metapost/context/base/mpiv/mp-tool.mpiv @@ -3594,3 +3594,11 @@ def drawdot expr p = ) fi enddef ; + +% vardef textlength(text t) = +% save n ; n := 0 ; +% for i = t : +% n := n + 1 ; +% endfor; +% n +% enddef; -- cgit v1.2.3