lilypond-user
[Top][All Lists]
Advanced

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

Re: Centering a stencil on another stencil


From: Paul Morris
Subject: Re: Centering a stencil on another stencil
Date: Mon, 10 Aug 2015 14:47:32 -0400

> On Aug 7, 2015, at 2:17 PM, Thomas Morley <address@hidden> 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'
}




reply via email to

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