diff options
author | Karl Berry <karl@freefriends.org> | 2006-11-16 01:02:47 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-11-16 01:02:47 +0000 |
commit | 3c85b55e2f245fb7edac7e445f107e6d0bb423ae (patch) | |
tree | c62b7f80edafe0455310d08e09f4218127bf9e87 /Master/texmf-dist/metapost | |
parent | e5ecff27a26ef59e1dbe9702677687fd7107be3a (diff) |
context update
git-svn-id: svn://tug.org/texlive/trunk@2444 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/metapost')
-rw-r--r-- | Master/texmf-dist/metapost/context/base/metafun.mp | 10 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-base.mp | 556 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-core.mp | 74 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-spec.mp | 181 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-tool.mp | 13 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/context/base/mp-txts.mp | 67 |
6 files changed, 735 insertions, 166 deletions
diff --git a/Master/texmf-dist/metapost/context/base/metafun.mp b/Master/texmf-dist/metapost/context/base/metafun.mp index 5071013c5f8..cfbf7b2f98c 100644 --- a/Master/texmf-dist/metapost/context/base/metafun.mp +++ b/Master/texmf-dist/metapost/context/base/metafun.mp @@ -23,10 +23,15 @@ %D that we use (unless overloaded) the settings of \type %D {mpost}. +%D First we input John Hobby's metapost plain file. However, +%D because we want to prevent dependency problems and in the +%D end even may use a patched version, we prefer to use a +%D copy, + if unknown ahangle : - input plain.mp ; % John Hobby's file + input mp-base.mp ; % input plain.mp ; else : - let dump = relax ; + let dump = relax ; fi ; input mp-tool.mp ; @@ -34,6 +39,7 @@ input mp-spec.mp ; input mp-core.mp ; input mp-page.mp ; input mp-text.mp ; +input mp-txts.mp ; input mp-shap.mp ; input mp-butt.mp ; input mp-char.mp ; diff --git a/Master/texmf-dist/metapost/context/base/mp-base.mp b/Master/texmf-dist/metapost/context/base/mp-base.mp new file mode 100644 index 00000000000..87f3fd2f742 --- /dev/null +++ b/Master/texmf-dist/metapost/context/base/mp-base.mp @@ -0,0 +1,556 @@ +% This is (currently) a copy of the plain.mp file. We use a copy +% because (1) we want to make sure that there are no unresolved +% dependencies, and (2) we may patch this file eventually. + +% This file gives the macros for plain MetaPost +% It contains all the features of plain METAFONT except those specific to +% font-making. (See The METAFONTbook by D.E. Knuth). +% There are also a number of macros for labeling figures, etc. +string base_name, base_version; base_name="plain"; base_version="0.63"; + +message "Preloading the plain mem file, version "&base_version; + +delimiters (); % this makes parentheses behave like parentheses +def upto = step 1 until enddef; % syntactic sugar +def downto = step -1 until enddef; +def exitunless expr c = exitif not c enddef; +let relax = \; % ignore the word `relax', as in TeX +let \\ = \; % double relaxation is like single +def ]] = ] ] enddef; % right brackets should be loners +def -- = {curl 1}..{curl 1} enddef; +def --- = .. tension infinity .. enddef; +def ... = .. tension atleast 1 .. enddef; + +def gobble primary g = enddef; +primarydef g gobbled gg = enddef; +def hide(text t) = exitif numeric begingroup t;endgroup; enddef; +def ??? = hide(interim showstopping:=1; showdependencies) enddef; +def stop expr s = message s; gobble readstring enddef; + +warningcheck:=1; +tracinglostchars:=1; + +def interact = % sets up to make "show" commands stop + hide(showstopping:=1; tracingonline:=1) enddef; + +def loggingall = % puts tracing info into the log + tracingcommands:=3; tracingtitles:=1; tracingequations:=1; + tracingcapsules:=1; tracingspecs:=2; tracingchoices:=1; tracinglostchars:=1; + tracingstats:=1; tracingoutput:=1; tracingmacros:=1; tracingrestores:=1; + enddef; + +def tracingall = % turns on every form of tracing + tracingonline:=1; showstopping:=1; loggingall enddef; + +def tracingnone = % turns off every form of tracing + tracingcommands:=0; tracingtitles:=0; tracingequations:=0; + tracingcapsules:=0; tracingspecs:=0; tracingchoices:=0; tracinglostchars:=0; + tracingstats:=0; tracingoutput:=0; tracingmacros:=0; tracingrestores:=0; + enddef; + + + +%% dash patterns + +vardef dashpattern(text t) = + save on, off, w; + let on=_on_; + let off=_off_; + w = 0; + nullpicture t +enddef; + +tertiarydef p _on_ d = + begingroup save pic; + picture pic; pic=p; + addto pic doublepath (w,w)..(w+d,w); + w := w+d; + pic shifted (0,d) + endgroup +enddef; + +tertiarydef p _off_ d = + begingroup w:=w+d; + p shifted (0,d) + endgroup +enddef; + + + +%% basic constants and mathematical macros + +% numeric constants +newinternal eps,epsilon,infinity,_; +eps := .00049; % this is a pretty small positive number +epsilon := 1/256/256; % but this is the smallest +infinity := 4095.99998; % and this is the largest +_ := -1; % internal constant to make macros unreadable but shorter + +newinternal mitered, rounded, beveled, butt, squared; +mitered:=0; rounded:=1; beveled:=2; % linejoin types +butt:=0; rounded:=1; squared:=2; % linecap types + + +% pair constants +pair right,left,up,down,origin; +origin=(0,0); up=-down=(0,1); right=-left=(1,0); + +% path constants +path quartercircle,halfcircle,fullcircle,unitsquare; +fullcircle = makepath pencircle; +halfcircle = subpath (0,4) of fullcircle; +quartercircle = subpath (0,2) of fullcircle; +unitsquare=(0,0)--(1,0)--(1,1)--(0,1)--cycle; + +% transform constants +transform identity; +for z=origin,right,up: z transformed identity = z; endfor + +% color constants +color black, white, red, green, blue, background; +black = (0,0,0); +white = (1,1,1); +red = (1,0,0); +green = (0,1,0); +blue = (0,0,1); +background = white; % The user can reset this + +% picture constants +picture blankpicture,evenly,withdots; +blankpicture=nullpicture; % `display blankpicture...' +evenly=dashpattern(on 3 off 3); % `dashed evenly' +withdots=dashpattern(off 2.5 on 0 off 2.5); % `dashed withdots' + +% string constants +string ditto, EOF; +ditto = char 34; % ASCII double-quote mark +EOF = char 0; % end-of-file for readfrom and write..to + +% pen constants +pen pensquare,penrazor,penspeck; +pensquare = makepen(unitsquare shifted -(.5,.5)); +penrazor = makepen((-.5,0)--(.5,0)--cycle); +penspeck=pensquare scaled eps; + +% nullary operators +vardef whatever = save ?; ? enddef; + +% unary operators +let abs = length; + +vardef round primary u = + if numeric u: floor(u+.5) + elseif pair u: (round xpart u, round ypart u) + else: u fi enddef; + +vardef ceiling primary x = -floor(-x) enddef; + +vardef byte primary s = + if string s: ASCII fi s enddef; + +vardef dir primary d = right rotated d enddef; + +vardef unitvector primary z = z/abs z enddef; + +vardef inverse primary T = + transform T_; T_ transformed T = identity; T_ enddef; + +vardef counterclockwise primary c = + if turningnumber c <= 0: reverse fi c enddef; + +vardef tensepath expr r = + for k=0 upto length r - 1: point k of r --- endfor + if cycle r: cycle else: point infinity of r fi enddef; + +vardef center primary p = .5[llcorner p, urcorner p] enddef; + + + +% binary operators + +primarydef x mod y = (x-y*floor(x/y)) enddef; +primarydef x div y = floor(x/y) enddef; +primarydef w dotprod z = (xpart w * xpart z + ypart w * ypart z) enddef; + +primarydef x**y = if y=2: x*x else: takepower y of x fi enddef; +def takepower expr y of x = + if x>0: mexp(y*mlog x) + elseif (x=0) and (y>0): 0 + else: 1 + if y=floor y: + if y>=0: for n=1 upto y: *x endfor + else: for n=_ downto y: /x endfor + fi + else: hide(errmessage "Undefined power: " & decimal x&"**"&decimal y) + fi fi enddef; + +vardef direction expr t of p = + postcontrol t of p - precontrol t of p enddef; + +vardef directionpoint expr z of p = + a_:=directiontime z of p; + if a_<0: errmessage("The direction doesn't occur"); fi + point a_ of p enddef; + +secondarydef p intersectionpoint q = + begingroup save x_,y_; (x_,y_)=p intersectiontimes q; + if x_<0: errmessage("The paths don't intersect"); origin + else: .5[point x_ of p, point y_ of q] fi endgroup +enddef; + +tertiarydef p softjoin q = + begingroup c_:=fullcircle scaled 2join_radius shifted point 0 of q; + a_:=ypart(c_ intersectiontimes p); b_:=ypart(c_ intersectiontimes q); + if a_<0:point 0 of p{direction 0 of p} else: subpath(0,a_) of p fi + ... if b_<0:{direction infinity of q}point infinity of q + else: subpath(b_,infinity) of q fi endgroup enddef; +newinternal join_radius,a_,b_; path c_; + + +path cuttings; % what got cut off + +tertiarydef a cutbefore b = % tries to cut as little as possible + begingroup save t; + (t, whatever) = a intersectiontimes b; + if t<0: + cuttings:=point 0 of a; + a + else: cuttings:= subpath (0,t) of a; + subpath (t,length a) of a + fi + endgroup +enddef; + +tertiarydef a cutafter b = + reverse (reverse a cutbefore b) + hide(cuttings:=reverse cuttings) +enddef; + + + +% special operators +vardef incr suffix $ = $:=$+1; $ enddef; +vardef decr suffix $ = $:=$-1; $ enddef; + +def reflectedabout(expr w,z) = % reflects about the line w..z + transformed + begingroup transform T_; + w transformed T_ = w; z transformed T_ = z; + xxpart T_ = -yypart T_; xypart T_ = yxpart T_; % T_ is a reflection + T_ endgroup enddef; + +def rotatedaround(expr z, d) = % rotates d degrees around z + shifted -z rotated d shifted z enddef; +let rotatedabout = rotatedaround; % for roundabout people + +vardef min(expr u)(text t) = % t is a list of numerics, pairs, or strings + save u_; setu_ u; for uu = t: if uu<u_: u_:=uu; fi endfor + u_ enddef; + +vardef max(expr u)(text t) = % t is a list of numerics, pairs, or strings + save u_; setu_ u; for uu = t: if uu>u_: u_:=uu; fi endfor + u_ enddef; + +def setu_ primary u = + if pair u: pair u_ elseif string u: string u_ fi; + u_=u enddef; + +def flex(text t) = % t is a list of pairs + hide(n_:=0; for z=t: z_[incr n_]:=z; endfor + dz_:=z_[n_]-z_1) + z_1 for k=2 upto n_-1: ...z_[k]{dz_} endfor ...z_[n_] enddef; +newinternal n_; pair z_[],dz_; + +def superellipse(expr r,t,l,b,s)= + r{up}...(s[xpart t,xpart r],s[ypart r,ypart t]){t-r}... + t{left}...(s[xpart t,xpart l],s[ypart l,ypart t]){l-t}... + l{down}...(s[xpart b,xpart l],s[ypart l,ypart b]){b-l}... + b{right}...(s[xpart b,xpart r],s[ypart r,ypart b]){r-b}...cycle enddef; + +vardef interpath(expr a,p,q) = + for t=0 upto length p-1: a[point t of p, point t of q] + ..controls a[postcontrol t of p, postcontrol t of q] + and a[precontrol t+1 of p, precontrol t+1 of q] .. endfor + if cycle p: cycle + else: a[point infinity of p, point infinity of q] fi enddef; + +vardef solve@#(expr true_x,false_x)= % @#(true_x)=true, @#(false_x)=false + tx_:=true_x; fx_:=false_x; + forever: x_:=.5[tx_,fx_]; exitif abs(tx_-fx_)<=tolerance; + if @#(x_): tx_ else: fx_ fi :=x_; endfor + x_ enddef; % now x_ is near where @# changes from true to false +newinternal tolerance, tx_,fx_,x_; tolerance:=.01; + +vardef buildcycle(text ll) = + save ta_, tb_, k_, i_, pp_; path pp_[]; + k_=0; + for q=ll: pp_[incr k_]=q; endfor + i_=k_; + for i=1 upto k_: + (ta_[i], length pp_[i_]-tb_[i_]) = + pp_[i] intersectiontimes reverse pp_[i_]; + if ta_[i]<0: + errmessage("Paths "& decimal i &" and "& decimal i_ &" don't intersect"); + fi + i_ := i; + endfor + for i=1 upto k_: subpath (ta_[i],tb_[i]) of pp_[i] .. endfor + cycle +enddef; + + + +%% units of measure + +mm=2.83464; pt=0.99626; dd=1.06601; bp:=1; +cm=28.34645; pc=11.95517; cc=12.79213; in:=72; + +vardef magstep primary m = mexp(46.67432m) enddef; + + + +%% macros for drawing and filling + +def drawoptions(text t) = + def _op_ = t enddef +enddef; + +linejoin:=rounded; % parameters that effect drawing +linecap:=rounded; +miterlimit:=10; + +drawoptions(); + +pen currentpen; +picture currentpicture; + +def fill expr c = addto currentpicture contour c _op_ enddef; +def draw expr p = + addto currentpicture + if picture p: + also p + else: + doublepath p withpen currentpen + fi + _op_ +enddef; +def filldraw expr c = + addto currentpicture contour c withpen currentpen + _op_ enddef; +def drawdot expr z = + addto currentpicture contour makepath currentpen shifted z + _op_ enddef; + +def unfill expr c = fill c withcolor background enddef; +def undraw expr p = draw p withcolor background enddef; +def unfilldraw expr c = filldraw c withcolor background enddef; +def undrawdot expr z = drawdot z withcolor background enddef; +def erase text t = + def _e_ = withcolor background hide(def _e_=enddef;) enddef; + t _e_ +enddef; +def _e_= enddef; + +def cutdraw text t = + begingroup interim linecap:=butt; draw t _e_; endgroup enddef; + +vardef image(text t) = + save currentpicture; + picture currentpicture; + currentpicture := nullpicture; + t; + currentpicture +enddef; + +def pickup secondary q = + if numeric q: numeric_pickup_ else: pen_pickup_ fi q enddef; +def numeric_pickup_ primary q = + if unknown pen_[q]: errmessage "Unknown pen"; clearpen + else: currentpen:=pen_[q]; + pen_lft:=pen_lft_[q]; + pen_rt:=pen_rt_[q]; + pen_top:=pen_top_[q]; + pen_bot:=pen_bot_[q]; + currentpen_path:=pen_path_[q] fi; enddef; +def pen_pickup_ primary q = + currentpen:=q; + pen_lft:=xpart penoffset down of currentpen; + pen_rt:=xpart penoffset up of currentpen; + pen_top:=ypart penoffset left of currentpen; + pen_bot:=ypart penoffset right of currentpen; + path currentpen_path; enddef; +newinternal pen_lft,pen_rt,pen_top,pen_bot,pen_count_; + +vardef savepen = pen_[incr pen_count_]=currentpen; + pen_lft_[pen_count_]=pen_lft; + pen_rt_[pen_count_]=pen_rt; + pen_top_[pen_count_]=pen_top; + pen_bot_[pen_count_]=pen_bot; + pen_path_[pen_count_]=currentpen_path; + pen_count_ enddef; + +def clearpen = currentpen:=nullpen; + pen_lft:=pen_rt:=pen_top:=pen_bot:=0; + path currentpen_path; + enddef; +def clear_pen_memory = + pen_count_:=0; + numeric pen_lft_[],pen_rt_[],pen_top_[],pen_bot_[]; + pen currentpen,pen_[]; + path currentpen_path, pen_path_[]; + enddef; + +vardef lft primary x = x + if pair x: (pen_lft,0) else: pen_lft fi enddef; +vardef rt primary x = x + if pair x: (pen_rt,0) else: pen_rt fi enddef; +vardef top primary y = y + if pair y: (0,pen_top) else: pen_top fi enddef; +vardef bot primary y = y + if pair y: (0,pen_bot) else: pen_bot fi enddef; + +vardef penpos@#(expr b,d) = + (x@#r-x@#l,y@#r-y@#l)=(b,0) rotated d; + x@#=.5(x@#l+x@#r); y@#=.5(y@#l+y@#r) enddef; + +def penstroke text t = + forsuffixes e = l,r: path_.e:=t; endfor + fill path_.l -- reverse path_.r -- cycle enddef; +path path_.l,path_.r; + + + +%% High level drawing commands + +newinternal ahlength, ahangle; +ahlength := 4; % default arrowhead length 4bp +ahangle := 45; % default head angle 45 degrees + +vardef arrowhead expr p = + save q,e; path q; pair e; + e = point length p of p; + q = gobble(p shifted -e cutafter makepath(pencircle scaled 2ahlength)) + cuttings; + (q rotated .5ahangle & reverse q rotated -.5ahangle -- cycle) shifted e +enddef; + +path _apth; +def drawarrow expr p = _apth:=p; _finarr enddef; +def drawdblarrow expr p = _apth:=p; _findarr enddef; + +def _finarr text t = + draw _apth t; + filldraw arrowhead _apth t +enddef; + +def _findarr text t = + draw _apth t; + fill arrowhead _apth withpen currentpen t; + fill arrowhead reverse _apth withpen currentpen t +enddef; + + + +%% macros for labels + +newinternal bboxmargin; bboxmargin:=2bp; + +vardef bbox primary p = + llcorner p-(bboxmargin,bboxmargin) -- lrcorner p+(bboxmargin,-bboxmargin) + -- urcorner p+(bboxmargin,bboxmargin) -- ulcorner p+(-bboxmargin,bboxmargin) + -- cycle +enddef; + +string defaultfont; +newinternal defaultscale, labeloffset; +defaultfont = "cmr10"; +defaultscale := 1; +labeloffset := 3bp; + +vardef thelabel@#(expr s,z) = % Position s near z + save p; picture p; + if picture s: p=s + else: p = s infont defaultfont scaled defaultscale + fi; + p shifted (z + labeloffset*laboff@# - + (labxf@#*lrcorner p + labyf@#*ulcorner p + + (1-labxf@#-labyf@#)*llcorner p + ) + ) +enddef; + +def label = draw thelabel enddef; +newinternal dotlabeldiam; dotlabeldiam:=3bp; +vardef dotlabel@#(expr s,z) = + label@#(s,z); + interim linecap:=rounded; + draw z withpen pencircle scaled dotlabeldiam; +enddef; +def makelabel = dotlabel enddef; + +pair laboff, laboff.lft, laboff.rt, laboff.top, laboff.bot; +pair laboff.ulft, laboff.llft, laboff.urt, laboff.lrt; +laboff =(0,0); labxf =.5; labyf =.5; +laboff.lft=(-1,0); labxf.lft=1; labyf.lft=.5; +laboff.rt =(1,0); labxf.rt =0; labyf.rt =.5; +laboff.bot=(0,-1); labxf.bot=.5; labyf.bot=1; +laboff.top=(0,1); labxf.top=.5; labyf.top=0; +laboff.ulft=(-.7,.7);labxf.ulft=1; labyf.ulft=0; +laboff.urt=(.7,.7); labxf.urt=0; labyf.urt=0; +laboff.llft=-(.7,.7);labxf.llft=1; labyf.llft=1; +laboff.lrt=(.7,-.7); labxf.lrt=0; labyf.lrt=1; + +vardef labels@#(text t) = + forsuffixes $=t: + label@#(str$,z$); endfor + enddef; +vardef dotlabels@#(text t) = + forsuffixes $=t: + dotlabel@#(str$,z$); endfor + enddef; +vardef penlabels@#(text t) = + forsuffixes $$=l,,r: forsuffixes $=t: + makelabel@#(str$.$$,z$.$$); endfor endfor + enddef; + + +def range expr x = numtok[x] enddef; +def numtok suffix x=x enddef; +tertiarydef m thru n = + m for x=m+1 step 1 until n: , numtok[x] endfor enddef; + + + +%% Overall adminstration + +string extra_beginfig, extra_endfig; +extra_beginfig = extra_endfig = ""; + +def beginfig(expr c) = + begingroup + charcode:=c; + clearxy; clearit; clearpen; + pickup defaultpen; + drawoptions(); + scantokens extra_beginfig; +enddef; + +def endfig = + scantokens extra_endfig; + shipit; + endgroup +enddef; + + +%% last-minute items + +vardef z@#=(x@#,y@#) enddef; + +def clearxy = save x,y enddef; +def clearit = currentpicture:=nullpicture enddef; +def shipit = shipout currentpicture enddef; + +let bye = end; outer end,bye; + +clear_pen_memory; % initialize the `savepen' mechanism +clearit; + +newinternal defaultpen; +pickup pencircle scaled .5bp; % set default line width +defaultpen := savepen; diff --git a/Master/texmf-dist/metapost/context/base/mp-core.mp b/Master/texmf-dist/metapost/context/base/mp-core.mp index eb038163e35..92036febfc9 100644 --- a/Master/texmf-dist/metapost/context/base/mp-core.mp +++ b/Master/texmf-dist/metapost/context/base/mp-core.mp @@ -350,13 +350,14 @@ enddef ; numeric nofmultipars ; nofmultipars := 0 ; -boolean obey_multi_par_hang ; obey_multi_par_hang := true ; -boolean obey_multi_par_more ; obey_multi_par_more := true ; -boolean snap_multi_par_tops ; snap_multi_par_tops := true ; -boolean local_multi_par_area ; local_multi_par_area := false ; -boolean ignore_multi_par_page ; ignore_multi_par_page := false ; - -boolean one_piece_multi_par ; one_piece_multi_par := false ; +boolean obey_multi_par_hang ; obey_multi_par_hang := true ; +boolean obey_multi_par_more ; obey_multi_par_more := true ; +boolean snap_multi_par_tops ; snap_multi_par_tops := true ; +boolean local_multi_par_area ; local_multi_par_area := false ; +boolean ignore_multi_par_page ; ignore_multi_par_page := false ; +boolean force_multi_par_chain ; force_multi_par_chain := true ; +boolean one_piece_multi_par ; one_piece_multi_par := false ; +boolean check_multi_par_chain ; check_multi_par_chain := true ; % extra page check def simplify_multi_pars = % boundingbox ipv shape als optie for i := 1 upto nofmultipars : @@ -720,14 +721,24 @@ fi ; % fallback - multipar := + % multipar := + % llxy[fpos] -- + % lrxy[tpos] -- + % urxy[tpos] -- + % ulxy[fpos] -- cycle ; + % + % save_multipar (1,1,multipar) ; + + % we need to take the boundingbox because there can be + % more lines and we want a proper rectange - llxy[fpos] -- - lrxy[tpos] -- + multipar := + ulxy[fpos] -- urxy[tpos] -- - ulxy[fpos] -- cycle ; + lrxy[fpos] -- + llxy[tpos] -- cycle ; - save_multipar (1,1,multipar) ; + save_multipar (1,1,boundingbox(multipar)) ; else : @@ -743,7 +754,6 @@ fi ; if (nxy[fpos]=RealPageNumber) and (InsideTextArea(i,par_start_pos)) : - % first one in chain ii := i ; @@ -930,11 +940,16 @@ snapped_multi_pos(ulxy[tpos]) -- % second loop +if force_multi_par_chain or (ii > 1) : + for i=ii+1 upto nn-1 : % rest of chain / todo : hang -%if (nxy[fpos]<=RealPageNumber) and (nxy[tpos]>=RealPageNumber) : +% we need to test, else we get a <lineheight bottom one +% triggering a whole text frame; weird + +if (not check_multi_par_chain) or ((nxy[fpos]<RealPageNumber) and (nxy[tpos]>RealPageNumber)) : multipar := set_multipar(i) ; @@ -951,10 +966,12 @@ snapped_multi_pos(ulxy[tpos]) -- save_multipar(i,2,multipar) ; -%fi ; +fi ; endfor ; +fi ; + % end of normal/fallback fi ; @@ -963,6 +980,14 @@ fi ; endgroup ; fi ; + % potential safeguard: + + % for i=1 upto nofmultipars : + % if length p <= 4 : + % multipars[i] := boundingbox(multipars[i]) ; + % fi ; + % end ; + % quick hack for gb: one_piece_multi_par := (nofmultipars=1) and (pn=tn) ; @@ -990,20 +1015,24 @@ enddef ; def draw_par = % 1 2 3 11 12 do_draw_par(pxy) ; do_draw_par(txy) ; do_draw_par(bxy) ; for i = pxy, txy, bxy : - if boxgridtype= 1 : + if boxgridtype = 1 : boxgriddirection := origin ; draw baseline_grid (i,boxgriddirection,true ) withcolor boxgridcolor ; - elseif boxgridtype= 2 : + elseif boxgridtype = 2 : boxgriddirection := origin ; draw baseline_grid (i,boxgriddirection,false) withcolor boxgridcolor ; - elseif boxgridtype= 3 : + elseif boxgridtype = 3 : boxgriddirection := origin ; draw baseline_grid (i,boxgriddirection,true ) withcolor boxgridcolor ; draw baseline_grid (i,boxgriddirection,true ) shifted (0,ExHeight) withcolor boxgridcolor ; - elseif boxgridtype=11 : + elseif boxgridtype = 4 : + boxgriddirection := origin ; + draw baseline_grid (i,boxgriddirection,true ) + shifted (0,ExHeight/2) withcolor boxgridcolor ; + elseif boxgridtype = 11 : draw graphic_grid(i,boxgriddistance,boxgriddistance,boxgriddistance/2,boxgriddistance/2) ; - elseif boxgridtype=12 : + elseif boxgridtype = 12 : draw graphic_grid(i,boxgriddistance,boxgriddistance,0,0) ; fi ; endfor ; @@ -1090,6 +1119,9 @@ def draw_multi_pars = draw baseline_grid (multipars[i],up,true ) withcolor boxgridcolor ; draw baseline_grid (multipars[i],up,true ) shifted (0,ExHeight) withcolor boxgridcolor ; + elseif boxgridtype= 4 : + draw baseline_grid (multipars[i],up,true ) + shifted (0,ExHeight/2) withcolor boxgridcolor ; elseif boxgridtype=11 : draw graphic_grid(multipars[i],boxgriddistance,boxgriddistance,boxgriddistance/2,boxgriddistance/2) ; elseif boxgridtype=12 : @@ -1349,4 +1381,4 @@ def ProcessSyncTask(expr p, c) = fill p withcolor c ; enddef ; -endinput ;
\ No newline at end of file +endinput ; diff --git a/Master/texmf-dist/metapost/context/base/mp-spec.mp b/Master/texmf-dist/metapost/context/base/mp-spec.mp index 9fe3c724fdc..a46b09e92dd 100644 --- a/Master/texmf-dist/metapost/context/base/mp-spec.mp +++ b/Master/texmf-dist/metapost/context/base/mp-spec.mp @@ -35,6 +35,8 @@ numeric _special_counter_ ; _special_counter_ := 0 ; numeric _color_counter_ ; _color_counter_ := 11 ; % < 10 reserved numeric _special_signal_ ; _special_signal_ := 123 ; +numeric _special_div_ ; _special_div_ := 1000 ; + %D When set to \type {true}, shading will be supported. Some %D day I will also write an additional directive. @@ -48,12 +50,31 @@ boolean _inline_specials_ ; _inline_specials_ := false ; string _global_specials_ ; _global_specials_ := "" ; string _local_specials_ ; _local_specials_ := "" ; +% vardef add_special_signal = % write the version number +% if (length _global_specials_>0) or (length _local_specials_ >0) : +% special ("%%MetaPostSpecials: 1.0 " & decimal _special_signal_ ) ; +% fi ; +% enddef ; +% +% After some reported problems at the \CONTEXT\ mailing list, +% Taco's came up with: + +% TH: \quotation {Ok, got it. There is a bug in mp-spec.mp (inside metafun). +% Because of a wrapping number, it fails to recognize the fact that there +% are embedded specials at all.} The corrected definition is: + vardef add_special_signal = % write the version number - if (length _global_specials_>0) or (length _local_specials_ >0) : - special ("%%MetaPostSpecials: 1.0 " & decimal _special_signal_ ) ; + if (length _global_specials_ <> 0) or (length _local_specials_ <> 0) : + special ("%%MetaPostSpecials: 2.0 " & decimal _special_signal_ & " " & decimal _special_div_) ; fi ; enddef ; +% \quotation {It now tests for \quote {not equal to zero} instead of +% \quote {larger than zero}: because of all the included files, the +% string \type {_local_specials_} becomes longer than the maximum number +% \quote {length} can return, so it returns -32768 instead, and that is +% of course less than zero.} + vardef add_extra_specials = scantokens _global_specials_ ; scantokens _local_specials_ ; @@ -263,12 +284,12 @@ enddef ; primarydef p withshade sc = % == p withcolor shadecolor(sh) hide (_color_counter_ := _color_counter_ + 1) - p withcolor (_special_signal_/1000,_color_counter_/1000,sc/1000) + p withcolor (_special_signal_/_special_div_,_color_counter_/_special_div_,sc/_special_div_) enddef ; vardef shadecolor(expr sc) = hide (_color_counter_ := _color_counter_ + 1) - (_special_signal_/1000,_color_counter_/1000,sc/1000) + (_special_signal_/_special_div_,_color_counter_/_special_div_,sc/_special_div_) enddef ; %D Figure inclusion. @@ -288,8 +309,7 @@ def doexternalfigure (expr filename) text transformation = addto p contour unitsquare scaled 0 ; setbounds p to unitsquare transformed t ; _color_counter_ := _color_counter_ + 1 ; - draw p withcolor (_special_signal_/1000,_color_counter_/1000,_special_counter_/1000) ; -%draw p withcolor (_special_signal_/1000,cef/1000,_special_counter_/1000) ; + draw p withcolor (_special_signal_/_special_div_,_color_counter_/_special_div_,_special_counter_/_special_div_) ; endgroup ; enddef ; @@ -312,11 +332,9 @@ def dohyperpath (expr destination) expr somepath = flush_special(20, 7, ddecimal (xpart llcorner somepath, ypart llcorner somepath) & " " & ddecimal (xpart urcorner somepath, ypart urcorner somepath) & " " & destination) ; -% currenthyperlink := currenthyperlink + 1 ; _color_counter_ := _color_counter_ + 1 ; fill boundingbox unitsquare scaled 0 withcolor - (_special_signal_/1000,_color_counter_/1000,_special_counter_/1000) ; -% (_special_signal_/1000,currenthyperlink/1000,_special_counter_/1000) ; + (_special_signal_/_special_div_,_color_counter_/_special_div_,_special_counter_/_special_div_) ; endgroup ; enddef ; @@ -380,14 +398,14 @@ vardef cmyk(expr c,m,y,k) = if not ok : save s ; string s ; s := dddecimal (c,m,y) & " " & decimal k ; _cmyk_counter_ := _cmyk_counter_ + 1 ; - cmykcolorpattern[_cmyk_counter_/1000] := s ; + cmykcolorpattern[_cmyk_counter_/_special_div_] := s ; cmykcolorhash[c][m][y][k] := _cmyk_counter_ ; flush_special(1, 7, decimal _cmyk_counter_ & " " & s) ; _local_specials_ := _local_specials_ & " cmykcolorhash[" & decimal c & "][" & decimal m & "][" & decimal y & "][" & decimal k & "] := -1 ; " ; fi ; - (_special_signal_/1000,1/1000,cmykcolorhash[c][m][y][k]/1000) + (_special_signal_/_special_div_,1/_special_div_,cmykcolorhash[c][m][y][k]/_special_div_) else : (1-c-k,1-m-k,1-y-k) fi @@ -414,68 +432,6 @@ resetspotcolors ; boolean spotcolors ; spotcolors := false ; % true string spotcolorpattern[] ; % needed for transparancies -% vardef spotcolor(expr p, s) = -% if spotcolors : -% save ok, pc_tag ; boolean ok ; string pc_tag ; -% pc_tag := "_pct_"&p ; -% if not unstringed(pc_tag) : -% _spotcolor_number_ := _spotcolor_number_ + 1 ; -% setunstringed(pc_tag,_spotcolor_number_) ; -% fi ; -% pp := getunstringed(pc_tag) ; -% if unknown spotcolorhash[pp][s] : -% ok := false ; % not yet defined -% elseif spotcolorhash[pp][s] = -1 : -% ok := false ; % locally defined and undefined -% else : -% ok := true ; % globally already defined -% fi ; -% if not ok : -% save ss ; string ss ; ss := p & " " & decimal s ; -% _spotcolor_counter_ := _spotcolor_counter_ + 1 ; -% spotcolorpattern[_spotcolor_counter_/1000] := ss ; -% spotcolorhash[pp][s] := _spotcolor_counter_ ; -% flush_special(2, 5, decimal _spotcolor_counter_ & " " & ss) ; -% _local_specials_ := _local_specials_ & -% "spotcolorhash["&decimal pp&"]["&decimal s&"]:=-1;" ; -% fi ; -% (_special_signal_/1000,2/1000,spotcolorhash[pp][s]/1000) -% else : -% (1-s,1-s,1-s) -% fi -% enddef ; - -% vardef spotcolor(expr p, s) = -% if spotcolors : -% save ok, pc_tag ; boolean ok ; string pc_tag ; -% pc_tag := "_pct_"&p ; -% if not unstringed(pc_tag) : -% _spotcolor_number_ := _spotcolor_number_ + 1 ; -% setunstringed(pc_tag,_spotcolor_number_) ; -% fi ; -% pp := getunstringed(pc_tag) ; -% if unknown spotcolorhash[pp][s] : -% ok := false ; % not yet defined -% elseif spotcolorhash[pp][s] = -1 : -% ok := false ; % locally defined and undefined -% else : -% ok := true ; % globally already defined -% fi ; -% if not ok : -% save ss ; string ss ; ss := p & " " & decimal s ; -% _spotcolor_counter_ := _spotcolor_counter_ + 1 ; -% spotcolorpattern[_spotcolor_counter_/1000] := ss ; -% spotcolorhash[pp][s] := _spotcolor_counter_ ; -% flush_special(2, 5, decimal _spotcolor_counter_ & " " & ss) ; -% _local_specials_ := _local_specials_ & -% "spotcolorhash["&decimal pp&"]["&decimal s&"]:=-1;" ; -% fi ; -% (_special_signal_/1000,2/1000,spotcolorhash[pp][s]/1000) -% else : -% (1-s,1-s,1-s) -% fi -% enddef ; - vardef spotcolor(expr p, s) = multitonecolor(p, 1, "", decimal s) enddef ; @@ -505,13 +461,13 @@ vardef multitonecolor(expr n, f, d, p) = % name fractions names factors if not ok : save ss ; string ss ; ss := n & " " & decimal f & " " & if d = "" : n else : d fi & " " & p ; _spotcolor_counter_ := _spotcolor_counter_ + 1 ; - spotcolorpattern[_spotcolor_counter_/1000] := ss ; + spotcolorpattern[_spotcolor_counter_/_special_div_] := ss ; spotcolorhash[pp][ps] := _spotcolor_counter_ ; flush_special(2, 7, decimal _spotcolor_counter_ & " " & ss) ; _local_specials_ := _local_specials_ & "spotcolorhash["&decimal pp&"]["&decimal ps&"]:=-1;" ; fi ; - (_special_signal_/1000,2/1000,spotcolorhash[pp][ps]/1000) + (_special_signal_/_special_div_,2/_special_div_,spotcolorhash[pp][ps]/_special_div_) else : .5white fi @@ -529,64 +485,7 @@ differencetransparent := 11 ; exclusiontransparent := 12 ; % nottransparent := 0 ; % compatibletransparent := 99 ; -% fill fullcircle scaled 10cm withcolor transparant(.8,3,color) ; - -% vardef transparent(expr n, t, c) = -% save s, ss, nn, cc, is_cmyk, is_spot, ok ; -% string s, ss ; numeric nn ; color cc ; boolean is_cmyk, is_spot, ok ; -% % transparancy type -% if string n : -% if expandafter known scantokens(n&"transparent") : -% nn := scantokens(n&"transparent") ; -% else : -% nn := 0 ; -% fi -% else : % nn := min(n,13) -% nn := if n<13 : n else : nn := 0 fi ; -% fi ; -% % we need to expand the color (can be cmyk(..) or predefined) -% cc := c ; % expand color -% % check for cmyk special -% is_cmyk := (redpart cc = _special_signal_/1000) -% and (greenpart cc = 1/1000) ; -% is_spot := (redpart cc = _special_signal_/1000) -% and (greenpart cc = 2/1000) ; -% % build special string, fetch cmyk components -% s := decimal nn & " " & decimal t & " " & -% if is_cmyk : cmykcolorpattern[bluepart cc] -% elseif is_spot : spotcolorpattern[bluepart cc] -% else : dddecimal cc fi ; -% % check if this one is already used -% ss := "tr_" & s ; -% % efficiency hack -% if expandafter unknown scantokens(ss) : -% ok := false ; % not yet defined -% elseif scantokens(ss) < 0 : -% ok := false ; % locally defined and undefined -% else : -% ok := true ; % globally already defined -% fi ; -% if not ok : -% if is_spot : -% flush_special(5, 6, s) ; -% elseif is_cmyk : -% flush_special(4, 8, s) ; -% else : -% flush_special(3, 7, s) ; -% fi ; -% scantokens(ss) := _special_counter_ ; -% _local_specials_ := _local_specials_ & -% "scantokens(" & ditto & ss & ditto & ") := -1 ;" ; -% fi ; -% % go ahead -% if is_spot : -% (_special_signal_/1000,5/1000,scantokens(ss)/1000) -% elseif is_cmyk : -% (_special_signal_/1000,4/1000,scantokens(ss)/1000) -% else : -% (_special_signal_/1000,3/1000,scantokens(ss)/1000) -% fi -% enddef ; +% fill fullcircle scaled 10cm withcolor transparant(8,.3,red) ; vardef transparent(expr n, t, c) = save s, ss, nn, cc, is_cmyk, is_spot, ok ; @@ -604,10 +503,10 @@ vardef transparent(expr n, t, c) = % we need to expand the color (can be cmyk(..) or predefined) cc := c ; % expand color % check for cmyk special - is_cmyk := (redpart cc = _special_signal_/1000) - and (greenpart cc = 1/1000) ; - is_spot := (redpart cc = _special_signal_/1000) - and (greenpart cc = 2/1000) ; + is_cmyk := (redpart cc = _special_signal_/_special_div_) + and (greenpart cc = 1/_special_div_) ; + is_spot := (redpart cc = _special_signal_/_special_div_) + and (greenpart cc = 2/_special_div_) ; % build special string, fetch cmyk components s := decimal nn & " " & decimal t & " " & if is_cmyk : cmykcolorpattern[bluepart cc] @@ -642,11 +541,11 @@ vardef transparent(expr n, t, c) = fi ; % go ahead if is_spot : - (_special_signal_/1000,5/1000,scantokens(ss)/1000) + (_special_signal_/_special_div_,5/_special_div_,scantokens(ss)/_special_div_) elseif is_cmyk : - (_special_signal_/1000,4/1000,scantokens(ss)/1000) + (_special_signal_/_special_div_,4/_special_div_,scantokens(ss)/_special_div_) else : - (_special_signal_/1000,3/1000,scantokens(ss)/1000) + (_special_signal_/_special_div_,3/_special_div_,scantokens(ss)/_special_div_) fi enddef ; @@ -712,7 +611,7 @@ endinput ; % vardef normalgray(expr s ) = (s,s,s) enddef ; % vardef normalrgb (expr r,g,b ) = (r,g,b) enddef ; -% vardef normalcmyk(expr c,m,y,k) = if cmykcolors : save ok ; boolean ok ; if unknown cmykcolorhash[c][m][y][k] : ok := false ; elseif cmykcolorhash[c][m][y][k] = -1 : ok := false ; else : ok := true ; fi ; if not ok : save s ; string s ; s := dddecimal (c,m,y) & " " & decimal k ; _cmyk_counter_ := _cmyk_counter_ + 1 ; cmykcolorpattern[_cmyk_counter_/1000] := s ; cmykcolorhash[c][m][y][k] := _cmyk_counter_ ; flush_special(1, 7, decimal _cmyk_counter_ & " " & s) ; _local_specials_ := _local_specials_ & " cmykcolorhash[" & decimal c & "][" & decimal m & "][" & decimal y & "][" & decimal k & "] := -1 ; " ; fi ; (_special_signal_/1000,1/1000,cmykcolorhash[c][m][y][k]/1000) else : (1-c-k,1-m-k,1-y-k) fi enddef ; +% vardef normalcmyk(expr c,m,y,k) = if cmykcolors : save ok ; boolean ok ; if unknown cmykcolorhash[c][m][y][k] : ok := false ; elseif cmykcolorhash[c][m][y][k] = -1 : ok := false ; else : ok := true ; fi ; if not ok : save s ; string s ; s := dddecimal (c,m,y) & " " & decimal k ; _cmyk_counter_ := _cmyk_counter_ + 1 ; cmykcolorpattern[_cmyk_counter_/_special_div_] := s ; cmykcolorhash[c][m][y][k] := _cmyk_counter_ ; flush_special(1, 7, decimal _cmyk_counter_ & " " & s) ; _local_specials_ := _local_specials_ & " cmykcolorhash[" & decimal c & "][" & decimal m & "][" & decimal y & "][" & decimal k & "] := -1 ; " ; fi ; (_special_signal_/_special_div_,1/_special_div_,cmykcolorhash[c][m][y][k]/_special_div_) else : (1-c-k,1-m-k,1-y-k) fi enddef ; % vardef gray(expr s) = normalgray(s ) enddef ; % vardef rgb (expr r,g,b) = normalrgb (r,g,b ) enddef ; diff --git a/Master/texmf-dist/metapost/context/base/mp-tool.mp b/Master/texmf-dist/metapost/context/base/mp-tool.mp index 925b9ca4449..3b52b9d5d47 100644 --- a/Master/texmf-dist/metapost/context/base/mp-tool.mp +++ b/Master/texmf-dist/metapost/context/base/mp-tool.mp @@ -994,6 +994,7 @@ enddef ; vardef arrowheadonpath (expr p, s) = save autoarrows ; boolean autoarrows ; autoarrows := true ; + set_ahlength(scaled ahfactor) ; % added arrowhead p if s<1 : cutafter (point (s*arclength(p)+.5ahlength) on p) fi enddef ; @@ -1174,7 +1175,10 @@ boolean autoarrows ; autoarrows := false ; numeric ahfactor ; ahfactor := 2.5 ; def set_ahlength (text t) = - ahlength := (ahfactor*pen_size(_op_ t)) ; % _op_ added +% ahlength := (ahfactor*pen_size(_op_ t)) ; % _op_ added +% problem: _op_ can contain color so a no-go, we could apply the transform +% but i need to figure out the best way (fakepicture and take components). + ahlength := (ahfactor*pen_size(t)) ; enddef ; vardef pen_size (text t) = @@ -1204,7 +1208,6 @@ enddef ; vardef pointarrow (expr pat, loc, len, off) = save l, r, s, t ; path l, r ; numeric s ; pair t ; t := if pair loc : loc else : point loc along pat fi ; -% draw t withpen pencircle scaled 10 withcolor .5white ; s := len/2 - off ; if s<=0 : s := 0 elseif s>len : s := len fi ; r := pat cutbefore t ; r := (r cutafter point (arctime s of r) of r) ; @@ -2361,6 +2364,12 @@ vardef c_phantom (expr b) (text t) = fi ; enddef ; +% mark paths (for external progs to split) + +% def somepath(expr p) +% p +% enddef ; + % done endinput ; diff --git a/Master/texmf-dist/metapost/context/base/mp-txts.mp b/Master/texmf-dist/metapost/context/base/mp-txts.mp new file mode 100644 index 00000000000..f208c714900 --- /dev/null +++ b/Master/texmf-dist/metapost/context/base/mp-txts.mp @@ -0,0 +1,67 @@ +%D \module +%D [ file=mp-txts.mp, +%D version=2006.06.08, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=more text support, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright=PRAGMA] +%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 context_tool : input mp-tool ; fi ; +if known context_txts : endinput ; fi ; + +boolean context_txts ; context_txts := true ; + +%D The real code: + +string txtfile ; txtfile := "" ; +string txtfont ; txtfont := defaultfont ; +string txtpref ; txtpref := "00001::::" ; +numeric txtnext ; txtnext := 0 ; +numeric txtdepth ; txtdepth := 0 ; + +vardef nexttxt = + txtnext := txtnext + 1 ; + txtnext +enddef ; + +picture savedtxts[] ; +numeric depthtxts[] ; + +vardef zerofilled(expr fd) = + if fd<10: "0000" else : + if fd<100: "000" else : + if fd<1000: "00" else : + if fd<10000: "0" else : + fi fi fi fi & decimal fd +enddef; + +vardef savetxt(expr n,w,h,d) text t = + depthtxts[n] := d ; + savedtxts[n] := ((txtpref & zerofilled(n)) infont txtfont) xysized(w,h+d) t +enddef ; + +vardef sometxt(expr n) = + if known savedtxts[n] : + txtdepth := depthtxts[n] ; savedtxts[n] + else : + txtdepth := 0 ; nullpicture + fi +enddef ; + +def loadtxts = + if txtfile <> "" : + readfile(txtfile) ; + fi ; +enddef ; + +def StartTexts = + loadtxts ; +enddef ; + +def StopTexts = +enddef ; |