[metapost] Whether any metapost package could provide all kinds of arrows, just like arrows in MicroSoft Visio.?

Marcus Harnisch marcus.harnisch at gmx.net
Sun Nov 28 22:19:31 CET 2004


mylatex mylatex writes:
 > So, I wants to know whether any metapost package could provide all
 > kinds of arrows, just like arrows in MicroSoft Visio.

As a matter of fact I wrote a package that extends the drawarrow
macros to provide unfilled arrowheads, as well as inset for an
arrowhead. Well, that's certainly not all of what Visio provides but
adds to the bunch.

I hereby put the code into public domain.

Warning: Apart from the original arrow code which I copied, the code
was written by me some time between five and six years ago and I
haven't really looked into reading (never mind writing) Metapost
macros a lot since then. I don't claim that the code makes any sense
but it did Work For Me(tm).

Enjoy,
Marcus

-------------- next part --------------
%
% Author: Marcus Harnisch <marcus.harnisch at gmx.net>
%
% The macros drawemptyarrow and drawdblemptyarrow work exactly as
% their well known counterparts drawarrow and drawdblarrow, except
% that the arrowheads are not filled.

% Additionally the arrowhead macro has been redefined to provide
% an arrow inset option. It's value must be in the range [0,1] and
% gives the ratio between the length of the inset and the arrowhead's
% true length (NOT ahlength).
newinternal ahinset;
ahinset := 0; % The arrowhead's inset must have a value between 0 and 1

vardef arrowhead expr p =
  save q,e,i,j,qq,pp; path q; pair e; path i; pair qq[];
  numeric pp;
  e = point length p of p;
  q = gobble(p shifted -e cutafter makepath(pencircle scaled 2ahlength))
      cuttings;
  qq0 = point 0 of (q rotated .5ahangle);
  qq1 = point 0 of (q rotated -.5ahangle);
  (pp, whatever) = q intersectiontimes (qq0--qq1);
  i = subpath (pp, length q) of q;
  qq2 = point (arctime (ahinset*arclength i) of i) of i;
  (q rotated .5ahangle & reverse q rotated -.5ahangle -- qq2 -- cycle)  shifted e
enddef;

def drawemptyarrow expr p = _apth:=p; _finearr enddef;
def drawdblemptyarrow expr p = _apth:=p; _findearr enddef;

def _finearr text t =
  draw _apth t;
  unfilldraw arrowhead _apth  t;
  draw arrowhead _apth  t;
enddef;

def _findearr text t =
  draw _apth t;
  unfilldraw arrowhead _apth withpen currentpen  t;
  draw arrowhead _apth withpen currentpen  t;
  unfilldraw arrowhead  reverse _apth  withpen currentpen  t;
  draw arrowhead  reverse _apth  withpen currentpen  t
enddef;


More information about the metapost mailing list