summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mpiv/mp-mlib.mpiv21
-rw-r--r--metapost/context/base/mpiv/mp-tool.mpiv25
2 files changed, 33 insertions, 13 deletions
diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv
index 8b8d21c14..2b9b8bef6 100644
--- a/metapost/context/base/mpiv/mp-mlib.mpiv
+++ b/metapost/context/base/mpiv/mp-mlib.mpiv
@@ -54,8 +54,8 @@ vardef transparency_alternative_to_number(expr name) =
fi
enddef ;
-def namedcolor (expr n) =
- 1
+def namedcolor expr n =
+ (1)
withprescript "sp_type=named"
withprescript "sp_name=" & n
enddef ;
@@ -77,21 +77,21 @@ enddef ;
% enddef ;
def spotcolor(expr name, v) =
- 1
+ (1)
withprescript "sp_type=spot"
withprescript "sp_name=" & name
withprescript "sp_value=" & colordecimals v
enddef ;
def multitonecolor(expr name)(text t) =
- 1
+ (1)
withprescript "sp_type=multitone"
withprescript "sp_name=" & name
withprescript "sp_value=" & colordecimalslist(t)
enddef ;
def transparent(expr a, t)(text c) = % use withtransparency instead
- 1 % this permits withcolor x intoshade y
+ (1) % this permits withcolor x intoshade y
withprescript "tr_alternative=" & decimal transparency_alternative_to_number(a)
withprescript "tr_transparency=" & decimal t
withcolor c
@@ -1537,9 +1537,18 @@ def nofill text t = fill t withpostscript "collect" enddef ;
% so we can do: withcolor "red"
-def resolvedcolor(expr s) =
+def resolvedcolor expr s =
% lua.mp.namedcolor(s) % conflicts with macro namedcolor
% lua.mp.NamedColor(s) % okay but, can also be
% lua.mp("NamedColor",s) % which gives expansion mess
runscript("mp.NamedColor('" & s & "')") % faster anyway
enddef ;
+
+% A comment will end up on top of the graphic in the output. This can be handy for
+% locating a graphic: comment("test graphic").
+
+def comment(expr str) =
+ special "metapost.comment[[" & str & "]]" ;
+enddef ;
+
+comment("test graphic");
diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv
index d5793d086..09cf24103 100644
--- a/metapost/context/base/mpiv/mp-tool.mpiv
+++ b/metapost/context/base/mpiv/mp-tool.mpiv
@@ -825,20 +825,31 @@ enddef ;
let normalwithcolor = withcolor ;
-def withcolor primary c =
+def withcolor expr c =
normalwithcolor if string c : resolvedcolor(c) else : c fi
enddef ;
-def colortype(expr c) =
- if cmykcolor c : cmykcolor elseif rgbcolor c : rgbcolor else : grayscale fi
+vardef colortype expr c =
+ if cmykcolor c : cmykcolor
+ elseif rgbcolor c : rgbcolor
+ elseif numeric c : grayscale
+ fi
enddef ;
-vardef whitecolor(expr c) =
- if cmykcolor c : (0,0,0,0) elseif rgbcolor c : (1,1,1) else : 1 fi
+vardef whitecolor expr c =
+ if cmykcolor c : (0,0,0,0)
+ elseif rgbcolor c : (1,1,1)
+ elseif numeric c : 1
+ elseif string c : whitecolor resolvedcolor(c)
+ fi
enddef ;
vardef blackcolor expr c =
- if cmykcolor c : (0,0,0,1) elseif rgbcolor c : (0,0,0) else : 0 fi
+ if cmykcolor c : (0,0,0,1)
+ elseif rgbcolor c : (0,0,0)
+ elseif numeric c : 0
+ elseif string c : blackcolor resolvedcolor(c)
+ fi
enddef ;
vardef complementary expr c =
@@ -1653,7 +1664,7 @@ enddef ;
% nice: currentpicture := inverted currentpicture ;
-primarydef p uncolored c =
+primarydef p uncolored c = % not complete ... needs text and scripts and ...
if color p :
c - p
else :