diff options
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mpiv/mp-bare.mpiv | 164 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-blob.mpiv | 5 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-grph.mpiv | 1 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-mlib.mpiv | 54 |
4 files changed, 168 insertions, 56 deletions
diff --git a/metapost/context/base/mpiv/mp-bare.mpiv b/metapost/context/base/mpiv/mp-bare.mpiv index c6194b1ee..e995556c1 100644 --- a/metapost/context/base/mpiv/mp-bare.mpiv +++ b/metapost/context/base/mpiv/mp-bare.mpiv @@ -14,35 +14,7 @@ if known context_bare : endinput ; fi ; boolean context_bare ; context_bare := true ; -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 ; - -extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ; -extra_endfig := "mfun_flush_tex_texts ; mfun_reset_tex_texts ; " & extra_endfig ; +boolean mfun_use_one_pass ; mfun_use_one_pass := runscript("mp.print(metapost.use_one_pass)") ; vardef colordecimals primary c = if cmykcolor c : @@ -54,34 +26,122 @@ vardef colordecimals primary c = fi 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 : +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 ; + + 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 ; + + 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 - withprescript "tx_number=" & decimal mfun_tt_n - withprescript "tx_stage=trial" + 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 - 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 ; + + 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 - fi -enddef ; + 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 ; + +extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ; +extra_endfig := "mfun_flush_tex_texts ; mfun_reset_tex_texts ; " & extra_endfig ; primarydef str infont name = % nasty hack if name = "" : diff --git a/metapost/context/base/mpiv/mp-blob.mpiv b/metapost/context/base/mpiv/mp-blob.mpiv index d2bdf741a..1d8a205f1 100644 --- a/metapost/context/base/mpiv/mp-blob.mpiv +++ b/metapost/context/base/mpiv/mp-blob.mpiv @@ -37,6 +37,7 @@ if mfun_use_one_pass : 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) ; mfun_blob_c enddef ; @@ -50,6 +51,7 @@ else : 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) ; mfun_blob_c @@ -125,6 +127,7 @@ if mfun_use_one_pass : 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 ; ) @@ -137,6 +140,7 @@ else : 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 ; @@ -196,6 +200,7 @@ else : 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 ; diff --git a/metapost/context/base/mpiv/mp-grph.mpiv b/metapost/context/base/mpiv/mp-grph.mpiv index 2fc000b9d..a2f710881 100644 --- a/metapost/context/base/mpiv/mp-grph.mpiv +++ b/metapost/context/base/mpiv/mp-grph.mpiv @@ -168,6 +168,7 @@ else : 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 diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index 99928c81c..403b2d3ae 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -20,6 +20,12 @@ numeric LUATEXFUNCTIONALITY ; LUATEXFUNCTIONALITY := runscript("mp.print(LUATEXF boolean mfun_use_one_pass ; mfun_use_one_pass := runscript("mp.print(metapost.use_one_pass)") ; +%D Objects: + +vardef isobject expr p = + lua.mp.isobject(prescriptpart p) +enddef ; + %D Color and transparency %D %D Separable: @@ -201,6 +207,7 @@ if mfun_use_one_pass : 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 ; @@ -218,6 +225,7 @@ if mfun_use_one_pass : 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 ; @@ -237,6 +245,7 @@ else : 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 @@ -251,6 +260,7 @@ else : xscaled redpart mfun_tt_b yscaled (greenpart mfun_tt_b + bluepart mfun_tt_b) shifted (0,- bluepart mfun_tt_b) + withprescript "mf_object=text" withprescript "tx_number=" & decimal mfun_tt_n withprescript "tx_stage=final" ; fi ; @@ -281,6 +291,7 @@ vardef rawtexbox(expr category, name) = xscaled redpart mfun_tt_b yscaled (greenpart mfun_tt_b + bluepart mfun_tt_b) shifted (0,- bluepart mfun_tt_b) + withprescript "mf_object=box" withprescript "bx_category=" & if numeric category : decimal fi category withprescript "bx_name=" & if numeric name : decimal fi name ; fi @@ -424,8 +435,6 @@ enddef ; plain_compatibility_data := plain_compatibility_data & "save label, thelabel ;" & "useplainlabels ;" ; -% next comes own own: - vardef thetextext@#(expr p,z) = % interim labeloffset := textextoffset ; if string p : @@ -464,6 +473,7 @@ if mfun_use_one_pass : 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 ; @@ -484,6 +494,7 @@ else : 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 @@ -507,6 +518,7 @@ else : xscaled redpart mfun_tt_b yscaled (greenpart mfun_tt_b + bluepart mfun_tt_b) shifted (0,- bluepart mfun_tt_b) + withprescript "mf_object=text" withprescript "tx_number=" & decimal mfun_tt_n withprescript "tx_stage=final" ; % begin of fmt specific @@ -557,11 +569,44 @@ vardef texbox@#(expr category, name) = % no draw here thetexbox@#(category,name,origin) enddef ; +% vardef thelabel@#(expr p,z) = +% if string p : +% thelabel@#(rawtextext("\definedfont[" & defaultfont & "]" & p) scaled defaultscale,z) +% else : +% p shifted (z + labeloffset*mfun_laboff@# - (mfun_labxf@#*lrcorner p + mfun_labyf@#*ulcorner p + (1-mfun_labxf@#-mfun_labyf@#)*llcorner p)) +% fi +% enddef; + +vardef theoffset@#(expr z) = + if pair z : + z + elseif path z : + if mfun_laboff@# = origin : + center z + elseif cycle z : + ((center z )-- + (mfun_labxf@#*ulcorner z + mfun_labyf@#*lrcorner z + (1-mfun_labxf@#-mfun_labyf@#)*urcorner z)) + intersectionpoint z + else : + ((center z)-- + (mfun_labxf@#*ulcorner z + mfun_labyf@#*lrcorner z + (1-mfun_labxf@#-mfun_labyf@#)*urcorner z)) + intersectionpoint (z--cycle) + fi + else : % picture + (mfun_labxf@#*ulcorner z + mfun_labyf@#*lrcorner z + (1-mfun_labxf@#-mfun_labyf@#)*urcorner z) + fi +enddef; + vardef thelabel@#(expr p,z) = - if string p : + if numeric p : + thelabel@#(decimal p) + elseif string p : thelabel@#(rawtextext("\definedfont[" & defaultfont & "]" & p) scaled defaultscale,z) else : - p shifted (z + labeloffset*mfun_laboff@# - (mfun_labxf@#*lrcorner p + mfun_labyf@#*ulcorner p + (1-mfun_labxf@#-mfun_labyf@#)*llcorner p)) + p shifted (theoffset@#(z) + + labeloffset*mfun_laboff@# + - (mfun_labxf@#*lrcorner p + mfun_labyf@#*ulcorner p + + (1-mfun_labxf@#-mfun_labyf@#)*llcorner p)) fi enddef; @@ -1235,6 +1280,7 @@ else : 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 |