summaryrefslogtreecommitdiff
path: root/metapost/context/base/mpiv/mp-mlib.mpiv
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-08-19 01:38:26 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-08-19 01:38:26 +0200
commited42bd4c79946716033bf5dbedbd54bbe81f49e8 (patch)
treea3d63d74f0e07f799c538eb04096195b6b6d4631 /metapost/context/base/mpiv/mp-mlib.mpiv
parent30b3a925bfc1857a31e23d9b17b8da0be572d02a (diff)
downloadcontext-ed42bd4c79946716033bf5dbedbd54bbe81f49e8.tar.gz
2016-08-19 00:35:00
Diffstat (limited to 'metapost/context/base/mpiv/mp-mlib.mpiv')
-rw-r--r--metapost/context/base/mpiv/mp-mlib.mpiv71
1 files changed, 70 insertions, 1 deletions
diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv
index ea148d0c1..add58a43b 100644
--- a/metapost/context/base/mpiv/mp-mlib.mpiv
+++ b/metapost/context/base/mpiv/mp-mlib.mpiv
@@ -429,6 +429,75 @@ vardef onetimetextext@#(expr p) = % no draw here
thetextext@#(p,origin)
enddef ;
+% formatted text
+
+pair mfun_tt_z ;
+
+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 "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.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)
+ shifted (0,- bluepart mfun_tt_b)
+ 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 ;
+
+vardef thefmttext@#(text t) =
+ mfun_tt_z := origin ;
+ save p ; picture p ; p := rawfmttext(t) ;
+ p
+ if (mfun_labtype@# >= 10) :
+ shifted (0,ypart center p)
+ fi
+ shifted (mfun_tt_z + textextoffset*mfun_laboff@# - (mfun_labxf@#*lrcorner p + mfun_labyf@#*ulcorner p + (1-mfun_labxf@#-mfun_labyf@#)*llcorner p))
+enddef ;
+
+vardef fmttext@#(text t) = % no draw here
+ thefmttext@#(t,origin)
+enddef ;
+
+% or just: def fmttext = thefmttext enddef ;
+
+vardef onetimefmttext@#(text t) = % no draw here
+ mfun_onetime_textext := true ;
+ thefmttext@#(t,origin)
+enddef ;
+
+% so much for formatted text
+
vardef thetexbox@#(expr category, name, z) =
save p ; picture p ; p := rawtexbox(category,name) ;
p
@@ -1584,7 +1653,7 @@ vardef formatted(expr f, x) = textext(varfmt(f, x)) enddef ;
% def varfmt = formatted enddef ; % old
-def fmttext = lua.mp.formatted enddef ;
+% def fmttext = lua.mp.formatted enddef ;
% new