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: Thomas Morley
Subject: Re: Centering a stencil on another stencil
Date: Tue, 11 Aug 2015 10:48:11 +0200

Hi Paul,

thanks for the examples

2015-08-10 20:47 GMT+02:00 Paul Morris <address@hidden>:
>> 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.

Me not.

> ...but then I noticed that the horizontal spacing is affected by 
> centered-stencil but not with center-stencil-on-stencil.  Not sure why...

It's because centered-stencil centers the stencil around the
ref-point. In so far your initial examples were misleading because the
circle-markup is already constructed around his center. Whereas
NoteHeads have their ref-point at their left side.

Thanks again for your examples, which gave me the possibility to
notice the problem.
I now come up with a simplified coding:

\version "2.19.24"

#(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."
    (ly:stencil-translate-axis
      (ly:stencil-aligned-to stil-b axis CENTER)
      (interval-center (ly:stencil-extent stil-a axis))
      axis))

#(define (make-notehead-stencil grob)
   (let*
    ((font (ly:grob-default-font grob))
     (solid-head (ly:font-get-glyph font "noteheads.s2"))
     (stil (ly:note-head::print grob)) ;; default
     (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)
        green))))
   dot-head))

%%%%%%%%%%%%%%%%%
%% EXAMPLES
%%%%%%%%%%%%%%%%%

%% NoteHeads

\markup "default"

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

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

\new Staff \with {
  \override NoteHead.stencil =
  #(lambda (grob) (make-notehead-stencil grob))
} {
  c'4 d' e' f'
}

%% Markups

circle = #(make-circle-stencil 3 0.4 #f)

square =
#(stencil-with-color
  (make-connected-path-stencil
   '((0 0) (3 0) (3 3) (0 3) (0 0))
   0.4 1 1 #f #f)
  blue)

\markup \box \line {
  \stencil #(ly:stencil-add circle square)
  "   "
  \stencil #(ly:stencil-add circle (center-stencil-on-stencil X circle square))
  "   "
  \stencil #(ly:stencil-add circle (center-stencil-on-stencil Y circle square))
  "   "
  \stencil #(ly:stencil-add
              circle
              (center-stencil-on-stencil Y circle
                (center-stencil-on-stencil X circle square)))
}


HTH,
  Harm



reply via email to

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