diff options
Diffstat (limited to 'Master/texmf-dist/metapost')
-rw-r--r-- | Master/texmf-dist/metapost/context/base/metafun.mp | 18 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-base.mp | 5 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-core.mp | 24 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-figs.mp | 2 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-grph.mp | 13 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-mlib.mp | 156 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-spec.mp | 105 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-text.mp | 7 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-tool.mp | 179 |
9 files changed, 428 insertions, 81 deletions
diff --git a/Master/texmf-dist/metapost/context/base/metafun.mp b/Master/texmf-dist/metapost/context/base/metafun.mp index cfbf7b2f98c..b828b8b9ebb 100644 --- a/Master/texmf-dist/metapost/context/base/metafun.mp +++ b/Master/texmf-dist/metapost/context/base/metafun.mp @@ -35,7 +35,7 @@ else : fi ; input mp-tool.mp ; -input mp-spec.mp ; +input mp-spec.mp ; % will be skipped in mkiv, some day input mp-core.mp ; input mp-page.mp ; input mp-text.mp ; @@ -47,18 +47,22 @@ input mp-step.mp ; input mp-grph.mp ; input mp-figs.mp ; +input mp-mlib.mp ; + % mp-form.mp ; input mp-grid.mp ; input mp-func.mp ; string metafunversion ; -metafunversion = "metafun" & " " & - decimal year & "-" & - decimal month & "-" & - decimal day & " " & - decimal (time div 60) & ":" & - decimal (time-(time div 60)*60) ; +metafunversion = "metafun" & " " & + decimal year & "-" & + decimal month & "-" & + decimal day & " " & + if ((time div 60) < 10) : "0" & fi + decimal (time div 60) & ":" & + if ((time-(time div 60)*60) < 10) : "0" & fi + decimal (time-(time div 60)*60) ; let normalend = end ; diff --git a/Master/texmf-dist/metapost/context/base/mp-base.mp b/Master/texmf-dist/metapost/context/base/mp-base.mp index 87f3fd2f742..41eb7aa96a5 100644 --- a/Master/texmf-dist/metapost/context/base/mp-base.mp +++ b/Master/texmf-dist/metapost/context/base/mp-base.mp @@ -477,10 +477,11 @@ enddef; def label = draw thelabel enddef; newinternal dotlabeldiam; dotlabeldiam:=3bp; -vardef dotlabel@#(expr s,z) = +vardef dotlabel@#(expr s,z) text t_ = + label@#(s,z) t_; label@#(s,z); interim linecap:=rounded; - draw z withpen pencircle scaled dotlabeldiam; + draw z withpen pencircle scaled dotlabeldiam t_; enddef; def makelabel = dotlabel enddef; diff --git a/Master/texmf-dist/metapost/context/base/mp-core.mp b/Master/texmf-dist/metapost/context/base/mp-core.mp index 92036febfc9..2b62559b8bc 100644 --- a/Master/texmf-dist/metapost/context/base/mp-core.mp +++ b/Master/texmf-dist/metapost/context/base/mp-core.mp @@ -1000,12 +1000,14 @@ color boxfillcolor ; boxfillcolor := .8white ; numeric boxgridtype ; boxgridtype := 0 ; numeric boxlinetype ; boxlinetype := 1 ; numeric boxfilltype ; boxfilltype := 1 ; +numeric boxdashtype ; boxdashtype := 0 ; pair boxgriddirection ; boxgriddirection := up ; numeric boxgridwidth ; boxgridwidth := 1pt ; numeric boxlinewidth ; boxlinewidth := 1pt ; numeric boxlineradius ; boxlineradius := 0pt ; numeric boxfilloffset ; boxfilloffset := 0pt ; numeric boxgriddistance ; boxgriddistance := .5cm ; +numeric boxgridshift ; boxgridshift := 0pt ; def draw_box = draw pxy withcolor boxlinecolor withpen pencircle scaled boxlinewidth ; @@ -1112,16 +1114,16 @@ def draw_multi_pars = for i=1 upto nofmultipars : do_draw_par(multipars[i]) ; if boxgridtype= 1 : - draw baseline_grid (multipars[i],up,true ) withcolor boxgridcolor ; + draw baseline_grid (multipars[i],up,true ) ; % withcolor boxgridcolor ; elseif boxgridtype= 2 : - draw baseline_grid (multipars[i],up,false) withcolor boxgridcolor ; + draw baseline_grid (multipars[i],up,false) ; % withcolor boxgridcolor ; elseif boxgridtype= 3 : - draw baseline_grid (multipars[i],up,true ) withcolor boxgridcolor ; + draw baseline_grid (multipars[i],up,true ) ; % withcolor boxgridcolor ; draw baseline_grid (multipars[i],up,true ) - shifted (0,ExHeight) withcolor boxgridcolor ; + shifted (0,ExHeight) ; % withcolor boxgridcolor ; elseif boxgridtype= 4 : draw baseline_grid (multipars[i],up,true ) - shifted (0,ExHeight/2) withcolor boxgridcolor ; + shifted (0,ExHeight/2) ; % withcolor boxgridcolor ; elseif boxgridtype=11 : draw graphic_grid(multipars[i],boxgriddistance,boxgriddistance,boxgriddistance/2,boxgriddistance/2) ; elseif boxgridtype=12 : @@ -1162,9 +1164,16 @@ enddef ; vardef baseline_grid (expr pxy, pdir, at_baseline) = if (par_line_height>0) and (bbheight(pxy)>1) and (bbwidth(pxy)>1) and (boxgridwidth>0) : - save i, grid ; picture grid ; pair start ; + save i, grid, bb ; picture grid ; pair start ; path bb ; def _do_ (expr start) = + % 1 = normal, 2 = with background (i.e. no shine-through) + if boxdashtype = 2 : + draw start -- start shifted (bbwidth(pxy),0) + withpen pencircle scaled boxgridwidth + withcolor boxfillcolor ; + fi ; draw start -- start shifted (bbwidth(pxy),0) + if boxdashtype > 0 : dashed evenly fi withpen pencircle scaled boxgridwidth withcolor boxgridcolor ; enddef ; @@ -1186,6 +1195,9 @@ vardef baseline_grid (expr pxy, pdir, at_baseline) = fi ; ) ; clip grid to pxy ; + bb := boundingbox grid ; + grid := grid shifted (0,boxgridshift) ; + setbounds grid to bb ; grid else : nullpicture diff --git a/Master/texmf-dist/metapost/context/base/mp-figs.mp b/Master/texmf-dist/metapost/context/base/mp-figs.mp index aa6bc0399fb..da5fa0d1691 100644 --- a/Master/texmf-dist/metapost/context/base/mp-figs.mp +++ b/Master/texmf-dist/metapost/context/base/mp-figs.mp @@ -22,7 +22,7 @@ def registerfigure(expr name,width,height) = begingroup ; save s ; string s ; s := cleanstring(name) ; scantokens( s & "_width := " & decimal(width)) ; - scantokens( s & "_height := " & decimal(width)) ; + scantokens( s & "_height := " & decimal(height)) ; endgroup ; enddef ; diff --git a/Master/texmf-dist/metapost/context/base/mp-grph.mp b/Master/texmf-dist/metapost/context/base/mp-grph.mp index 18c43c57b53..87a17967734 100644 --- a/Master/texmf-dist/metapost/context/base/mp-grph.mp +++ b/Master/texmf-dist/metapost/context/base/mp-grph.mp @@ -56,19 +56,20 @@ string graphictextformat ; graphictextformat := "plain" ; string graphictextstring ; graphictextstring := "" ; string graphictextfile ; graphictextfile := "dummy.mpo" ; +def data_mpo_file = job_name & "-mp.mpo" enddef ; +def data_mpy_file = job_name & "-mp.mpy" enddef ; + def savegraphictext (expr str) = - graphictextfile := jobname & ".mpo" ; if (graphictextstring<>"") : - write graphictextstring to graphictextfile ; + write graphictextstring to data_mpo_file ; graphictextstring := "" ; fi ; - write str to graphictextfile ; + write str to data_mpo_file ; let erasegraphictextfile = relax ; enddef ; def erasegraphictextfile = - graphictextfile := jobname & ".mpo" ; - write EOF to graphictextfile ; + write EOF to data_mpo_file ; let erasegraphictextfile = relax ; enddef ; @@ -213,7 +214,7 @@ def dofinishgraphictext text x_op_x = if (urcorner dashpart i) = origin : outline_fill := false ; fi ; endfor ; scratchpicture := nullpicture ; - readfile(jobname & ".mpy") ; + readfile(data_mpy_file) ; scratchpicture := (scratchpicture shifted -llcorner scratchpicture) scaled (1/10) ; if not d_color and not f_color : d_color := true ; fi if s_color : d_color := false ; f_color := false ; fi ; diff --git a/Master/texmf-dist/metapost/context/base/mp-mlib.mp b/Master/texmf-dist/metapost/context/base/mp-mlib.mp new file mode 100644 index 00000000000..6722c81e4f4 --- /dev/null +++ b/Master/texmf-dist/metapost/context/base/mp-mlib.mp @@ -0,0 +1,156 @@ +%D \module +%D [ file=mp-mlib.mp, +%D version=2008.03.21, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=specials, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See licen-en.pdf for +%C details. + +if unknown mplib : endinput ; fi ; +if known context_mlib : endinput ; fi ; + +boolean context_mlib ; context_mlib := true ; + +numeric _tt_w_[], _tt_h_[], _tt_d_[] ; +numeric _tt_n_ ; _tt_n_ := 0 ; +picture _tt_p_ ; _tt_p_ := nullpicture ; +boolean _trial_run_ ; _trial_run_ := false ; + +def resettextexts = + _tt_n_ := 0 ; + _tt_p_ := nullpicture ; +enddef ; + +extra_endfig := ";draw _tt_p_; " & extra_endfig ; +extra_beginfig := extra_beginfig & "resettextexts;"; + +vardef rawtextext(expr str) = + if _trial_run_ : + image ( + _tt_n_ := _tt_n_ + 1 ; + _tt_p_ := image ( + draw _tt_p_ ; + draw unitsquare withprescript "tf" withpostscript decimal _tt_n_ & ":" & str ; + ) ; + draw unitsquare ; + ) + else : + image ( + _tt_n_ := _tt_n_ + 1 ; + draw unitsquare + xscaled _tt_w_[_tt_n_] + yscaled (_tt_h_[_tt_n_] + _tt_d_[_tt_n_]) + withprescript "ts" + withpostscript decimal _tt_n_ & ":" & str ; + ) + fi +enddef ; + +vardef textext@#(expr txt) = + interim labeloffset := textextoffset ; + if string txt : + thelabel@#(rawtextext(txt),origin) + else : + thelabel@#(txt,origin) + fi +enddef ; + +def circular_shade (expr p, n, ca, cb) = + begingroup ; + save ab, r ; pair ab ; numeric r ; + r := (xpart lrcorner p - xpart llcorner p) ++ (ypart urcorner p - ypart lrcorner p) ; + set_circular_vector(ab,r)(p,n) ; + fill p withcircularshade(ab,ab,0,r,ca,cb) ; + if trace_shades : + drawarrow ab -- ab shifted (0,r) withpen pencircle scaled 1pt withcolor .5white ; + fi ; + endgroup ; +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 withlinearshade(a,b,ca,cb) ; + if trace_shades : + drawarrow a -- b withpen pencircle scaled 1pt withcolor .5white ; + fi ; + endgroup ; +enddef ; +def withcircularshade (expr a, b, ra, rb, ca, cb) = + withprescript + "cs" + withpostscript + "0 1 " & decimal shadefactor & " " & + colordecimals ca & " " & ddecimal (a shifted shadeoffset) & " " & decimal ra & " " & + colordecimals cb & " " & ddecimal (b shifted shadeoffset) & " " & decimal rb +enddef ; +def withlinearshade (expr a, b, ca, cb) = + withprescript + "ls" + withpostscript + "0 1 " & decimal shadefactor & " " & + colordecimals ca & " " & ddecimal (a shifted shadeoffset) & " " & + colordecimals cb & " " & ddecimal (b shifted shadeoffset) +enddef ; +string _defined_cs_pre_[], _defined_cs_post_[] ; numeric _defined_cs_ ; _defined_cs_:= 0 ; +vardef define_circular_shade (expr a, b, ra, rb, ca, cb) = + _defined_cs_ := _defined_cs_ + 1 ; + _defined_cs_pre_ [_defined_cs_] := "cs" ; + _defined_cs_post_[_defined_cs_] := "0 1 " & decimal shadefactor & " " & + colordecimals ca & " " & ddecimal (a shifted shadeoffset) & " " & decimal ra & " " & + colordecimals cb & " " & ddecimal (b shifted shadeoffset) & " " & decimal rb ; + _defined_cs_ +enddef ; +vardef define_linear_shade (expr a, b, ca, cb) = + _defined_cs_ := _defined_cs_ + 1 ; + _defined_cs_pre_ [_defined_cs_] := "ls" ; + _defined_cs_post_[_defined_cs_] := "0 1 " & decimal shadefactor & " " & + colordecimals ca & " " & ddecimal (a shifted shadeoffset) & " " & + colordecimals cb & " " & ddecimal (b shifted shadeoffset) ; + _defined_cs_ +enddef ; +primarydef p withshade sc = + p withprescript _defined_cs_pre_[sc] withpostscript _defined_cs_post_[sc] +enddef ; +def shadecolor(expr sc) = % obsolete + 1 withprescript _defined_cs_pre_[sc] withpostscript _defined_cs_post_[sc] +enddef ; + +def graphictext primary t = + if _trial_run_ : + let dographictextindeed = nographictext ; + else : + let dographictextindeed = dographictext ; + fi + dographictextindeed(t) +enddef ; +def dographictext (expr t) = + begingroup ; + save figurepicture ; picture figurepicture ; + figurepicture := currentpicture ; currentpicture := nullpicture ; + currentgraphictext := currentgraphictext + 1 ; + dofinishgraphictext +enddef ; +def nographictext (expr t) text rest = + draw unitsquare withprescript "gt" withpostscript t ; +enddef ; +def savegraphictext (expr str) = +enddef ; +def erasegraphictextfile = +enddef ; + +def doexternalfigure (expr filename) text transformation = + draw unitsquare transformation withprescript "fg" withpostscript filename ; +enddef ; + +extra_beginfig := extra_beginfig & "currentgraphictext := 0 ; " ; +extra_endfig := extra_endfig & "finishsavingdata ; " ; +extra_endfig := extra_endfig & "resettextexts ; " ; + +boolean cmykcolors ; cmykcolors := true ; +boolean spotcolors ; spotcolors := true ; 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 diff --git a/Master/texmf-dist/metapost/context/base/mp-text.mp b/Master/texmf-dist/metapost/context/base/mp-text.mp index 2e061df0996..c1f9c80e909 100644 --- a/Master/texmf-dist/metapost/context/base/mp-text.mp +++ b/Master/texmf-dist/metapost/context/base/mp-text.mp @@ -61,18 +61,11 @@ vardef textext@#(expr txt) = interim labeloffset := textextoffset ; noftexpictures := noftexpictures + 1 ; if string txt : -% if textextstring <> "" : -% _s_ := "verbatimtex " & textextstring & " etex ;" ; -% else : -% _s_ := "" ; -% fi ; if hobbiestextext : % the tex.mp method as fallback (see tex.mp) -% write _s_ to "mptextmp.mp" ; write _s_ & "btex " & txt & " etex" to "mptextmp.mp" ; write EOF to "mptextmp.mp" ; scantokens "input mptextmp" else : -% write "% setup : " & _s_ to jobname & ".mpt" ; write "% figure " & decimal charcode & " : " & "texpictures[" & decimal noftexpictures & "] := btex " & txt & " etex ;" to jobname & ".mpt" ; diff --git a/Master/texmf-dist/metapost/context/base/mp-tool.mp b/Master/texmf-dist/metapost/context/base/mp-tool.mp index fca61cb346a..24f2e6676fd 100644 --- a/Master/texmf-dist/metapost/context/base/mp-tool.mp +++ b/Master/texmf-dist/metapost/context/base/mp-tool.mp @@ -102,34 +102,88 @@ vardef ddecimal primary p = decimal xpart p & " " & decimal ypart p enddef ; -extra_endfig := extra_endfig - & "special " - & "(" - & ditto - & "%%HiResBoundingBox: " - & ditto - & "&ddecimal llcorner currentpicture" - & "&space" - & "&ddecimal urcorner currentpicture" - & ");"; +% is now built in + +% extra_endfig := extra_endfig +% & "special " +% & "(" +% & ditto +% & "%%HiResBoundingBox: " +% & ditto +% & "&ddecimal llcorner currentpicture" +% & "&space" +% & "&ddecimal urcorner currentpicture" +% & ");"; + +%D Colors: + +nocolormodel := 1 ; +greycolormodel := 3 ; +rgbcolormodel := 5 ; +cmykcolormodel := 7 ; + +let grayscale = numeric ; + +% def colorlike(expr c) text v = % colorlike(a) b, c, d ; +% forsuffixes i=v : % save i ; +% if cmykcolor c : +% cmykcolor i ; +% elseif rgbcolor c : +% rgbcolor i ; +% else : +% grayscale i ; +% fi ; +% endfor ; +% enddef ; + +vardef colorlike(text c) text v = % colorlike(a) b, c, d ; + save _p_ ; picture _p_ ; + forsuffixes i=v : + _p_ := image(draw origin withcolor c ;) ; % intercept pre and postscripts + if (colormodel _p_ = cmykcolormodel) : + cmykcolor i ; + elseif (colormodel _p_ = rgbcolormodel) : + rgbcolor i ; + else : + grayscale i ; + fi ; + endfor ; +enddef ; + +% if (unknown colormodel) : +% def colormodel = +% rgbcolormodel +% enddef ; +% fi ; %D Also handy (when we flush colors): vardef dddecimal primary c = - decimal redpart c & " " & decimal greenpart c & " " & decimal bluepart c + decimal redpart c & " " & decimal greenpart c & " " & decimal bluepart c enddef ; -%D We have standardized data file names: +vardef ddddecimal primary c = + decimal cyanpart c & " " & decimal magentapart c & " " & decimal yellowpart c & " " & decimal blackpart c +enddef ; -if not known _data_prefix_ : +vardef colordecimals primary c = + if cmykcolor 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 + else : + decimal c + fi +enddef ; - string _data_prefix_ ; _data_prefix_ = "mpd-" ; - string _data_suffix_ ; _data_suffix_ = ".tmp" ; +%D We have standardized data file names: -fi ; +def job_name = + jobname +enddef ; -def data_file = - _data_prefix_ & decimal charcode & _data_suffix_ +def data_mpd_file = + job_name & "-mp.mpd" enddef ; %D Because \METAPOST\ has a hard coded limit of 4~datafiles, @@ -143,12 +197,12 @@ boolean savingdata ; savingdata := false ; def savedata expr txt = if collapse_data : + write txt to data_mpd_file ; + else : write if savingdata : txt else : "\MPdata{" & decimal charcode & "}{" & txt & "}" fi - & "%" to jobname & _data_suffix_ ; - else : - write txt to data_file ; + & "%" to data_mpd_file ; fi ; enddef ; @@ -158,15 +212,19 @@ def startsavingdata = write "\MPdata{" & decimal charcode & "}{%" to - jobname & _data_suffix_ ; + data_mpd_file ; fi ; enddef ; def stopsavingdata = - savingdata := false ; if collapse_data : - write "}%" to jobname & _data_suffix_ ; + write "}%" to data_mpd_file ; fi ; + savingdata := false ; +enddef ; + +def finishsavingdata = + write EOF to data_mpd_file ; enddef ; %D Instead of a keystroke eating save and allocation @@ -650,6 +708,16 @@ color cyan ; cyan = (0,1,1) ; color magenta ; magenta = (1,0,1) ; color yellow ; yellow = (1,1,0) ; +def colortype(expr c) = + if cmykcolor c : cmykcolor elseif rgbcolor c : rgbcolor else : grayscale fi +enddef ; +vardef whitecolor(expr c) = + if cmykcolor c : (0,0,0,0) elseif rgbcolor c : (1,1,1) else : 1 fi +enddef ; +vardef blackcolor(expr c) = + if cmykcolor c : (0,0,0,1) elseif rgbcolor c : (0,0,0) else : 0 fi +enddef ; + %D Well, this is the dangerous and naive version: def drawfill text t = @@ -819,7 +887,18 @@ primarydef p randomized s = fi elseif pair p : p randomshifted s - elseif color p : + elseif cmykcolor p : + if color s : + (uniformdeviate cyanpart s * cyanpart p, + uniformdeviate magentapart s * magentapart p, + uniformdeviate yellowpart s * yellowpart p, + uniformdeviate blackpart s * blackpart p) + elseif pair s : + ((xpart s + uniformdeviate (ypart s - xpart s)) * p) + else : + (uniformdeviate s * p) + fi + elseif rgbcolor p : if color s : (uniformdeviate redpart s * redpart p, uniformdeviate greenpart s * greenpart p, @@ -829,6 +908,14 @@ primarydef p randomized s = else : (uniformdeviate s * p) fi + elseif color p : + if color s : + (uniformdeviate graypart s * graypart p) + elseif pair s : + ((xpart s + uniformdeviate (ypart s - xpart s)) * p) + else : + (uniformdeviate s * p) + fi else : p + uniformdeviate s fi) @@ -1138,7 +1225,7 @@ def visualizedfill expr c = enddef ; def do_visualizeddraw text t = - draworigin ; + draworigin ; drawpath _c_ t ; drawcontrollines _c_ ; drawcontrolpoints _c_ ; @@ -2220,9 +2307,10 @@ enddef ; % handy for myself def addbackground text t = - begingroup ; save p ; picture p ; + begingroup ; save p, b ; picture p ; path b ; + b := boundingbox currentpicture ; p := currentpicture ; currentpicture := nullpicture ; - fill boundingbox p t ; addto currentpicture also p ; + fill b t ; setbounds currentpicture to b ; addto currentpicture also p ; endgroup ; enddef ; @@ -2371,6 +2459,41 @@ enddef ; % p % enddef ; +%D Handy: + +def break = + exitif true fi ; +enddef ; + +%D New too: + +primarydef p xstretched w = + (p if (bbwidth (p)>0) and (w>0) : xscaled (w/bbwidth (p)) fi) +enddef ; + +primarydef p ystretched h = + (p if (bbheight(p)>0) and (h>0) : yscaled (h/bbheight(p)) fi) +enddef ; + +primarydef p snapped s = + hide ( if path p : + forever : + exitif (bbheight(p) <= s) and (bbwidth(p) <= s) ; + p := p scaled (1/2) ; + endfor ; + elseif numeric p : + forever : + exitif p <= s ; + p := p scaled (1/2) ; + endfor ; + fi ; ) + p +enddef ; + % done endinput ; + +end + +end |