[metapost] augment drawoptions

Stephan Hennig mailing_list at arcor.de
Fri Apr 11 15:03:09 CEST 2008


Hi,

inside a macro I want to determine some draw options, say pen width,
while keeping others that are already set by drawoption(), e.g., stroke
colour.  The straight forward way to do that is directly applying my
modified draw options to the drawing command, e.g.,

def mydraw =
  draw fullcircle scaled 100 withpen pencircle scaled 4bp;
enddef;

beginfig(1);
  drawoptions(withcolor red);% Set colour.
  mydraw;% Circle is drawn red and with a 4bp pen.
endfig;

Now, in macro mydraw I do not directly draw anything, but delegate all
drawing operations to another macro, so that I cannot apply 'withpen
...' directly.  My idea was to augment the current draw option by
'withpen ...', that is, keeping the former drawoptions configuration,
but append my own draw options.

The definition of drawoptions in plain.mp is

def drawoptions(text t) =
  def _op_ = t enddef
enddef;

My approach to a macro addtodrawoption() doesn't work (attached below).
 How would you do that?

Best regards,
Stephan Hennig



def addtodrawoptions(text t) =
  def _myop_ = _op_ t enddef;
  let _op_ = _myop_;
enddef;

def mydraw =
begingroup
  addtodrawoptions(withpen pencircle scaled 4bp);
  draw fullcircle scaled 100;
endgroup
enddef;

beginfig(1);
  drawoptions(withcolor red);% Set colour.
  mydraw;% Circle is drawn red and with a 4bp pen.
endfig;
end


More information about the metapost mailing list