Il 28/04/21 17:53, Hans Hagen ha scritto:
On 4/28/2021 5:27 PM, mf wrote:
Hello,
I made an experiment to add alternatives to sidebars (see attachment).
I discovered the sidebar is drawn by anch_sidebars_draw in
metapost/context/base/mpiv/mp-apos.mpiv.
I've redefined it locally to add alternatives.
To make fancy, zig zag bars I defined a macro, draw_pattern_bar, that
draws a bar repeating a pattern which is a path connecting (0,0) and
(1,0).
The macro has 3 parameters (actually it has more params, but the
remainder are anch_sidebars_draw params):
- a pattern, which is a path from (0,0) to (1,0) that should have a
vertical size = 1; it's a sort of waveform
- a pattern length, by which the pattern is xsized
- a pattern width, by which the pattern is ysized
Then the pattern is rotated along the bar direction (so -90 degrees)
and drawn many times until it covers the bar length.
A proposal and a question:
- patternlength and patternwidth could become \setupsidebar params;
alternative (=2,3,4...) could be used to specify the pattern (a sort
of waveform); currently alternative=0 is a solid bar and alternative=1
is a dashed one
- in case of long patterns (a patternlength spanning more lines of
text) the last replica of the pattern should be clipped not to exceed
the last line of the sidebarred text (see the last example): how can
that be done?
how about
def draw_pattern_bar(expr a, b, pattern, patternlength, patternheight,
linewidth, linecolor) =
draw image (
begingroup ;
save p, q, stp ;
pair p, q, stp ;
stp := ( ( b - a ) / arclength( a -- b ) ) * patternlength ;
path q ; q := pattern xscaled patternlength yscaled
patternheight rotated (angle(stp)) ;
p := a ;
forever :
draw
q shifted p
withpen pencircle scaled linewidth
withcolor linecolor ;
p := p + stp ;
exitif arclength( a -- p ) > arclength( a -- b ) ;
endfor ;
endgroup ;
clip currentpicture to
(xpart llcorner currentpicture, ypart b) --
(xpart lrcorner currentpicture, ypart b) --
(xpart urcorner currentpicture, ypart a) --
(xpart ulcorner currentpicture, ypart a) -- cycle ;
) ;
enddef ;
Thank you, Hans.
To save this example, I wikified \setupsidebar, \definesidebar and
\startsidebar...\stopsidebar.
If you do something on alternatives, let me know.
Massi
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________