summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/context/base/mp-spec.mp
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/metapost/context/base/mp-spec.mp')
-rw-r--r--Master/texmf-dist/metapost/context/base/mp-spec.mp105
1 files changed, 81 insertions, 24 deletions
diff --git a/Master/texmf-dist/metapost/context/base/mp-spec.mp b/Master/texmf-dist/metapost/context/base/mp-spec.mp
index 6c5a557b475..f28e5a5d3ce 100644
--- a/Master/texmf-dist/metapost/context/base/mp-spec.mp
+++ b/Master/texmf-dist/metapost/context/base/mp-spec.mp
@@ -13,6 +13,27 @@
% Spot colors are not handled by mptopdf !
+% let graycolor = numeric ;
+% let greycolor = numeric ;
+% let withanycolor = withcolor ;
+
+% rgbcolor red ; red := (1,0,0) ;
+% rgbcolor green ; green := (0,1,0) ;
+% rgbcolor blue ; blue := (0,0,1) ;
+% cmykcolor cyan ; cyan := (1,0,0,0) ;
+% cmykcolor magenta ; magenta := (0,1,0,0) ;
+% cmykcolor yellow ; yellow := (0,0,1,0) ;
+% graycolor black ; black := 0 ; % (0) ;
+% graycolor white ; white := 1 ; % (1) ;
+
+% primarydef p withcolor c =
+% p withanycolor (c)
+% enddef ;
+
+% fill fullcircle scaled 10cm withcolor cyan ;
+% fill fullcircle scaled 7cm withcolor red ;
+% fill fullcircle scaled 4cm withcolor white ;
+
% (r,g,b) => cmyk : r=123 g= 1 b=hash
% => spot : r=123 g= 2 b=hash
% => transparent rgb : r=123 g= 3 b=hash
@@ -199,20 +220,41 @@ pair shadeoffset ; shadeoffset := origin ;
% _special_counter_
% enddef ;
+% these tests are not yet robust for new gray/cmyk features;
+%
+% - we need to get rid of cmykcolor() and
+
vardef _is_cmyk_(expr c) =
(redpart c = _special_signal_/_special_div_) and (greenpart c = 1/_special_div_)
enddef ;
vardef _is_spot_(expr c) =
(redpart c = _special_signal_/_special_div_) and (greenpart c = 2/_special_div_)
enddef ;
+vardef _is_gray_(expr c) =
+ (redpart c = greenpart c) and (greenpart c = bluepart c)
+enddef ;
numeric mp_shade_version ; mp_shade_version := 2 ; % more colors, needs new backend
vardef define_linear_shade (expr a, b, ca, cb) =
- if (mp_shade_version > 1) and _is_cmyk_(ca) and _is_cmyk_(cb) :
+ save cmyk_a, cmyk_b ; boolean cmyk_a, cmyk_b ;
+ save gray_a, gray_b ; boolean gray_a, gray_b ;
+ cmyk_a := _is_cmyk_(ca) ; gray_a := _is_gray_(ca) ;
+ cmyk_b := _is_cmyk_(cb) ; gray_b := _is_gray_(cb) ;
+ if (mp_shade_version > 1) and cmyk_a and cmyk_b :
flush_special(32, 17, "0 1 " & decimal shadefactor & " " &
cmykcolorpattern[bluepart ca] & " " & ddecimal (a shifted shadeoffset) & " " &
cmykcolorpattern[bluepart cb] & " " & ddecimal (b shifted shadeoffset) ) ;
+ elseif (mp_shade_version > 1) and cmyk_a and gray_b :
+ save cg ; color cg ; cg := cmyk(0,0,0,1-greenpart cb) ;
+ flush_special(32, 17, "0 1 " & decimal shadefactor & " " &
+ cmykcolorpattern[bluepart ca] & " " & ddecimal (a shifted shadeoffset) & " " &
+ cmykcolorpattern[bluepart cg] & " " & ddecimal (b shifted shadeoffset) ) ;
+ elseif (mp_shade_version > 1) and gray_a and cmyk_b :
+ save cg ; color cg ; cg := cmyk(0,0,0,1-greenpart ca) ;
+ flush_special(32, 17, "0 1 " & decimal shadefactor & " " &
+ cmykcolorpattern[bluepart cg] & " " & ddecimal (a shifted shadeoffset) & " " &
+ cmykcolorpattern[bluepart cb] & " " & ddecimal (b shifted shadeoffset) ) ;
elseif (mp_shade_version > 1) and _is_spot_(ca) and _is_spot_(cb) :
flush_special(34, 17, "0 1 " & decimal shadefactor & " " &
spotcolorpattern[bluepart ca] & " " & ddecimal (a shifted shadeoffset) & " " &
@@ -226,10 +268,24 @@ vardef define_linear_shade (expr a, b, ca, cb) =
enddef ;
vardef define_circular_shade (expr a, b, ra, rb, ca, cb) =
- if (mp_shade_version > 1) and _is_cmyk_(ca) and _is_cmyk_(cb) :
+ save cmyk_a, cmyk_b ; boolean cmyk_a, cmyk_b ;
+ save gray_a, gray_b ; boolean gray_a, gray_b ;
+ cmyk_a := _is_cmyk_(ca) ; gray_a := _is_gray_(ca) ;
+ cmyk_b := _is_cmyk_(cb) ; gray_b := _is_gray_(cb) ;
+ if (mp_shade_version > 1) and cmyk_a and cmyk_b :
flush_special(33, 19, "0 1 " & decimal shadefactor & " " &
cmykcolorpattern[bluepart ca] & " " & ddecimal (a shifted shadeoffset) & " " & decimal ra & " " &
cmykcolorpattern[bluepart cb] & " " & ddecimal (b shifted shadeoffset) & " " & decimal rb ) ;
+ elseif (mp_shade_version > 1) and cmyk_a and gray_b :
+ save cg ; color cg ; cg := cmyk(0,0,0,1-greenpart cb) ;
+ flush_special(33, 19, "0 1 " & decimal shadefactor & " " &
+ cmykcolorpattern[bluepart ca] & " " & ddecimal (a shifted shadeoffset) & " " & decimal ra & " " &
+ cmykcolorpattern[bluepart cg] & " " & ddecimal (b shifted shadeoffset) & " " & decimal rb ) ;
+ elseif (mp_shade_version > 1) and gray_a and cmyk_b :
+ save cg ; color cg ; cg := cmyk(0,0,0,1-greenpart ca) ;
+ flush_special(33, 19, "0 1 " & decimal shadefactor & " " &
+ cmykcolorpattern[bluepart cg] & " " & ddecimal (a shifted shadeoffset) & " " & decimal ra & " " &
+ cmykcolorpattern[bluepart cb] & " " & ddecimal (b shifted shadeoffset) & " " & decimal rb ) ;
elseif (mp_shade_version > 1) and _is_spot_(ca) and _is_spot_(cb) :
flush_special(35, 19, "0 1 " & decimal shadefactor & " " &
spotcolorpattern[bluepart ca] & " " & ddecimal (a shifted shadeoffset) & " " & decimal ra & " " &
@@ -274,33 +330,26 @@ def set_linear_vector (suffix a,b)(expr p,n) =
fi ;
enddef ;
+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 ;
+ elseif (n=4) : ab := ulcorner p ;
+ else : ab := center p ; r := .5r ;
+ fi ;
+enddef ;
+
def linear_shade (expr p, n, ca, cb) =
begingroup ;
save a, b, sh ; pair a, b ;
set_linear_vector(a,b)(p,n) ;
fill p withshade define_linear_shade (a,b,ca,cb) ;
if trace_shades :
- drawarrow a -- b withpen pencircle scaled 1pt ;
+ drawarrow a -- b withpen pencircle scaled 1pt withcolor .5white ;
fi ;
endgroup ;
enddef ;
-vardef predefined_linear_shade (expr p, n, ca, cb) =
- save a, b, sh ; pair a, b ;
- set_linear_vector(a,b)(p,n) ;
- set_shade_vector(a,b)(p,n) ;
- define_linear_shade (a,b,ca,cb)
-enddef ;
-
-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 ;
- elseif (n=4) : ab := ulcorner p ;
- else : ab := center p ; r := .5r ;
- fi ;
-enddef ;
-
def circular_shade (expr p, n, ca, cb) =
begingroup ;
save ab, r ; pair ab ; numeric r ;
@@ -309,11 +358,18 @@ def circular_shade (expr p, n, ca, cb) =
set_circular_vector(ab,r)(p,n) ;
fill p withshade define_circular_shade(ab,ab,0,r,ca,cb) ;
if trace_shades :
- drawarrow ab -- ab shifted (0,r) withpen pencircle scaled 1pt ;
+ drawarrow ab -- ab shifted (0,r) withpen pencircle scaled 1pt withcolor .5white ;
fi ;
endgroup ;
enddef ;
+vardef predefined_linear_shade (expr p, n, ca, cb) =
+ save a, b, sh ; pair a, b ;
+ set_linear_vector(a,b)(p,n) ;
+ set_shade_vector(a,b)(p,n) ;
+ define_linear_shade (a,b,ca,cb)
+enddef ;
+
vardef predefined_circular_shade (expr p, n, ca, cb) =
save ab, r ; pair ab ; numeric r ;
r := (xpart lrcorner p - xpart llcorner p) ++
@@ -439,7 +495,8 @@ vardef cmyk(expr c,m,y,k) =
ok := true ; % globally already defined
fi ;
if not ok :
- save s ; string s ; s := dddecimal (c,m,y) & " " & decimal k ;
+% save s ; string s ; s := dddecimal (c,m,y) & " " & decimal k ;
+ save s ; string s ; s := ddddecimal (c,m,y,k) ;
_cmyk_counter_ := _cmyk_counter_ + 1 ;
cmykcolorpattern[_cmyk_counter_/_special_div_] := s ;
cmykcolorhash[c][m][y][k] := _cmyk_counter_ ;
@@ -456,9 +513,9 @@ enddef ;
% newcolor truecyan, truemagenta, trueyellow ;
%
-% truecyan = cmyk (1,0,0,0) ;
-% truemagenta = cmyk (0,1,0,0) ;
-% trueyellow = cmyk (0,0,1,0) ;
+% truecyan = (1,0,0,0) ;
+% truemagenta = (0,1,0,0) ;
+% trueyellow = (0,0,1,0) ;
%D Spot colors