diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2015-01-22 14:15:05 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2015-01-22 14:15:05 +0100 |
commit | 442277c17f9171ecb94d4d974d3f16a07e1df4b1 (patch) | |
tree | 162e85aab26c05e84c947eb8143749e787a51ba2 /metapost | |
parent | f5d6cbdeba9b2e7e63997df429eb796bb871a7a2 (diff) | |
download | context-442277c17f9171ecb94d4d974d3f16a07e1df4b1.tar.gz |
2015-01-22 13:28:00
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/metafun.mpiv | 1 | ||||
-rw-r--r-- | metapost/context/base/mp-mlib.mpiv | 16 | ||||
-rw-r--r-- | metapost/context/base/mp-tool.mpiv | 55 |
3 files changed, 62 insertions, 10 deletions
diff --git a/metapost/context/base/metafun.mpiv b/metapost/context/base/metafun.mpiv index 095b84b0e..a2ef05306 100644 --- a/metapost/context/base/metafun.mpiv +++ b/metapost/context/base/metafun.mpiv @@ -47,6 +47,7 @@ let normalend = end ; if known mplib : def end = ; message "" ; message metafunversion ; message "" ; endinput ; enddef ; + def bye = ; message "" ; message metafunversion ; message "" ; endinput ; enddef ; else : def end = ; message "" ; message metafunversion ; message "" ; normalend ; enddef ; fi ; diff --git a/metapost/context/base/mp-mlib.mpiv b/metapost/context/base/mp-mlib.mpiv index ac1bf7437..a3eec2818 100644 --- a/metapost/context/base/mp-mlib.mpiv +++ b/metapost/context/base/mp-mlib.mpiv @@ -175,8 +175,8 @@ extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ; % see mp-keep.mpiv for older code -vardef rawtextext(expr str) = % todo: avoid currentpicture - if str = "" : +vardef rawtextext(expr s) = % todo: avoid currentpicture + if s = "" : nullpicture else : mfun_tt_n := mfun_tt_n + 1 ; @@ -188,7 +188,7 @@ vardef rawtextext(expr str) = % todo: avoid currentpicture withprescript "tx_number=" & decimal mfun_tt_n withprescript "tx_stage=trial" withprescript "tx_color=" & colordecimals colorpart mfun_tt_o - withpostscript str ; + withpostscript s ; addto mfun_tt_p also mfun_tt_c ; elseif known mfun_tt_d[mfun_tt_n] : addto mfun_tt_c doublepath unitsquare @@ -375,11 +375,11 @@ enddef ; let normalinfont = infont ; -primarydef str infont name = % nasty hack +primarydef s infont name = % nasty hack if name = "" : - textext(str) + textext(s) else : - textext("\definedfont[" & name & "]" & str) + textext("\definedfont[" & name & "]" & s) fi enddef ; @@ -722,8 +722,8 @@ extra_endfig := extra_endfig & "mfun_reset_tex_texts ; " ; % Bonus -vardef verbatim(expr str) = - ditto & "\detokenize{" & str & "}" & ditto +vardef verbatim(expr s) = + ditto & "\detokenize{" & s & "}" & ditto enddef ; % New diff --git a/metapost/context/base/mp-tool.mpiv b/metapost/context/base/mp-tool.mpiv index 8af2693cd..b82910f6b 100644 --- a/metapost/context/base/mp-tool.mpiv +++ b/metapost/context/base/mp-tool.mpiv @@ -2516,21 +2516,72 @@ enddef ; % ) % enddef ; +vardef mfun_snapped(expr p, s) = + if p < 0 : - ( - else : ( fi p div s) * s % the less tokens the better +enddef ; + +vardef mfun_applied(expr p, s)(suffix a) = + if path p : + if pair s : + for i=0 upto length(p)-1 : + (a(xpart point i of p,xpart s),a(ypart point i of p,ypart s)) -- + endfor + if cycle p : + cycle + else : + (a(xpart point length(p) of p,xpart s),a(ypart point length(p) of p,ypart s)) + fi + else : + for i=0 upto length(p)-1 : + (a(xpart point i of p,s),a(ypart point i of p,s)) -- + endfor + if cycle p : + cycle + else : + (a(xpart point length(p) of p,s),a(ypart point length(p) of p,s)) + fi + fi + elseif pair p : + if pair s : + (a(xpart p,xpart s),a(ypart p,ypart s)) + else : + (a(xpart p,s),a(ypart p,s)) + fi + elseif cmykcolor p : + (a(cyanpart p,s),a(magentapart p,s),a(yellowpart p,s),a(blackpart p,s)) + elseif rgbcolor p : + (a(redpart p,s),a(greenpart p,s),a(bluepart p,s)) + elseif graycolor p : + a(p,s) + elseif numeric p : + a(p,s) + else + p + fi +enddef ; + +primarydef p snapped s = + mfun_applied(p,s)(mfun_snapped) % so we can play with variants +enddef ; + %D New helpers: +newinternal charscale ; charscale := 1 ; % persistent so one needs to 'reset' it to 0 or 1 + def beginglyph(expr unicode, width, height, depth) = beginfig(unicode) ; % the number is irrelevant charcode := unicode ; charwd := width ; charht := height ; chardp := depth ; + % charscale := 1 ; % can be set for a whole font, so no reset here enddef ; def endglyph = setbounds currentpicture to (boundingbox unitsquare xscaled charwd yscaled (charht + chardp) shifted (0,-chardp)) ; - if known charscale : + if known charscale : if (charscale > 0) and (charscale <> 1) : currentpicture := currentpicture scaled charscale ; - fi ; + fi ; fi ; endfig ; enddef ; |