summaryrefslogtreecommitdiff
path: root/metapost/context/base/mpiv/mp-tool.mpiv
diff options
context:
space:
mode:
Diffstat (limited to 'metapost/context/base/mpiv/mp-tool.mpiv')
-rw-r--r--metapost/context/base/mpiv/mp-tool.mpiv161
1 files changed, 124 insertions, 37 deletions
diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv
index cd04b8dcb..36d6f1743 100644
--- a/metapost/context/base/mpiv/mp-tool.mpiv
+++ b/metapost/context/base/mpiv/mp-tool.mpiv
@@ -234,50 +234,27 @@ def job_name =
jobname
enddef ;
-def data_mpd_file =
- job_name & "-mp.mpd"
-enddef ;
-
%D Because \METAPOST\ has a hard coded limit of 4~datafiles,
%D we need some trickery when we have multiple files. This will
%D be redone (via \LUA).
-if unknown collapse_data :
- boolean collapse_data ;
- collapse_data := false ;
-fi ;
-
boolean savingdata ; savingdata := false ;
boolean savingdatadone ; savingdatadone := false ;
def savedata expr txt =
- write if collapse_data :
- txt
- else :
- if savingdata : txt else : "\MPdata{" & decimal charcode & "}{" & txt & "}" fi & "%"
- fi to data_mpd_file ;
+ lua.mp.save_data(txt);
enddef ;
def startsavingdata =
- savingdata := true ;
- savingdatadone := true ;
- if collapse_data :
- write "\MPdata{" & decimal charcode & "}{%" to data_mpd_file ;
- fi ;
+ lua.mp.start_saving_data();
enddef ;
def stopsavingdata =
- if collapse_data :
- write "}%" to data_mpd_file ;
- fi ;
- savingdata := false ;
+ lua.mp.stop_saving_data() ;
enddef ;
def finishsavingdata =
- if savingdatadone :
- write EOF to data_mpd_file ;
- savingdatadone := false ;
- fi ;
+ lua.mp.finish_saving_data() ;
enddef ;
%D Instead of a keystroke eating save and allocation
@@ -1204,8 +1181,53 @@ enddef ;
%D Interesting too:
+% primarydef p paralleled d = (
+% p shifted if d < 0 : - fi ((point abs(d) on (p rotatedaround(point 0 of p,90))) - point 0 of p)
+% ) enddef ;
+%
+% primarydef p paralleled d = (
+% p shifted ((d*unitvector(direction 0 of p) - point 0 of p) rotated 90)
+% ) enddef ;
+%
+% Alan came up with an improved version and stepwise we ended up with (or
+% might up with a variant of):
+
+vardef perpendicular expr t of p =
+ unitvector((direction t of p) rotated 90)
+enddef ;
+
+def istextext(expr p) =
+ (picture p and ((substring(0,3) of prescriptpart p) = "tx_"))
+enddef ;
+
primarydef p paralleled d = (
- p shifted if d < 0 : - fi ((point abs(d) on (p rotatedaround(point 0 of p,90))) - point 0 of p)
+ if path p :
+ begingroup ;
+ save dp ; pair dp ;
+ for i=0 upto length p if cycle p : -1 fi :
+ hide(dp := d * perpendicular i of p)
+ if i > 0 : .. fi
+ (point i of p + dp)
+ if i < length p :
+ .. controls (postcontrol i of p + dp) and
+ (precontrol (i+1) of p + dp)
+ fi
+ endfor
+ if cycle p : .. cycle fi
+ endgroup
+ elseif picture p :
+ image(
+ for i within p :
+ draw (pathpart i)
+ if not istextext(i) : % dirty trick
+ paralleled d
+ fi
+ mfun_decoration_i i ;
+ endfor ;
+ )
+ elseif pair p :
+ p
+ fi
) enddef ;
vardef punked primary p =
@@ -1291,6 +1313,7 @@ enddef ;
newinternal ahvariant ; ahvariant := 0 ;
newinternal ahdimple ; ahdimple := 1/5 ;
+newinternal ahscale ; ahscale := 3/4 ;
vardef arrowhead expr p =
save q, e, r ;
@@ -1333,7 +1356,8 @@ def resetarrows =
ahangle := 45 ;
ahvariant := 0 ;
ahdimple := 1/5 ;
- )
+ ahscale := 3/4 ;
+)
enddef ;
%D Points.
@@ -1690,7 +1714,9 @@ def mfun_with_arrow_picture (text t) =
mfun_arrow_count := 0 ;
mfun_arrow_snippets := stroked_paths(mfun_arrow_picture) ;
for i within mfun_arrow_picture :
- if stroked i :
+ if istextext(i) :
+ draw i
+ else :
mfun_arrow_count := mfun_arrow_count + 1 ;
mfun_arrow_path := pathpart i ;
t
@@ -1719,13 +1745,12 @@ def mfun_draw_arrow_picture_double text t =
fi
mfun_with_arrow_picture (
draw
- if mfun_arrow_count = 1 :
- arrowpath reverse
- fi
- if mfun_arrow_count = mfun_arrow_snippets :
- arrowpath
- fi
- mfun_arrow_path mfun_decoration_i i t ;
+ if mfun_arrow_count = 1 :
+ arrowpath reverse
+ elseif mfun_arrow_count = mfun_arrow_snippets :
+ arrowpath
+ fi
+ mfun_arrow_path mfun_decoration_i i t ;
if mfun_arrow_count = 1 :
fillup arrowhead reverse mfun_arrow_path mfun_decoration_i i t ;
fi
@@ -1736,6 +1761,65 @@ def mfun_draw_arrow_picture_double text t =
endgroup ;
enddef ;
+%D Some more arrow magic, by Alan:
+
+def drawdoublearrows expr p =
+ begingroup ;
+ save mfun_arrow_path ;
+ path mfun_arrow_path ;
+ save mfun_arrow_path_parallel ;
+ path mfun_arrow_path_parallel ;
+ if path p :
+ mfun_arrow_path := p ;
+ expandafter mfun_draw_arrow_paths
+ elseif picture p :
+ save mfun_arrow_picture ;
+ picture mfun_arrow_picture ;
+ mfun_arrow_picture := p ;
+ expandafter mfun_draw_arrow_pictures
+ else :
+ expandafter mfun_draw_arrow_nothing
+ fi
+enddef ;
+
+def mfun_draw_arrow_paths text t =
+ if autoarrows :
+ set_ahlength(t) ;
+ fi
+ save d ; d := ahscale*ahlength*sind(ahangle/2) ;
+ mfun_arrow_path_parallel := mfun_arrow_path paralleled d ;
+ draw arrowpath mfun_arrow_path_parallel t ;
+ fillup arrowhead mfun_arrow_path_parallel t ;
+ mfun_arrow_path_parallel := (reverse mfun_arrow_path) paralleled d ;
+ draw arrowpath mfun_arrow_path_parallel t ;
+ fillup arrowhead mfun_arrow_path_parallel t ;
+ endgroup ;
+enddef ;
+
+def mfun_draw_arrow_pictures text t =
+ if autoarrows :
+ set_ahlength(t) ;
+ fi
+ save d ; d := ahscale*ahlength*sind(ahangle/2) ;
+ mfun_with_arrow_picture(
+ if mfun_arrow_count = 1 :
+ draw (mfun_arrow_path paralleled d) mfun_decoration_i i t ;
+ mfun_arrow_path_parallel := (reverse mfun_arrow_path) paralleled d ;
+ draw arrowpath mfun_arrow_path_parallel mfun_decoration_i i t ;
+ fillup arrowhead mfun_arrow_path_parallel mfun_decoration_i i t ;
+ elseif mfun_arrow_count = mfun_arrow_snippets :
+ draw ((reverse mfun_arrow_path) paralleled d) mfun_decoration_i i t ;
+ mfun_arrow_path_parallel := mfun_arrow_path paralleled d ;
+ draw arrowpath mfun_arrow_path_parallel mfun_decoration_i i t ;
+ fillup arrowhead mfun_arrow_path_parallel mfun_decoration_i i t ;
+ else :
+ draw ( mfun_arrow_path paralleled d) mfun_decoration_i i t ;
+ draw ((reverse mfun_arrow_path) paralleled d) mfun_decoration_i i t ;
+ fi
+ )
+ endgroup ;
+enddef ;
+
%D Handy too ......
vardef pointarrow (expr pat, loc, len, off) =
@@ -3222,6 +3306,9 @@ def loadmodule expr name = % no vardef
fi ;
enddef ;
+def loadfile (expr filename) = scantokens("input " & filename) enddef ;
+def loadimage (expr filename) = image(scantokens("input " & filename);) enddef ;
+
%D Handy for backgrounds:
def drawpathwithpoints expr p =