summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2016-11-28 14:23:17 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-11-28 14:23:17 +0100
commitb8a38bef2eaacea0dd17897dc99f1ef09b46a7e3 (patch)
treee53017157648c5d4abab9b14ddfd23db0e43de38 /metapost
parentf4d0ad2ba2c4ca5bfae469650e535fd46749b3f4 (diff)
downloadcontext-b8a38bef2eaacea0dd17897dc99f1ef09b46a7e3.tar.gz
2016-11-28 13:36:00
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mpiv/mp-page.mpiv8
-rw-r--r--metapost/context/base/mpiv/mp-tool.mpiv105
2 files changed, 90 insertions, 23 deletions
diff --git a/metapost/context/base/mpiv/mp-page.mpiv b/metapost/context/base/mpiv/mp-page.mpiv
index fd5485dd3..f32990677 100644
--- a/metapost/context/base/mpiv/mp-page.mpiv
+++ b/metapost/context/base/mpiv/mp-page.mpiv
@@ -300,6 +300,14 @@ vardef InnerEdgeDistance = if not OnRightPage : lua.mp.RightEdgeDistance () e
vardef OuterSpaceWidth = if not OnRightPage : lua.mp.BackSpace () else : lua.mp.CutSpace () fi enddef ;
vardef InnerSpaceWidth = if not OnRightPage : lua.mp.CutSpace () else : lua.mp.BackSpace () fi enddef ;
+% indices
+
+vardef OuterMargin = if not OnRightPage : LeftMargin else : RightMargin fi enddef ;
+vardef InnerMargin = if not OnRightPage : RightMargin else : LeftMargin fi enddef ;
+
+vardef OuterEdge = if not OnRightPage : LeftEdge else : RightEdge fi enddef ;
+vardef InnerEdge = if not OnRightPage : Rightedge else : LeftEdge fi enddef ;
+
% vardef CurrentLayout = lua.mp.CurrentLayout () enddef ;
vardef OverlayWidth = lua.mp.OverlayWidth () enddef ;
diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv
index ba137c1e9..68bc0a9c7 100644
--- a/metapost/context/base/mpiv/mp-tool.mpiv
+++ b/metapost/context/base/mpiv/mp-tool.mpiv
@@ -34,6 +34,10 @@ prologues := 1 ;
warningcheck := 0 ;
mpprocset := 1 ;
+%D Handy:
+
+def nothing = enddef ;
+
%D Namespace handling:
% let exclamationmark = ! ;
@@ -107,22 +111,25 @@ enddef ;
%D Variables
def dispose suffix s =
- begingroup ;
- save ss ;
- if numeric s : numeric ss
- elseif boolean s : boolean ss
- elseif pair s : pair ss
- elseif path s : path ss
- elseif picture s : picture ss
- elseif string s : string ss
- elseif transform s : transform ss
- elseif color s : color ss
- elseif rgbcolor s : rgbcolor ss
- elseif cmykcolor s : cmykcolor ss
- else s : numeric ss
+ if known s :
+ begingroup ;
+ save ss ;
+ if numeric s : numeric ss
+ elseif boolean s : boolean ss
+ elseif pair s : pair ss
+ elseif path s : path ss
+ elseif picture s : picture ss
+ elseif string s : string ss
+ elseif transform s : transform ss
+ elseif color s : color ss
+ elseif rgbcolor s : rgbcolor ss
+ elseif cmykcolor s : cmykcolor ss
+ elseif pen s : pen ss
+ else s : numeric ss
+ fi ;
+ s := ss ;
+ endgroup ;
fi ;
- s := ss ;
- endgroup ;
enddef ;
%D Colors:
@@ -1779,9 +1786,7 @@ enddef ;
%D To be documented.
-path freesquare ;
-
-freesquare := (
+path freesquare ; freesquare := (
(-1,0) -- (-1,-1) -- (0,-1) -- (+1,-1) --
(+1,0) -- (+1,+1) -- (0,+1) -- (-1,+1) -- cycle
) scaled .5 ;
@@ -3243,8 +3248,8 @@ newinternal crossingscale ; crossingscale := 20 ;
% primary, secondary or tertiary? always hard to decide but primary makes sense
-vardef infotext(expr txt, ysize) =
- textext("\infofont" & if numeric txt : decimal fi txt) ysized ysize
+vardef infotext@#(expr txt, ysize) =
+ textext@#("\infofont " & if numeric txt : decimal fi txt) ysized ysize
enddef ;
primarydef p crossingunder q =
@@ -3355,14 +3360,68 @@ enddef ;
%D Also handy:
-vardef circularpath(expr n) =
+vardef circularpath primary n =
reverse (for i=0 step 2/n until 8-2/n+2eps: point i of fullcircle .. endfor cycle) rotated 90
enddef ;
-vardef squarepath(expr n) =
+vardef squarepath primary n =
for i=0 step 1/n until 4-1/n + 2eps: point i of fullsquare -- endfor cycle
enddef ;
-vardef linearpath(expr n) =
+vardef linearpath primary n =
origin for i=1/n step 1/n until 1-1/n + 2eps: -- point i of (origin--(1,0)) endfor
enddef ;
+
+%D A nice tracing helper:
+
+color pensilcolor ; pensilcolor := .5red ;
+newinternal pensilstep ; pensilstep := 1/25 ;
+
+vardef pensilled(expr p, q) =
+ image (
+ draw p withcolor pensilcolor withpen q ;
+ for i = 0 step pensilstep until length(p) + eps:
+ draw point i of p withcolor white withtransparency (1,.5) withpen q ;
+ endfor ;
+ )
+enddef ;
+
+%D Easy to forget but handy for manuals:
+
+vardef tolist(suffix l)(text t) =
+ save n ; n := 1 ;
+ for p = t :
+ if numeric p :
+ n := p ;
+ dispose(l[n])
+ elseif pair p :
+ l[n] := p ;
+ n := n + 1 ;
+ elseif path p :
+ for i=0 step 1 until length(p) :
+ l[n] := point i of p ;
+ n := n + 1 ;
+ endfor ;
+ else :
+ % ignore
+ fi ;
+ endfor ;
+ forever :
+ exitif unknown l[n] ;
+ dispose(l[n])
+ n := n + 1 ;
+ endfor ;
+enddef ;
+
+vardef topath(suffix p)(text t) =
+ save i ; i := if known p[1] : 2 ; p[1] elseif known p[0] : 1 ; p[0] else : 0 ; origin fi
+ forever :
+ exitif unknown p[i] ;
+ t p[i]
+ hide(i := i + 1)
+ endfor
+enddef ;
+
+vardef tocycle(suffix p)(text t) =
+ topath(p,t) t cycle
+enddef ;