* custom zig zag sidebars
@ 2021-04-28 15:27 mf
2021-04-28 15:53 ` Hans Hagen
0 siblings, 1 reply; 5+ messages in thread
From: mf @ 2021-04-28 15:27 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1314 bytes --]
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?
Massi
[-- Attachment #1.2: Type: text/html, Size: 2830 bytes --]
[-- Attachment #2: zigzag-sidebar.tex --]
[-- Type: text/x-tex, Size: 3699 bytes --]
\definesidebar[zigzag1][rulecolor=black,distance=4pt,rulethickness=1pt,alternative=2]
\definesidebar[zigzag2][rulecolor=red,distance=4pt,rulethickness=1pt,alternative=3]
\definesidebar[wave1][rulecolor=blue,distance=4pt,rulethickness=1pt,alternative=4]
\definesidebar[wave2][rulecolor=cyan,distance=4pt,rulethickness=1pt,alternative=5]
\definesidebar[obliquedashes][rulecolor=darkgreen,distance=4pt,rulethickness=1pt,alternative=6]
\definesidebar[longobliquedashes][rulecolor=orange,distance=10pt,rulethickness=1pt,alternative=7]
\startMPcode
def draw_pattern_bar(expr a, b, pattern, patternlength, patternheight, linewidth, linecolor) =
begingroup ;
save p, z, step ;
pair p, z, step ;
step := ( ( b - a ) / arclength( a -- b ) ) * patternlength ;
path z ; z := pattern xscaled patternlength yscaled patternheight rotated (angle(step)) ;
p := a ;
forever :
draw
z shifted p
withpen pencircle scaled linewidth
withcolor linecolor ;
p := p + step ;
exitif arclength( a -- p ) > arclength( a -- b ) ;
endfor ;
endgroup ;
enddef ;
% from metapost/context/base/mpiv/mp-apos.mpiv
def anch_sidebars_draw (expr p_b_self, p_e_self, y_b_self, y_e_self, h_b_self, d_e_self,
x, y, w, h, alternative, distance, linewidth, linecolor, topoffset, bottomoffset) =
% beware, we anchor at (x,y)
begingroup ;
if alternative = 1 :
interim linecap := rounded ;
else :
interim linecap := butt ;
fi ;
save a, b ; pair a, b ;
if p_b_self = p_e_self :
a := (-distance,y_b_self+h_b_self-y) ;
b := (-distance,y_e_self-d_e_self-y) ;
elseif RealPageNumber = p_b_self :
a := (-distance,y_b_self+h_b_self-y) ;
b := (-distance,0) ;
elseif RealPageNumber = p_e_self :
a := (-distance,h) ;
b := (-distance,y_e_self-d_e_self-y) ;
else :
a := (-distance,h) ;
b := (-distance,0) ;
fi ;
a := (xpart a, min(ypart a + topoffset, h)) ;
b := (xpart b, max(ypart b - bottomoffset,0)) ;
if alternative = 2 :
draw_pattern_bar( a, b, ((0,0)--(0.25,-0.5)--(0.75,0.5)--(1,0)), 2pt, 2pt, linewidth, linecolor ) ;
elseif alternative = 3 :
draw_pattern_bar( a, b, ((0,0)--(0.25,-0.5)--(0.75,0.5)--(1,0)), 4pt, 1.5pt, linewidth, linecolor ) ;
elseif alternative = 4 :
draw_pattern_bar( a, b, ( ((0,0) .. controls (0,0.5) and (0.5,0.5) .. (0.5,0)) -- ((0.5,0) .. controls (0.5,-0.5) and (1,-0.5) .. (1,0)) ), 6pt, 4pt, linewidth, linecolor ) ;
elseif alternative = 5 :
draw_pattern_bar( a, b, ( (0,0) .. controls (0,1) and (1,1) .. (1,0) ), 4pt, 2pt, linewidth, linecolor ) ;
elseif alternative = 6 :
draw_pattern_bar( a, b, ( (0,0.5) .. (1,-0.5) ), 4pt, 2pt, linewidth, linecolor ) ;
elseif alternative = 7 :
draw_pattern_bar( a, b, ( (0,-0.5) .. (1,0.5) ), 22pt, 5pt, linewidth, linecolor ) ;
else :
draw
a -- b
if alternative = 1 :
dashed (withdots scaled (linewidth/2))
fi
withpen pencircle scaled linewidth
withcolor linecolor ;
fi ;
endgroup ;
enddef ;
\stopMPcode
\starttext
\startsidebar[zigzag1]\input knuth\relax\stopsidebar\par
\blank
\startsidebar[zigzag2]\input sapolsky\relax\stopsidebar\par
\blank
\startsidebar[wave1]\input knuth\relax\stopsidebar\par
\blank
\startsidebar[wave2]\input sapolsky\relax\stopsidebar\par
\blank
\startsidebar[obliquedashes]\input knuth\relax\stopsidebar\par
\blank
\startsidebar[longobliquedashes]\input sapolsky\relax\stopsidebar\par
\stoptext
[-- Attachment #3: Type: text/plain, Size: 493 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: custom zig zag sidebars
2021-04-28 15:27 custom zig zag sidebars mf
@ 2021-04-28 15:53 ` Hans Hagen
2021-04-29 9:52 ` mf
0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2021-04-28 15:53 UTC (permalink / raw)
To: mailing list for ConTeXt users, mf
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 ;
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: custom zig zag sidebars
2021-04-28 15:53 ` Hans Hagen
@ 2021-04-29 9:52 ` mf
2021-04-29 21:08 ` Otared Kavian
0 siblings, 1 reply; 5+ messages in thread
From: mf @ 2021-04-29 9:52 UTC (permalink / raw)
To: Hans Hagen, mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: custom zig zag sidebars
2021-04-29 9:52 ` mf
@ 2021-04-29 21:08 ` Otared Kavian
2021-04-29 21:30 ` Hans Hagen
0 siblings, 1 reply; 5+ messages in thread
From: Otared Kavian @ 2021-04-29 21:08 UTC (permalink / raw)
To: mailing list for ConTeXt users
Hi Massi,
Thank you and Hans for this nice feature: is it going to be included in the built-in sidebar ?
Best regards: Otared
> On 29 Apr 2021, at 11:52, mf <massifr@fastwebnet.it> wrote:
>
> 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
> ___________________________________________________________________________________
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: custom zig zag sidebars
2021-04-29 21:08 ` Otared Kavian
@ 2021-04-29 21:30 ` Hans Hagen
0 siblings, 0 replies; 5+ messages in thread
From: Hans Hagen @ 2021-04-29 21:30 UTC (permalink / raw)
To: mailing list for ConTeXt users, Otared Kavian
On 4/29/2021 11:08 PM, Otared Kavian wrote:
> Hi Massi,
>
> Thank you and Hans for this nice feature: is it going to be included in the built-in sidebar ?
At some point yes.
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-04-29 21:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 15:27 custom zig zag sidebars mf
2021-04-28 15:53 ` Hans Hagen
2021-04-29 9:52 ` mf
2021-04-29 21:08 ` Otared Kavian
2021-04-29 21:30 ` Hans Hagen
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).