summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-04-13 15:51:39 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-04-13 15:51:39 +0200
commit25fcad7435f56cdce2658336909f4da6a65589c0 (patch)
treec23d5d04a7e86c7ddc2ebeca06d3de63ebdc806e /metapost
parent1e5d7f41ddede5e6400a2a7762032823d3545df4 (diff)
downloadcontext-25fcad7435f56cdce2658336909f4da6a65589c0.tar.gz
2018-04-13 15:02:00
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mpiv/metafun.mpiv1
-rw-r--r--metapost/context/base/mpiv/mp-blob.mpiv118
2 files changed, 119 insertions, 0 deletions
diff --git a/metapost/context/base/mpiv/metafun.mpiv b/metapost/context/base/mpiv/metafun.mpiv
index 818fd7c56..fa43d3460 100644
--- a/metapost/context/base/mpiv/metafun.mpiv
+++ b/metapost/context/base/mpiv/metafun.mpiv
@@ -38,6 +38,7 @@ input "mp-func.mpiv" ; % under construction
input "mp-node.mpiv" ; % relatively small so preloaded
input "mp-apos.mpiv" ;
input "mp-abck.mpiv" ;
+input "mp-blob.mpiv" ;
string metafunversion ; metafunversion =
"metafun iv" & " " &
diff --git a/metapost/context/base/mpiv/mp-blob.mpiv b/metapost/context/base/mpiv/mp-blob.mpiv
new file mode 100644
index 000000000..5bd0a6a75
--- /dev/null
+++ b/metapost/context/base/mpiv/mp-blob.mpiv
@@ -0,0 +1,118 @@
+%D \module
+%D [ file=mp-blob.mpiv,
+%D version=2018.04.08,
+%D title=\CONTEXT\ \METAPOST\ graphics,
+%D subtitle=Blobs,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+%D This is a follow up on good old \type {meta-imp-txt}.
+
+if known context_blob : endinput ; fi ;
+
+boolean context_blob ; context_blob := true ;
+
+numeric mfun_blob_n ; mfun_blob_n := 0 ;
+picture mfun_blob_c ;
+color mfun_blob_b ;
+
+def mfun_reset_tex_blobs =
+ mfun_blob_n := 0 ;
+ mfun_blob_c := nullpicture ;
+enddef ;
+
+extra_endfig := extra_endfig & "mfun_reset_tex_blobs ; " ;
+
+vardef mfun_inject_blob(expr n) =
+ mfun_blob_c := nullpicture ;
+ mfun_blob_b := lua.mp.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 "tb_stage=inject"
+ withprescript "tb_blob=" & decimal lua.mp.blob_index(mfun_blob_n,n) ;
+ mfun_blob_c
+enddef ;
+
+% An example of usage:
+
+newinternal followtextalternative ; followtextalternative := 1 ;
+newinternal tracingfollowtext ; tracingfollowtext := 0 ;
+newinternal autoscaleupfollowtext ; autoscaleupfollowtext := 2 ;
+newinternal autoscaledownfollowtext ; autoscaledownfollowtext := 0 ;
+
+vardef followtext(expr txt, pth) =
+ draw image (
+ mfun_blob_n := mfun_blob_n + 1 ;
+ if mfun_trial_run :
+ draw fullcircle scaled 100bp
+ 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.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) ;
+ 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.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 "ft_stage=final"
+ withprescript "ft_category=" & decimal mfun_blob_n ;
+ fi ;
+ ) ;
+enddef ;