\path in markup dashed line

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

\path in markup dashed line

Andrew Bernard
Is there any way to get the \path command in a markup to draw dashed
lines? I am aware I can use postscript of course.

Andrew

Reply | Threaded
Open this post in threaded view
|

Re: \path in markup dashed line

Andrew Bernard
No response from anwhere?

On 16/08/2020 4:43 pm, Andrew Bernard wrote:
> Is there any way to get the \path command in a markup to draw dashed
> lines? I am aware I can use postscript of course.
>
> Andrew

Reply | Threaded
Open this post in threaded view
|

Re: \path in markup dashed line

Thomas Morley-2
Am Mo., 7. Sept. 2020 um 03:53 Uhr schrieb Andrew Bernard
<[hidden email]>:
>
> No response from anwhere?
>
> On 16/08/2020 4:43 pm, Andrew Bernard wrote:
> > Is there any way to get the \path command in a markup to draw dashed
> > lines? I am aware I can use postscript of course.
> >
> > Andrew
>

Hi Andrew,

I see no other chance than redoing all from scratch.
Though, I'm not sure whether it would be successful. At least I've not
the time to try ...

Sorry,
  Harm

Reply | Threaded
Open this post in threaded view
|

Re: \path in markup dashed line

Aaron Hill
On 2020-09-07 12:52 pm, Thomas Morley wrote:
> Am Mo., 7. Sept. 2020 um 03:53 Uhr schrieb Andrew Bernard
> <[hidden email]>:
>>
>> No response from anwhere?

First an apology from me, Andrew.  I thought I had already replied to
your post, but I can find no record of that.  Perhaps I started looking
into things and got side-tracked without following up.


>> On 16/08/2020 4:43 pm, Andrew Bernard wrote:
>> > Is there any way to get the \path command in a markup to draw dashed
>> > lines? I am aware I can use postscript of course.
>> >
>> > Andrew
>>
>
> Hi Andrew,
>
> I see no other chance than redoing all from scratch.
> Though, I'm not sure whether it would be successful. At least I've not
> the time to try ...

Given a cursory glance, it would seem doable.  One would need to
copy/borrow the existing logic for \path and then add a suitable
"setdash" command to the PostScript output and an equivalent
"stroke-dasharray" attribute to the SVG output.  Looking at how
\draw-dashed-line works should provide a useful reference.


-- Aaron Hill

Reply | Threaded
Open this post in threaded view
|

Re: \path in markup dashed line

Aaron Hill
On 2020-09-07 1:20 pm, Aaron Hill wrote:
> Given a cursory glance, it would seem doable.  One would need to
> copy/borrow the existing logic for \path and then add a suitable
> "setdash" command to the PostScript output and an equivalent
> "stroke-dasharray" attribute to the SVG output.  Looking at how
> \draw-dashed-line works should provide a useful reference.

Here is an attempt that covers only PostScript:

%%%%
\version "2.20.0"

#(define* (dashed-path-ps thickness on off phase exps
                           #:optional (cap 'round) (join 'round))
   (string-append
     (ly:format "[ ~4f ~4f ] ~4f setdash\n" on off phase)
     ((module-ref (resolve-module '(scm output-ps)) 'path #f)
       thickness exps cap join)))

#(module-define! (resolve-module '(scm output-ps))
   'dashed-path dashed-path-ps)

#(ly:register-stencil-expression 'dashed-path)

#(define-markup-command
   (dashed-path layout props thickness commands)
   (number? list?)
   #:category graphic
   #:properties ((line-cap-style 'round)
                 (line-join-style 'round)
                 (on 1) (off 1) (phase 0))
   (let ((sten (path-markup layout props thickness commands))
         (command-list (fold-right append '() commands)))
     (ly:make-stencil
       `(dashed-path ,thickness ,on ,off ,phase
         `(,@',command-list)
         ',line-cap-style ',line-join-style)
       (ly:stencil-extent sten X)
       (ly:stencil-extent sten Y))))

samplePath =
   #'((moveto 0 0)
      (lineto -1 1)
      (lineto 1 1)
      (lineto 1 -1)
      (curveto -5 -5 -5 5 -1 0)
      (closepath))

\markup \path #0.25 #samplePath
\markup \dashed-path #0.25 #samplePath
\markup
   \override #'(on . 0.2)
   \override #'(off . 0.2)
   \override #'(line-cap-style . butt)
   \dashed-path #0.25 #samplePath
%%%%


-- Aaron Hill

dashed-path.cropped.png (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: \path in markup dashed line

Aaron Hill
On 2020-09-07 4:38 pm, Aaron Hill wrote:

> On 2020-09-07 1:20 pm, Aaron Hill wrote:
>> Given a cursory glance, it would seem doable.  One would need to
>> copy/borrow the existing logic for \path and then add a suitable
>> "setdash" command to the PostScript output and an equivalent
>> "stroke-dasharray" attribute to the SVG output.  Looking at how
>> \draw-dashed-line works should provide a useful reference.
>
> Here is an attempt that covers only PostScript:
>
> ...

Mistake found.  The setdash needs to be inside the gsave/grestore:

%%%%
\version "2.20.0"

#(define* (dashed-path-ps thickness on off phase exps
                           #:optional (cap 'round) (join 'round))
   (let* ((path (module-ref (resolve-module '(scm output-ps)) 'path #f))
          (ps (path thickness exps cap join))
          (lines (string-split ps #\nl)))
     (set! lines (cons (car lines)
       (cons (ly:format "[ ~4f ~4f ] ~4f setdash" on off phase)
             (cdr lines))))
     (string-join lines "\n")))

#(module-define! (resolve-module '(scm output-ps))
   'dashed-path dashed-path-ps)

#(ly:register-stencil-expression 'dashed-path)

#(define-markup-command
   (dashed-path layout props thickness commands)
   (number? list?)
   #:category graphic
   #:properties ((line-cap-style 'round)
                 (line-join-style 'round)
                 (on 1) (off 1) (phase 0))
   (let ((sten (path-markup layout props thickness commands))
         (command-list (fold-right append '() commands)))
     (ly:make-stencil
       `(dashed-path ,thickness ,on ,off ,phase
         `(,@',command-list)
         ',line-cap-style ',line-join-style)
       (ly:stencil-extent sten X)
       (ly:stencil-extent sten Y))))

samplePath =
   #'((moveto 0 0)
      (lineto -1 1)
      (lineto 1 1)
      (lineto 1 -1)
      (curveto -5 -5 -5 5 -1 0)
      (closepath))

\markup \path #0.25 #samplePath
\markup \dashed-path #0.25 #samplePath
\markup
   \override #'(on . 0.2)
   \override #'(off . 0.2)
   \override #'(line-cap-style . butt)
   \dashed-path #0.25 #samplePath
%%%%


-- Aaron Hill