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: Thu, 13 Aug 2015 13:50:01 -0400

Here’s another possibility that uses an optional axis argument.  -Paul

\version "2.19.22"

#(define* (center-stencil-on-stencil stil-a stil-b #:optional axis)
   "Return a copy of stencil @var{stil-b} that has been moved 
   so it is centered on stencil @var{stil-a} on @var{axis}. When
   @var{axis} is omitted, the centering is done on both X and
   Y axes. @var{axis} is 0 for X axis, 1 for Y axis."
   (if axis
       ;; center on one axis only
       (ly:stencil-translate-axis
        (ly:stencil-aligned-to stil-b axis CENTER)
        (interval-center (ly:stencil-extent stil-a axis))
        axis)
       ;; center on both X and Y axes
       (ly:stencil-translate
        (centered-stencil stil-b)
        (cons
         (interval-center (ly:stencil-extent stil-a X))
         (interval-center (ly:stencil-extent stil-a Y))))))

square =
#(make-connected-path-stencil
  '((0 0) (4 0) (4 4) (0 4) (0 0))
  0.4 1 1 #f #f)

blue-square =
#(stencil-with-color (make-filled-box-stencil '(0.4 . 2) '(0.4 . 2)) blue)

\markup
\override #'(word-space . 3)
\line {
  \stencil #(ly:stencil-add square blue-square)
  \stencil #(ly:stencil-add square
              (center-stencil-on-stencil square blue-square X))
  \stencil #(ly:stencil-add square
              (center-stencil-on-stencil square blue-square Y))
  \stencil #(ly:stencil-add square
              (center-stencil-on-stencil square blue-square))
}







reply via email to

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