lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: \path in markup dashed line


From: Aaron Hill
Subject: Re: \path in markup dashed line
Date: Mon, 07 Sep 2020 16:46:14 -0700
User-agent: Roundcube Webmail/1.4.2

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]