> On Aug 7, 2015, at 2:17 PM, Thomas Morley <thomasmorle...@gmail.com> wrote:
> 
> May I ask you to provide a code-example where the output is different?
> For the given one I can't see any.

Hi Harm,  Sure, see below for a somewhat minimized (if not completely minimal) 
example.

I was surprised to see that the resulting note head stencil and stem connection 
is the same in either case.  ...but then I noticed that the horizontal spacing 
is affected by centered-stencil but not with center-stencil-on-stencil.  Not 
sure why...

Cheers,
-Paul



\version "2.19.22"

#(define (center-stencil-on-stencil axis stil-a stil-b)
   "Return a copy of stencil @var{stil-b} that has been 
    moved so it is centered on stencil @var{stil-a} on 
    @var{axis}. @var{axis} is 0 for X axis, 1 for Y axis."
   (let* ((ext-a (ly:stencil-extent stil-a axis))
          (ext-b (ly:stencil-extent stil-b axis))
          (width-a (- (cdr ext-a) (car ext-a)))
          (width-b (- (cdr ext-b) (car ext-b)))
          (width-diff (- width-a width-b))
          (position-diff (- (car ext-a) (car ext-b)))
          (offset (+ position-diff (/ width-diff 2)))
          (new-stil-b (ly:stencil-translate-axis stil-b offset axis)))
     new-stil-b))

#(define (make-notehead-stencil-one grob)
   (let*
    ((font (ly:grob-default-font grob))
     (solid-head (ly:font-get-glyph font "noteheads.s2"))
     (stil (ly:grob-property grob 'stencil))
     (dot (flip-stencil X (ly:stencil-scale solid-head 0.333 0.333)))
     (dot-head
      (ly:stencil-add
       stil
       (stencil-with-color
        (center-stencil-on-stencil X stil dot)
        white))))
   dot-head))

#(define (make-notehead-stencil-two grob)
   (let*
    ((font (ly:grob-default-font grob))
     (solid-head (ly:font-get-glyph font "noteheads.s2"))
     (stil (ly:grob-property grob 'stencil))
     (dot (flip-stencil X (ly:stencil-scale solid-head 0.333 0.333)))
     (dot-head
      (ly:stencil-add
       (centered-stencil stil)
       (stencil-with-color
        (centered-stencil dot)
        white))))
    dot-head))

\markup "default"

\new Staff {
  c' d' e' f'
}

\markup "center-stencil-on-stencil (spacing is the same)"

\new Staff \with {
  \override NoteHead.before-line-breaking =
  #(lambda (grob)
     (ly:grob-set-property! grob 'stencil
       (make-notehead-stencil-one grob)))
} {
  c' d' e' f'
}

\markup "centered-stencil (spacing is affected)"

\new Staff \with {
  \override NoteHead.before-line-breaking =
  #(lambda (grob)
     (ly:grob-set-property! grob 'stencil
       (make-notehead-stencil-two grob)))
} {
  c' d' e' f'
}


_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to