From: mf <massifr@fastwebnet.it>
To: Hans Hagen <j.hagen@xs4all.nl>,
mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: custom zig zag sidebars
Date: Thu, 29 Apr 2021 11:52:08 +0200 [thread overview]
Message-ID: <f9837762-c601-a387-9b04-a9071b59c7c8@fastwebnet.it> (raw)
In-Reply-To: <d6899e2f-3a08-bccb-230f-9793619a973f@xs4all.nl>
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
___________________________________________________________________________________
next prev parent reply other threads:[~2021-04-29 9:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-28 15:27 mf
2021-04-28 15:53 ` Hans Hagen
2021-04-29 9:52 ` mf [this message]
2021-04-29 21:08 ` Otared Kavian
2021-04-29 21:30 ` Hans Hagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f9837762-c601-a387-9b04-a9071b59c7c8@fastwebnet.it \
--to=massifr@fastwebnet.it \
--cc=j.hagen@xs4all.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).