diff options
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mpiv/mp-chem.mpiv | 49 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-mlib.mpiv | 10 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-step.mpiv | 3 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-tool.mpiv | 50 |
4 files changed, 76 insertions, 36 deletions
diff --git a/metapost/context/base/mpiv/mp-chem.mpiv b/metapost/context/base/mpiv/mp-chem.mpiv index b861d3f12..161568b02 100644 --- a/metapost/context/base/mpiv/mp-chem.mpiv +++ b/metapost/context/base/mpiv/mp-chem.mpiv @@ -50,24 +50,34 @@ pair chem_pair[], % scratch chem_sb_pair, chem_sb_pair.m, chem_sb_pair.p, chem_sb_pair.b ; + + picture - chem_pic, % scratch + chem_pic; % scratch % The use of dashpattern is found to dot the starting point with chem_sb_dash.m... %chem_sb_dash, chem_sb_dash.m, chem_sb_dash.p, chem_sb_dash.b, + +% nice hack but now redone +% +% picture chem_axis_color ; +% +% chem_axis_color := image(draw origin withcolor axiscolor) ; % so we handle all color models +% +% withpen pencircle scaled chem_axis_rulethickness withcolor colorpart(chem_axis_color) ; + +string chem_axis_color ; transform chem_t ; % scratch -color lightblue ; lightblue := (173/255,216/255,230/255) ; - % debugging boolean chem_trace_nesting ; chem_trace_nesting := false ; boolean chem_trace_text ; chem_trace_text := false ; boolean chem_trace_boundingbox ; chem_trace_boundingbox := false ; -chem_axis_color := image(draw origin withcolor lightblue) ; +chem_axis_color := "lightblue" ; chem_setting_axis := false ; chem_axis_rulethickness := 1pt ; chem_emwidth := 10pt ; % EmWidth or \the\emwidth does not work... @@ -333,7 +343,7 @@ def chem_start_structure(expr i, l, r, t, b, rotation, unit, bond, scale, offset chem_setting_offset := offset ; chem_setting_axis := if boolean axis : axis else : (axis<>0) fi ; chem_axis_rulethickness := .75*(rulethickness) ; % axis 50% thinner than frame and bonds. - chem_axis_color := image(draw origin withcolor axiscolor) ; % so we handle all color models + chem_axis_color := axiscolor ; chem_reset ; enddef ; @@ -367,24 +377,24 @@ vardef chem_stop_structure = % draw the axes to the bounding box of the entire structure, % not necessarily the bounding box of the final figure draw (l,0) -- (r,0) - withpen pencircle scaled chem_axis_rulethickness withcolor colorpart(chem_axis_color) ; + withpen pencircle scaled chem_axis_rulethickness withcolor chem_axis_color ; draw (0,b) -- (0,t) - withpen pencircle scaled chem_axis_rulethickness withcolor colorpart(chem_axis_color) ; + withpen pencircle scaled chem_axis_rulethickness withcolor chem_axis_color ; for i = 0 step chem_num0 until r : draw (i,-chem_num1) -- (i,chem_num1) - withpen pencircle scaled chem_axis_rulethickness withcolor colorpart(chem_axis_color) ; + withpen pencircle scaled chem_axis_rulethickness withcolor chem_axis_color ; endfor for i = 0 step -chem_num0 until l : draw (i,-chem_num1) -- (i,chem_num1) - withpen pencircle scaled chem_axis_rulethickness withcolor colorpart(chem_axis_color) ; + withpen pencircle scaled chem_axis_rulethickness withcolor chem_axis_color ; endfor for i = 0 step chem_num0 until t : draw (-chem_num1,i) -- (chem_num1,i) - withpen pencircle scaled chem_axis_rulethickness withcolor colorpart(chem_axis_color) ; + withpen pencircle scaled chem_axis_rulethickness withcolor chem_axis_color ; endfor for i = 0 step -chem_num0 until b : draw (-chem_num1,i) -- (chem_num1,i) - withpen pencircle scaled chem_axis_rulethickness withcolor colorpart(chem_axis_color) ; + withpen pencircle scaled chem_axis_rulethickness withcolor chem_axis_color ; endfor addto currentpicture also chem_pic ; fi ; @@ -406,9 +416,8 @@ vardef chem_stop_component = enddef ; vardef chem_pb = % PB : if chem_trace_nesting : - draw boundingbox currentpicture - withpen pencircle scaled 1mm withcolor colorpart(chem_axis_color) ; - draw origin withpen pencircle scaled 2mm withcolor colorpart(chem_axis_color) ; + draw boundingbox currentpicture withpen pencircle scaled 1mm withcolor chem_axis_color ; + draw origin withpen pencircle scaled 2mm withcolor chem_axis_color ; fi ; chem_doing_pb := true ; enddef ; @@ -507,21 +516,21 @@ enddef ; vardef chem_draw (expr what, r, c) (text extra) = draw what withpen pencircle scaled r - withcolor c %\MPcolor{c} + withcolor c extra ; enddef ; vardef chem_fill (expr what, r, c) (text extra) = fill what withpen pencircle scaled r - withcolor c %\MPcolor{c} + withcolor c extra ; enddef ; vardef chem_drawarrow (expr what, r, c) (text extra) = drawarrow what withpen pencircle scaled r - withcolor c %\MPcolor{c} + withcolor c extra ; enddef ; @@ -1691,14 +1700,14 @@ vardef chem_line (suffix $) (expr f, t, r, c) = % LINE draw if f=t : origin else : chem_marked(f) fi -- chem_marked(t) % no chem_transformed withpen pencircle scaled r - withcolor c %\MPcolor{c} + withcolor c enddef ; vardef chem_dash (suffix $) (expr f, t, r, c) = % DASH draw if f=t : origin else : chem_marked(f) fi -- chem_marked(t) % no chem_transformed withpen pencircle scaled r - withcolor c %\MPcolor{c} + withcolor c dashed evenly ; enddef ; @@ -1706,7 +1715,7 @@ vardef chem_arrow (suffix $) (expr f, t, r, c) = % ARROW drawarrow if f=t : origin else : chem_marked(f) fi -- chem_marked(t) % no chem_transformed withpen pencircle scaled r - withcolor c %\MPcolor{c} + withcolor c enddef ; diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index cac84a6fd..689995df7 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -54,6 +54,7 @@ vardef transparency_alternative_to_number(expr name) = fi enddef ; + def namedcolor (expr n) = 1 withprescript "sp_type=named" @@ -1534,3 +1535,12 @@ def nofill text t = fill t withpostscript "collect" enddef ; % def withrule expr r = % if (t = "even-odd") or (t = "evenodd") : withpostscript "evenodd" fi % enddef ; + +% so we can do: withcolor "red" + +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 ; diff --git a/metapost/context/base/mpiv/mp-step.mpiv b/metapost/context/base/mpiv/mp-step.mpiv index 27bcffcdc..496eb0b20 100644 --- a/metapost/context/base/mpiv/mp-step.mpiv +++ b/metapost/context/base/mpiv/mp-step.mpiv @@ -11,7 +11,8 @@ %C therefore copyrighted by \PRAGMA. See licen-en.pdf for %C details. -% step prefixes .. no save needed +% maybe todo: step prefixes .. no save needed +% not todo : make it unreadable by lots of suffix compaction if known context_cell : endinput ; fi ; diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv index 76459d25c..d5793d086 100644 --- a/metapost/context/base/mpiv/mp-tool.mpiv +++ b/metapost/context/base/mpiv/mp-tool.mpiv @@ -143,6 +143,8 @@ vardef colordecimals primary c = decimal cyanpart c & ":" & decimal magentapart c & ":" & decimal yellowpart c & ":" & decimal blackpart c elseif rgbcolor c : decimal redpart c & ":" & decimal greenpart c & ":" & decimal bluepart c + elseif string c: + colordecimals resolvedcolor(c) else : decimal c fi @@ -817,6 +819,16 @@ enddef ; %D Some colors. +def resolvedcolor(expr s) = + .5white +enddef ; + +let normalwithcolor = withcolor ; + +def withcolor primary 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 enddef ; @@ -829,24 +841,26 @@ vardef blackcolor expr c = if cmykcolor c : (0,0,0,1) elseif rgbcolor c : (0,0,0) else : 0 fi enddef ; -vardef complementary expr c = ( - if cmykcolor c : (1,1,1,1) - - elseif rgbcolor c : (1,1,1) - - elseif pair c : (1,1) - - elseif numeric c : 1 - - fi c -) enddef ; +vardef complementary expr c = + if cmykcolor c : (1,1,1,1) - c + elseif rgbcolor c : (1,1,1) - c + elseif pair c : (1,1) - c + elseif numeric c : 1 - c + elseif string c : complementary resolvedcolor(c) + fi +enddef ; vardef complemented expr c = save m ; if cmykcolor c : m := max(cyanpart c, magentapart c, yellowpart c, blackpart c) ; - ( (m,m,m,m) - + (m,m,m,m) - c elseif rgbcolor c : m := max(redpart c, greenpart c, bluepart c) ; - ( (m,m,m) - + (m,m,m) - c elseif pair c : m := max(xpart c, ypart c) ; - ( (m,m) - - elseif numeric c : ( m - - fi c ) + (m,m) - c + elseif numeric c : m - c + elseif string c : complemented resolvedcolor(c) + fi enddef ; %D Well, this is the dangerous and naive version: @@ -1014,6 +1028,8 @@ primarydef p randomized s = ( else : ((uniformdeviate s) * p) fi + elseif string p : + resolvedcolor(p) randomized s else : p + uniformdeviate s fi @@ -1699,6 +1715,8 @@ vardef grayed primary p = tripled(.30*(1-cyanpart i)+.59*(1-magentapart i)+.11*(1-yellowpart i)+blackpart i) elseif greycolor p : p + elseif string p : + grayed resolvedcolor(p) elseif picture p : image ( for i within p : @@ -1854,14 +1872,16 @@ inner end ; % this will be redone (when needed) using scripts and backend handling -let normalwithcolor = withcolor ; +let mfun_remap_colors_normalwithcolor = normalwithcolor ; def remapcolors = - def withcolor primary c = normalwithcolor remappedcolor(c) enddef ; + def normalwithcolor primary c = + mfun_remap_colors_normalwithcolor remappedcolor(c) + enddef ; enddef ; def normalcolors = - let withcolor = normalwithcolor ; + let normalwithcolor = mfun_remap_colors_normalwithcolor ; enddef ; def resetcolormap = |