summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/metapost/context/base/mp-mlib.mpiv')
-rw-r--r--Master/texmf-dist/metapost/context/base/mp-mlib.mpiv566
1 files changed, 355 insertions, 211 deletions
diff --git a/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv b/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv
index 56815028e8f..b19f47f1e55 100644
--- a/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv
+++ b/Master/texmf-dist/metapost/context/base/mp-mlib.mpiv
@@ -60,32 +60,70 @@ def namedcolor (expr n) =
withprescript "sp_name=" & n
enddef ;
+% def spotcolor(expr n, v) =
+% 1
+% withprescript "sp_type=spot"
+% withprescript "sp_name=" & n
+% withprescript "sp_value=" & (if numeric v : decimal v else : v fi)
+% enddef ;
+%
+% def multitonecolor(expr name, fractions, components, value) =
+% 1
+% withprescript "sp_type=multitone"
+% withprescript "sp_name=" & name
+% withprescript "sp_fractions=" & decimal fractions
+% withprescript "sp_components=" & components
+% withprescript "sp_value=" & value
+% enddef ;
+
def spotcolor(expr n, v) =
1
withprescript "sp_type=spot"
withprescript "sp_name=" & n
- withprescript "sp_value=" & v
+ withprescript "sp_value=" & colordecimals v
enddef ;
-def multitonecolor(expr name, fractions, components, value) =
+def multitonecolor(expr name)(text t) =
1
withprescript "sp_type=multitone"
- withprescript "sp_name=" & name
- withprescript "sp_fractions=" & decimal fractions
- withprescript "sp_components=" & components
- withprescript "sp_value=" & value
+ withprescript "sp_name=" & name
+ withprescript "sp_value=" & colordecimalslist(t)
enddef ;
-def transparent(expr alternative, transparency)(text c) =
+def transparent(expr a, t)(text c) = % use withtransparency instead
1 % this permits withcolor x intoshade y
- withprescript "tr_alternative=" & decimal transparency_alternative_to_number(alternative)
- withprescript "tr_transparency=" & decimal transparency
+ withprescript "tr_alternative=" & decimal transparency_alternative_to_number(a)
+ withprescript "tr_transparency=" & decimal t
withcolor c
enddef ;
-def withtransparency(expr alternative, transparency) =
- withprescript "tr_alternative=" & decimal transparency_alternative_to_number(alternative)
- withprescript "tr_transparency=" & decimal transparency
+% def withtransparency(expr a, t) =
+% withprescript "tr_alternative=" & decimal transparency_alternative_to_number(a)
+% withprescript "tr_transparency=" & decimal t
+% enddef ;
+
+let transparency = pair ;
+
+% def withtransparency expr t =
+% withprescript "tr_alternative=" & decimal transparency_alternative_to_number(xpart t)
+% withprescript "tr_transparency=" & decimal ypart t
+% enddef ;
+%
+% withtransparency (1,.5)
+% withtransparency ("normal",.5)
+
+def withtransparency (expr t) (text rest) =
+ if pair t :
+ withprescript "tr_alternative=" & decimal transparency_alternative_to_number(xpart t)
+ withprescript "tr_transparency=" & decimal ypart t
+ else :
+ mfun_with_transparency (transparency_alternative_to_number(t))
+ fi rest
+enddef ;
+
+def mfun_with_transparency (expr a) expr t =
+ withprescript "tr_alternative=" & decimal a
+ withprescript "tr_transparency=" & decimal t
enddef ;
def cmyk(expr c, m, y, k) = % provided for downward compability
@@ -96,7 +134,8 @@ enddef ;
newinternal textextoffset ; textextoffset := 0 ;
-numeric mfun_tt_w[], mfun_tt_h[], mfun_tt_d[] ; % we can consider using colors (less hash space)
+%%%%%%% mfun_tt_w[], mfun_tt_h[], mfun_tt_d[] ; % we can consider using colors (less hash space)
+color mfun_tt_b ;
numeric mfun_tt_n ; mfun_tt_n := 0 ;
picture mfun_tt_p ; mfun_tt_p := nullpicture ;
picture mfun_tt_o ; mfun_tt_o := nullpicture ;
@@ -135,44 +174,10 @@ extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ;
% flush twice: once in location in order to pick up e.g. color properties,
% and once at the end because we need to flush missing ones.
-% vardef rawtextext(expr str) =
-% if str = "" :
-% nullpicture
-% elseif mfun_trial_run :
-% mfun_tt_n := mfun_tt_n + 1 ;
-% mfun_tt_o := image(draw origin) ; % save drawoptions
-% addto mfun_tt_p doublepath unitsquare
-% withprescript "tx_number=" & decimal mfun_tt_n
-% withprescript "tx_stage=extra"
-% withpostscript str ;
-% image (
-% addto currentpicture doublepath unitsquare
-% withprescript "tx_number=" & decimal mfun_tt_n
-% withprescript "tx_stage=trial"
-% withprescript "tx_color=" & colordecimals colorpart mfun_tt_o
-% withpostscript str
-% ; )
-% else :
-% mfun_tt_n := mfun_tt_n + 1 ;
-% if known mfun_tt_d[mfun_tt_n] :
-% image (
-% addto currentpicture doublepath unitsquare
-% xscaled mfun_tt_w[mfun_tt_n]
-% yscaled (mfun_tt_h[mfun_tt_n] + mfun_tt_d[mfun_tt_n])
-% withprescript "tx_number=" & decimal mfun_tt_n
-% withprescript "tx_stage=final"
-% % withpostscript str ; % for tracing
-% ; ) shifted (0,-mfun_tt_d[mfun_tt_n])
-% else :
-% image (
-% addto currentpicture doublepath unitsquare
-% ; )
-% fi
-% fi
-% enddef ;
+% 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 ;
@@ -180,15 +185,12 @@ extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ;
% if mfun_trial_run :
% mfun_tt_o := nullpicture ;
% addto mfun_tt_o doublepath origin _op_ ; % save drawoptions
-% addto mfun_tt_p doublepath unitsquare
-% withprescript "tx_number=" & decimal mfun_tt_n
-% withprescript "tx_stage=extra"
-% withpostscript str ;
% 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 ;
+% withpostscript s ;
+% 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]
@@ -203,8 +205,8 @@ extra_beginfig := extra_beginfig & "mfun_reset_tex_texts ;" ;
% fi
% enddef ;
-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 ;
@@ -216,17 +218,16 @@ 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] :
+ else :
+ mfun_tt_b := lua.mp.tt_dimensions(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])
+ 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" ;
- else :
- addto mfun_tt_c doublepath unitsquare ; % unitpicture
fi ;
mfun_tt_c
fi
@@ -234,7 +235,10 @@ enddef ;
% More text
-defaultfont := "Mono" ; % was cmr10, could be lmmono10-regular, but is fed into context anyway
+defaultfont := "Mono" ;
+defaultscale := 1 ;
+
+extra_beginfig := extra_beginfig & "defaultscale:=1;" ;
vardef fontsize expr name =
save size ; numeric size ;
@@ -403,19 +407,171 @@ 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 ;
+% Helper
+
+string mfun_prescript_separator ; mfun_prescript_separator := char(13) ;
+
% Shades
-newinternal shadefactor ; shadefactor := 1 ;
-pair shadeoffset ; shadeoffset := origin ;
-boolean trace_shades ; trace_shades := false ;
+% for while we had this:
+
+newinternal shadefactor ; shadefactor := 1 ; % currently obsolete
+pair shadeoffset ; shadeoffset := origin ; % currently obsolete
+boolean trace_shades ; trace_shades := false ; % still there
+
+% def withlinearshading (expr a, b) =
+% withprescript "sh_type=linear"
+% withprescript "sh_domain=0 1"
+% withprescript "sh_factor=" & decimal shadefactor
+% withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset)
+% withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset)
+% enddef ;
+%
+% def withcircularshading (expr a, b, ra, rb) =
+% withprescript "sh_type=circular"
+% withprescript "sh_domain=0 1"
+% withprescript "sh_factor=" & decimal shadefactor
+% withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset)
+% withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset)
+% withprescript "sh_radius_a=" & decimal ra
+% withprescript "sh_radius_b=" & decimal rb
+% enddef ;
+%
+% def withshading (expr how)(text rest) =
+% if how = "linear" :
+% withlinearshading(rest)
+% elseif how = "circular" :
+% withcircularshading(rest)
+% else :
+% % nothing
+% fi
+% enddef ;
+%
+% def withfromshadecolor expr t =
+% withprescript "sh_color=into"
+% withprescript "sh_color_a=" & colordecimals t
+% enddef ;
+
+% def withtoshadecolor expr t =
+% withprescript "sh_color=into"
+% withprescript "sh_color_b=" & colordecimals t
+% enddef ;
+
+% but this is nicer
+
+path mfun_shade_path ;
+
+primarydef p withshademethod m =
+ hide(mfun_shade_path := p ;)
+ p
+ withprescript "sh_domain=0 1"
+ withprescript "sh_color=into"
+ withprescript "sh_color_a=" & colordecimals white
+ withprescript "sh_color_b=" & colordecimals black
+ if m = "linear" :
+ withprescript "sh_type=linear"
+ withprescript "sh_factor=1"
+ withprescript "sh_center_a=" & ddecimal llcorner p
+ withprescript "sh_center_b=" & ddecimal urcorner p
+ else :
+ withprescript "sh_type=circular"
+ withprescript "sh_factor=1.2"
+ withprescript "sh_center_a=" & ddecimal center p
+ withprescript "sh_center_b=" & ddecimal center p
+ withprescript "sh_radius_a=" & decimal 0
+ withprescript "sh_radius_b=" & decimal ( max (
+ (xpart center p - xpart llcorner p) ++ (ypart center p - ypart llcorner p),
+ (xpart center p - xpart ulcorner p) ++ (ypart ulcorner p - ypart center p),
+ (xpart lrcorner p - xpart center p) ++ (ypart center p - ypart lrcorner p),
+ (xpart urcorner p - xpart center p) ++ (ypart urcorner p - ypart center p)
+ ) )
+ fi
+enddef ;
+
+def withshadevector expr a =
+ withprescript "sh_center_a=" & ddecimal (point xpart a of mfun_shade_path)
+ withprescript "sh_center_b=" & ddecimal (point ypart a of mfun_shade_path)
+enddef ;
+
+def withshadecenter expr a =
+ withprescript "sh_center_a=" & ddecimal (
+ center mfun_shade_path shifted (
+ xpart a * bbwidth (mfun_shade_path)/2,
+ ypart a * bbheight(mfun_shade_path)/2
+ )
+ )
+enddef ;
+
+def withshadedomain expr d =
+ withprescript "sh_domain=" & ddecimal d
+enddef ;
+
+def withshadefactor expr f =
+ withprescript "sh_factor=" & decimal f
+enddef ;
+
+def withshadecolors (expr a, b) =
+ withprescript "sh_color=into"
+ withprescript "sh_color_a=" & colordecimals a
+ withprescript "sh_color_b=" & colordecimals b
+enddef ;
+
+primarydef a shadedinto b = % withcolor red shadedinto green
+ 1 % does not work with transparency
+ withprescript "sh_color=into"
+ withprescript "sh_color_a=" & colordecimals a
+ withprescript "sh_color_b=" & colordecimals b
+enddef ;
+
+primarydef p withshade sc =
+ p withprescript mfun_defined_cs_pre[sc]
+enddef ;
+
+def defineshade suffix s =
+ mfun_defineshade(str s)
+enddef ;
+
+def mfun_defineshade (expr s) text t =
+ expandafter def scantokens s = t enddef ;
+enddef ;
+
+def shaded text s =
+ s
+enddef ;
+
+% Old macros:
+
+def withcircularshade (expr a, b, ra, rb, ca, cb) =
+ withprescript "sh_type=circular"
+ withprescript "sh_domain=0 1"
+ withprescript "sh_factor=1"
+ withprescript "sh_color_a=" & colordecimals ca
+ withprescript "sh_color_b=" & colordecimals cb
+ withprescript "sh_center_a=" & ddecimal a % (a shifted shadeoffset)
+ withprescript "sh_center_b=" & ddecimal b % (b shifted shadeoffset)
+ withprescript "sh_radius_a=" & decimal ra
+ withprescript "sh_radius_b=" & decimal rb
+enddef ;
+
+def withlinearshade (expr a, b, ca, cb) =
+ withprescript "sh_type=linear"
+ withprescript "sh_domain=0 1"
+ withprescript "sh_factor=1"
+ withprescript "sh_color_a=" & colordecimals ca
+ withprescript "sh_color_b=" & colordecimals cb
+ withprescript "sh_center_a=" & ddecimal a % (a shifted shadeoffset)
+ withprescript "sh_center_b=" & ddecimal b % (b shifted shadeoffset)
+enddef ;
+
+% replaced (obsolete):
def set_linear_vector (suffix a,b)(expr p,n) =
if (n=1) : a := llcorner p ; b := urcorner p ;
@@ -430,7 +586,7 @@ def set_linear_vector (suffix a,b)(expr p,n) =
fi ;
enddef ;
-def set_circular_vector (suffix ab, r)(expr p,n) =
+def set_circular_vector (suffix ab,r)(expr p,n) =
if (n=1) : ab := llcorner p ;
elseif (n=2) : ab := lrcorner p ;
elseif (n=3) : ab := urcorner p ;
@@ -453,7 +609,7 @@ enddef ;
def linear_shade (expr p, n, ca, cb) =
begingroup ;
- save a, b, sh ; pair a, b ;
+ save a, b ; pair a, b ;
set_linear_vector(a,b)(p,n) ;
fill p withlinearshade(a,b,ca,cb) ;
if trace_shades :
@@ -462,43 +618,19 @@ def linear_shade (expr p, n, ca, cb) =
endgroup ;
enddef ;
-def withcircularshade (expr a, b, ra, rb, ca, cb) =
- withprescript "sh_type=circular"
- withprescript "sh_domain=0 1"
- withprescript "sh_factor=" & decimal shadefactor
- withprescript "sh_color_a=" & colordecimals ca
- withprescript "sh_color_b=" & colordecimals cb
- withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset)
- withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset)
- withprescript "sh_radius_a=" & decimal ra
- withprescript "sh_radius_b=" & decimal rb
-enddef ;
-
-def withlinearshade (expr a, b, ca, cb) =
- withprescript "sh_type=linear"
- withprescript "sh_domain=0 1"
- withprescript "sh_factor=" & decimal shadefactor
- withprescript "sh_color_a=" & colordecimals ca
- withprescript "sh_color_b=" & colordecimals cb
- withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset)
- withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset)
-enddef ;
-
string mfun_defined_cs_pre[] ; numeric mfun_defined_cs ; mfun_defined_cs := 0 ;
-string mfun_prescript_separator ; mfun_prescript_separator := char(13) ;
-
vardef define_circular_shade (expr a, b, ra, rb, ca, cb) =
mfun_defined_cs := mfun_defined_cs + 1 ;
mfun_defined_cs_pre[mfun_defined_cs] := "sh_type=circular"
- & mfun_prescript_separator & "sh_domain=0 1"
- & mfun_prescript_separator & "sh_factor=" & decimal shadefactor
- & mfun_prescript_separator & "sh_color_a=" & colordecimals ca
- & mfun_prescript_separator & "sh_color_b=" & colordecimals cb
- & mfun_prescript_separator & "sh_center_a=" & ddecimal (a shifted shadeoffset)
- & mfun_prescript_separator & "sh_center_b=" & ddecimal (b shifted shadeoffset)
- & mfun_prescript_separator & "sh_radius_a=" & decimal ra
- & mfun_prescript_separator & "sh_radius_b=" & decimal rb
+ & mfun_prescript_separator & "sh_domain=0 1"
+ & mfun_prescript_separator & "sh_factor=1"
+ & mfun_prescript_separator & "sh_color_a=" & colordecimals ca
+ & mfun_prescript_separator & "sh_color_b=" & colordecimals cb
+ & mfun_prescript_separator & "sh_center_a=" & ddecimal a % (a shifted shadeoffset)
+ & mfun_prescript_separator & "sh_center_b=" & ddecimal b % (b shifted shadeoffset)
+ & mfun_prescript_separator & "sh_radius_a=" & decimal ra
+ & mfun_prescript_separator & "sh_radius_b=" & decimal rb
;
mfun_defined_cs
enddef ;
@@ -506,52 +638,49 @@ enddef ;
vardef define_linear_shade (expr a, b, ca, cb) =
mfun_defined_cs := mfun_defined_cs + 1 ;
mfun_defined_cs_pre[mfun_defined_cs] := "sh_type=linear"
- & mfun_prescript_separator & "sh_domain=0 1"
- & mfun_prescript_separator & "sh_factor=" & decimal shadefactor
- & mfun_prescript_separator & "sh_color_a=" & colordecimals ca
- & mfun_prescript_separator & "sh_color_b=" & colordecimals cb
- & mfun_prescript_separator & "sh_center_a=" & ddecimal (a shifted shadeoffset)
- & mfun_prescript_separator & "sh_center_b=" & ddecimal (b shifted shadeoffset)
+ & mfun_prescript_separator & "sh_domain=0 1"
+ & mfun_prescript_separator & "sh_factor=1"
+ & mfun_prescript_separator & "sh_color_a=" & colordecimals ca
+ & mfun_prescript_separator & "sh_color_b=" & colordecimals cb
+ & mfun_prescript_separator & "sh_center_a=" & ddecimal a % (a shifted shadeoffset)
+ & mfun_prescript_separator & "sh_center_b=" & ddecimal b % (b shifted shadeoffset)
;
mfun_defined_cs
enddef ;
-primarydef p withshade sc =
- p withprescript mfun_defined_cs_pre[sc]
-enddef ;
-
-
-vardef define_sampled_linear_shade(expr a,b,n)(text t) =
- mfun_defined_cs := mfun_defined_cs + 1 ;
- mfun_defined_cs_pre[mfun_defined_cs] := "ssh_type=linear"
- & mfun_prescript_separator & "ssh_center_a=" & ddecimal (a shifted shadeoffset)
- & mfun_prescript_separator & "ssh_center_b=" & ddecimal (b shifted shadeoffset)
- & mfun_prescript_separator & "ssh_nofcolors=" & decimal n
- & mfun_prescript_separator & "ssh_domain=" & domstr
- & mfun_prescript_separator & "ssh_extend=" & extstr
- & mfun_prescript_separator & "ssh_colors=" & colstr
- & mfun_prescript_separator & "ssh_bounds=" & bndstr
- & mfun_prescript_separator & "ssh_ranges=" & ranstr
- ;
- mfun_defined_cs
-enddef ;
-
-vardef define_sampled_circular_shade(expr a,b,ra,rb,n)(text t) =
- mfun_defined_cs := mfun_defined_cs + 1 ;
- mfun_defined_cs_pre[mfun_defined_cs] := "ssh_type=circular"
- & mfun_prescript_separator & "ssh_center_a=" & ddecimal (a shifted shadeoffset)
- & mfun_prescript_separator & "ssh_radius_a=" & decimal ra
- & mfun_prescript_separator & "ssh_center_b=" & ddecimal (b shifted shadeoffset)
- & mfun_prescript_separator & "ssh_radius_b=" & decimal rb
- & mfun_prescript_separator & "ssh_nofcolors=" & decimal n
- & mfun_prescript_separator & "ssh_domain=" & domstr
- & mfun_prescript_separator & "ssh_extend=" & extstr
- & mfun_prescript_separator & "ssh_colors=" & colstr
- & mfun_prescript_separator & "ssh_bounds=" & bndstr
- & mfun_prescript_separator & "ssh_ranges=" & ranstr
- ;
- mfun_defined_cs
-enddef ;
+% I lost the example code that uses this:
+%
+% vardef define_sampled_linear_shade(expr a,b,n)(text t) =
+% mfun_defined_cs := mfun_defined_cs + 1 ;
+% mfun_defined_cs_pre[mfun_defined_cs] := "ssh_type=linear"
+% & mfun_prescript_separator & "ssh_center_a=" & ddecimal (a shifted shadeoffset)
+% & mfun_prescript_separator & "ssh_center_b=" & ddecimal (b shifted shadeoffset)
+% & mfun_prescript_separator & "ssh_nofcolors=" & decimal n
+% & mfun_prescript_separator & "ssh_domain=" & domstr
+% & mfun_prescript_separator & "ssh_extend=" & extstr
+% & mfun_prescript_separator & "ssh_colors=" & colstr
+% & mfun_prescript_separator & "ssh_bounds=" & bndstr
+% & mfun_prescript_separator & "ssh_ranges=" & ranstr
+% ;
+% mfun_defined_cs
+% enddef ;
+%
+% vardef define_sampled_circular_shade(expr a,b,ra,rb,n)(text t) =
+% mfun_defined_cs := mfun_defined_cs + 1 ;
+% mfun_defined_cs_pre[mfun_defined_cs] := "ssh_type=circular"
+% & mfun_prescript_separator & "ssh_center_a=" & ddecimal (a shifted shadeoffset)
+% & mfun_prescript_separator & "ssh_radius_a=" & decimal ra
+% & mfun_prescript_separator & "ssh_center_b=" & ddecimal (b shifted shadeoffset)
+% & mfun_prescript_separator & "ssh_radius_b=" & decimal rb
+% & mfun_prescript_separator & "ssh_nofcolors=" & decimal n
+% & mfun_prescript_separator & "ssh_domain=" & domstr
+% & mfun_prescript_separator & "ssh_extend=" & extstr
+% & mfun_prescript_separator & "ssh_colors=" & colstr
+% & mfun_prescript_separator & "ssh_bounds=" & bndstr
+% & mfun_prescript_separator & "ssh_ranges=" & ranstr
+% ;
+% mfun_defined_cs
+% enddef ;
% vardef predefined_linear_shade (expr p, n, ca, cb) =
% save a, b, sh ; pair a, b ;
@@ -566,53 +695,6 @@ enddef ;
% define_circular_shade(ab,ab,0,r,ca,cb)
% enddef ;
-% NEW EXPERIMENTAL CODE
-
-def withlinearshading (expr a, b) =
- withprescript "sh_type=linear"
- withprescript "sh_domain=0 1"
- withprescript "sh_factor=" & decimal shadefactor
- withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset)
- withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset)
-enddef ;
-
-def withcircularshading (expr a, b, ra, rb) =
- withprescript "sh_type=circular"
- withprescript "sh_domain=0 1"
- withprescript "sh_factor=" & decimal shadefactor
- withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset)
- withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset)
- withprescript "sh_radius_a=" & decimal ra
- withprescript "sh_radius_b=" & decimal rb
-enddef ;
-
-def withfromshadecolor expr t =
- withprescript "sh_color=into"
- withprescript "sh_color_a=" & colordecimals t
-enddef ;
-
-def withtoshadecolor expr t =
- withprescript "sh_color=into"
- withprescript "sh_color_b=" & colordecimals t
-enddef ;
-
-def withshading (expr how)(text rest) =
- if how = "linear" :
- withlinearshading(rest)
- elseif how = "circular" :
- withcircularshading(rest)
- else :
- % nothing
- fi
-enddef ;
-
-primarydef a shadedinto b =
- 1 % does not work with transparency
- withprescript "sh_color=into"
- withprescript "sh_color_a=" & colordecimals a
- withprescript "sh_color_b=" & colordecimals b
-enddef ;
-
% Layers
def onlayer primary name =
@@ -657,10 +739,10 @@ enddef ;
% Positions
-def register (expr label, width, height, offset) =
+def register (expr tag, width, height, offset) =
% draw image (
addto currentpicture doublepath unitsquare xscaled width yscaled height shifted offset
- withprescript "ps_label=" & label ;
+ withprescript "ps_label=" & tag ;
% ) ; % no transformations
enddef ;
@@ -672,8 +754,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
@@ -749,7 +831,7 @@ primarydef t asgroup s = % s = isolated|knockout
endgroup
enddef ;
-% Also experimental
+% Also experimental ... needs to be made better ... so it can change!
string mfun_auto_align[] ;
@@ -826,6 +908,10 @@ vardef mfun_cmykcolor_to_string(expr c) =
decimal blackpart c
enddef ;
+vardef mfun_greycolor_to_string(expr n) =
+ decimal n
+enddef ;
+
vardef mfun_path_to_string(expr p) =
mfun_point_to_string(p,0) for i=1 upto length(p) : & " " & mfun_point_to_string(p,i) endfor
enddef ;
@@ -852,6 +938,7 @@ vardef tostring(expr value) =
elseif pair value : mfun_pair_to_string(value)
elseif rgbcolor value : mfun_rgbcolor_to_string(value)
elseif cmykcolor value : mfun_cmykcolor_to_string(value)
+ elseif greycolor value : mfun_greycolor_to_string(value)
elseif boolean value : mfun_boolean_to_string(value)
elseif path value : mfun_path_to_string(value)
elseif transform value : mfun_transform_to_string(value)
@@ -1047,23 +1134,80 @@ enddef ;
% moved here from mp-grap.mpiv
+% vardef escaped_format(expr s) =
+% "" for n=0 upto length(s) : &
+% if ASCII substring (n,n+1) of s = 37 :
+% "@"
+% else :
+% substring (n,n+1) of s
+% fi
+% endfor
+% enddef ;
+
+numeric mfun_esc_b ; % begin
+numeric mfun_esc_l ; % length
+string mfun_esc_s ; % character
+
+mfun_esc_s := "%" ; % or: char(37)
+
+% this one is the fastest when we have a match
+
+% vardef escaped_format(expr s) =
+% "" for n=0 upto length(s)-1 : &
+% % if ASCII substring (n,n+1) of s = 37 :
+% if substring (n,n+1) of s = mfun_esc_s :
+% "@"
+% else :
+% substring (n,n+1) of s
+% fi
+% endfor
+% enddef ;
+
+% this one wins when we have no match
+
vardef escaped_format(expr s) =
- "" for n=0 upto length(s) : &
- if ASCII substring (n,n+1) of s = 37 :
- "@"
- else :
- substring (n,n+1) of s
+ mfun_esc_b := 0 ;
+ mfun_esc_l := length(s) ;
+ for n=0 upto mfun_esc_l-1 :
+ % if ASCII substring (n,n+1) of s = 37 :
+ if substring (n,n+1) of s = mfun_esc_s :
+ if mfun_esc_b = 0 :
+ ""
+ fi
+ if n >= mfun_esc_b :
+ & (substring (mfun_esc_b,n) of s)
+ exitif numeric begingroup mfun_esc_b := n+1 endgroup ; % hide
+ fi
+ & "@"
fi
endfor
+ if mfun_esc_b = 0 :
+ s
+ % elseif mfun_esc_b > 0 :
+ elseif mfun_esc_b < mfun_esc_l :
+ & (substring (mfun_esc_b,mfun_esc_l) of s)
+ fi
enddef ;
-vardef strfmt(expr f, x) = % maybe use mfun_ namespace
- "\MPgraphformat{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}"
-enddef ;
-
-vardef varfmt(expr f, x) = % maybe use mfun_ namespace
- "\MPformatted{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}"
-enddef ;
+vardef strfmt(expr f, x) = "\MPgraphformat{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" enddef ;
+vardef varfmt(expr f, x) = "\MPformatted{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" enddef ;
vardef format (expr f, x) = textext(strfmt(f, x)) enddef ;
vardef formatted(expr f, x) = textext(varfmt(f, x)) enddef ;
+
+% could be this (something to discuss with alan as it involves graph):
+%
+% vardef format (expr f,x) = lua.mp.graphformat(f,mfun_tagged_string(x) enddef ;
+% vardef formatted(expr f,x) = lua.mp.format (f, x) enddef ;
+%
+% def strfmt = format enddef ; % old
+% def varfmt = formatted enddef ; % old
+
+% new
+
+def eofill text t = fill t withpostscript "evenodd" enddef ;
+%%% eoclip text t = clip t withpostscript "evenodd" enddef ; % no postscripts yet
+
+% def withrule expr r =
+% if (t = "even-odd") or (t = "evenodd") : withpostscript "evenodd" fi
+% enddef ;