summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2021-03-25 14:12:41 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2021-03-25 14:12:41 +0100
commitcaef1259af1c843232dfbf5efc65adcf83d67f6f (patch)
treedb2a4b76d4d14ca03d21e0bbf37c42759dda31a7 /metapost
parentcb28e8807d7908cc9644c2bd77c9d214dd8caefe (diff)
downloadcontext-caef1259af1c843232dfbf5efc65adcf83d67f6f.tar.gz
2021-03-25 14:03:00
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mpxl/mp-mlib.mpxl72
1 files changed, 68 insertions, 4 deletions
diff --git a/metapost/context/base/mpxl/mp-mlib.mpxl b/metapost/context/base/mpxl/mp-mlib.mpxl
index 40be3dd2d..ed3f79be5 100644
--- a/metapost/context/base/mpxl/mp-mlib.mpxl
+++ b/metapost/context/base/mpxl/mp-mlib.mpxl
@@ -123,12 +123,12 @@ def withtransparency(expr a, t) =
withprescript "tr_transparency=" & decimal t
enddef ;
-% works reverse from transparency (for svg)
+% for svg:
def withopacity expr o =
if o <> 1 :
withprescript "tr_alternative=" & decimal normaltransparent
- withprescript "tr_transparency=" & decimal (1 - o)
+ withprescript "tr_transparency=" & decimal o
fi
enddef ;
@@ -1126,6 +1126,11 @@ def figure primary filename =
rawtextext("\externalfigure[" & filename & "]")
enddef ;
+vardef svgembeddedfigure primary index =
+% mfun_onetime_textext := true ;
+ rawtextext("\svgembeddedfigure{" & decimal index & "}")
+enddef ;
+
permanent withmask, externalfigure, figure ;
% Positions
@@ -1425,16 +1430,75 @@ primarydef t asgroup s = % s = isolated|knockout
temp_q:= nullpicture ;
addto temp_q contour temp_r
withprescript "gr_state=start"
- withprescript "gr_type=" & s ;
+ withprescript "gr_type=" & s
+ ;
addto temp_q also temp_p ;
addto temp_q contour temp_r
- withprescript "gr_state=stop" ;
+ withprescript "gr_state=stop"
+ ;
temp_q
endgroup
enddef ;
permanent asgroup ;
+% Even more experimental:
+
+pair mfun_pattern_s ; mfun_pattern_s := origin ; % auto scale to fraction of shape (svg)
+boolean mfun_pattern_f ; mfun_pattern_f := false ; % anchor or not (normally we do that)
+
+def withpatternscale primary s = hide (mfun_pattern_s := s ;) enddef ;
+def withpatternfloat primary s = hide (mfun_pattern_f := s ;) enddef ;
+
+primarydef t withpattern p =
+ begingroup
+ %
+ save temp_q, temp_r ;
+ picture temp_q ; path temp_r ;
+ % the combination
+ temp_q:= nullpicture ;
+ % the pattern
+ temp_r := boundingbox p ;
+ if mfun_pattern_s <> origin :
+ sx := (xpart mfun_pattern_s) * bbwidth (t) ;
+ sy := (ypart mfun_pattern_s) * bbheight(t) ;
+ temp_r := temp_r xysized (sx,sy) ;
+ addto temp_q contour temp_r
+ withprescript "pt_state=start"
+ withprescript "pt_action=set"
+ withprescript "pt_float=" & tostring(mfun_pattern_f)
+ ;
+ addto temp_q also (p xysized (sx,sy));
+ else :
+ addto temp_q contour temp_r
+ withprescript "pt_state=start"
+ withprescript "pt_action=set"
+ withprescript "pt_float=" & tostring(mfun_pattern_f)
+ ;
+ addto temp_q also p ;
+ fi ;
+ addto temp_q contour temp_r
+ withprescript "pt_state=stop"
+ withprescript "pt_action=set" ;
+ % the path
+ temp_r := boundingbox t ;
+ addto temp_q contour temp_r
+ withprescript "pt_state=start"
+ withprescript "pt_action=get"
+ ;
+ addto temp_q contour temp_r
+ withprescript "pt_state=stop"
+ withprescript "pt_action=get" ;
+ % make sure we fill only t
+ clip temp_q to t ;
+ % reset
+ mfun_pattern_s := origin ;
+ mfun_pattern_f := false ;
+ % the path
+ temp_q
+ endgroup
+enddef ;
+
% Also experimental ... needs to be made better ... so it can change!
string mfun_auto_align[] ;